Core logic for Unity projects.
- Import into your Unity projects:
1.1) Resources (prefab Debug_ApplicationSystem need for work in editor)
1.2) Scripts
- Create Scene Controllers for your scenes and put in editor field SceneName your scene name. For example:
namespace Controllers.TestScene
{
public class TestSceneController : SceneControllerBase
{
public override IEnumerator Init()
{
//Put here your Init scene logic
throw new System.NotImplementedException();
}
}
}- Add a gameobject into your target scene and add to the gameobject the script from point 2
- If you need create Controller. For example:
namespace Controllers.TestScene
{
public class TestController : ControllerBase
{
protected override void Init()
{
//Put here your controller logic
throw new System.NotImplementedException();
}
}
}- Put controller on the scene
- If you need, create View. For example:
namespace View
{
public class ButtonView : ViewBase
{
[SerializeField] private Button _button;
public override void Init() { }
public void AddButtonOnClickListener(UnityAction action)
{
_button.onClick.AddListener(action);
}
}
}- Add your View to the scene and conect it to the controller, and init. For Example:
namespace Controllers.TestScene
{
public class TestController : ControllerBase
{
[SerializeField] private ButtonView _buttonView;
protected override void Init()
{
_buttonView.Init();
_buttonView.AddButtonOnClickListener(() =>
{
Debug.Log("Click");
});
}
}
}- All classes which inherit ControllerBase, have access to curent SceneController. Using this link, you can get another Controller. For Example:
namespace Controllers.TestScene
{
public class TestController : ControllerBase
{
[SerializeField] private ButtonView _buttonView;
protected override void Init()
{
_buttonView.Init();
_buttonView.AddButtonOnClickListener(() =>
{
Disable();
SceneController.Get<AnotherTestController>().Enable();
});
}
}
}- You can catch moment when your controller Enabling or Disabling. For example:
namespace Controllers.TestScene
{
public class AnotherTestController : ControllerBase
{
protected override void Init()
{
Disable();
}
public override void Enable()
{
base.Enable();
Debug.Log("AnotherTestController Enabled");
}
public override void Disable()
{
base.Disable();
Debug.Log("AnotherTestController Disabled");
}
}
}You can read this in Wiki
I applied this logic to several projects of different directions and it successfully demonstrated itself as a universal and enduring approach to the work of a large team on a project
If you have suggestions for improving this logic then please contact me, I'm open for discussions