コード例 #1
0
    // Use this for initialization
    void CreateSystemsDirectly()
    {
        RootSystems systems = new RootSystems(Contexts.sharedInstance);
        //systems.E

        //BEST PRACTICE: Contexts.sharedInstance is a useful way to get contexts and expose them to monobehavior scripts as well using a static modifier as op0osed to just createing new Contexts();
        Contexts contexts = Contexts.sharedInstance;

        //STANDARD PRACTICE:this is the standard way of creating contexts at start
        //var contexts = new Contexts();

        ///EXAMPLE ZERO: Initialize entities by using a system as opposed to creating the object in the start or update method
        //BEST PRACTICE: It's best to use systems for all logic, including creating Entities using ?Initialize
        m_TestPlayerCreateSystem = new CreatePlayerSystem(contexts);
        m_TestPlayerCreateSystem.Initialize();
        //STANDARD PRACTICE: this is a simple way to create an entity without using a system to do it

        /*  var e = contexts.game.CreateEntity();
         * //No AddComponent with ECS, instead we use the Add method and constructor form the generated IComponent script
         * e.AddHealth(100);
         */

        ///EXAMPLE ONE: ExecuteSystems: simply perform when execute method is called
        //Execution logic is generally contained in systems that need to be executed
        var system = new LogHealthSystem(contexts);

        system.Execute();

        ///EXAMPLE TWO: ReactiveSystems: Execute in reaction to some component changing
        m_TestReactiveSystem = new ReactLogHealthSystem(contexts);
    }
コード例 #2
0
ファイル: GameController.cs プロジェクト: Greg-Rus/Avocado
 void Start()
 {
     _context            = Contexts.sharedInstance;
     _logHealthSystem    = new LogHealth(_context);
     _createPlayerSystem = new CreatePlayerSystem(_context);
     _createPlayerSystem.Initialize();
 }