Design Patterns Unity3D? [closed]

2

Good morning,

I started working with Unity3D , everything was going well, until I saw my codes become GIANT, so I decided to separate everything right into a% of "own"%, I created three layers to separate the design pattern . scripts , to model the Model .

public class PlayerModel {
    public GameObject PlayerGameObject { get; set; }

    public string Name { get; set; }
    public int Life { get; set; }

    public PlayerMode() { 
        this.PlayerGameObject = GameObject.FindGameObjectWithTag("Player"); 
    }
}

public class PlayerService {
    private PlayerModel playerModel;

    void recoveryLife(int quantity) {
        playerModel.Life += quantity;
    }

    public PlayerService(PlayerModel _playerModel) {
        this.playerModel = _playerModel; 
    }
}

public class PlayerController : MonoBehaviour{
    public GameObject player;
    public PlayerModel playerModel;
    public PlayerService playerService;

    void Start() {
        playerModel = new PlayerModel();
        playerModel.Name = "Personagem";
        playerModel.Life = 100;

        playerService = new PlayerService(playerModel);
    }
}

GameObjects , to do the actions of Services (attack, receive damage, walk, etc) and a GameObject , which makes the call of both. However, to my understanding, Controller can be aware of another controllers , however the model and the service can only know about themselves?

In short, would anyone have some tutorial, an example of Design Pattern for Unity?

Thank you!

    
asked by anonymous 18.10.2017 / 13:27

0 answers