'Unity MVC get View atached to the UI label

A simple task. I have a ScoreController which will set the score to UI. I have a UI label that has ScoreView in it

The question is how do I get this ScoreView in my controller

I have found out the way to get View from prefab that's being instantiated:

public class CellViewFactory : ICellViewFactory
{
    public ICellView GetView(Vector3 position)
    {
      var prefab = Resources.Load<GameObject>("Cell");
      var instance = UnityEngine.Object.Instantiate(prefab);
      var cellView = instance.GetComponent<ICellView>();
      
      cellView.SetPosition(position);

      return cellView;
    }
}

But since UI isn't instantiated by the code, what's the way to get the ScoreView from it?

Now, I have found an option to call a static method of a Factory and pass self to the method. Smth like this:

    public class ScoreView : MonoBehaviour
    {
        void Start()
        {
            ScoreViewFactory.NotifyScoreViewCreated(this);
        }
    }

But it doesn't seem to be flexible using static methods in decoupled code with Factories and interfaces. Hope there's another way

I would also be glad if you post some complete tutorioal on MVC in Unity. Seems that there's no complete working tutorials.

It would also be great if you would share an example of MVC pattern in Unity using DependencyInjection.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source