Esempio n. 1
0
        /// <summary>
        /// Find all Views of type TIView that exist in the scene and give them a model and agent.
        /// </summary>
        /// <param name="modelArgs"> Arguments passed to the model's constructor. </param>
        protected TView[] BuildEntitiesOfType <TView, TIView, TIAgent, TIModel>(params object[] modelArgs)
            where TView : Component, TIView
            where TIView : class, IViewBase
            where TIModel : class, IModel
            where TIAgent : class, IAgent
        {
            var objs = FindObjectsOfType <TView>().OrderBy(o => o.name).ToArray();

            foreach (var obj in objs)
            {
                if (obj.AgentBase != null)
                {
                    continue;
                }

                Views.Bind <TIView, TView>(obj, false);

                var model = Models.Get <TIModel>(modelArgs);
                Assert.IsNotNull(model);

                var agent = Agents.Get <TIAgent>(model);
                Assert.IsNotNull(agent);

                obj.SetAgent(agent);
                obj.SetModel(model);

                obj.AddSubscriptions();
                agent.AddSubscriptions();
                model.AddSubscriptions();
            }
            return(objs);
        }
Esempio n. 2
0
        protected TView BuildEntityAsSingle <TView, TIView, TIAgent, TIModel>(params object[] modelArgs)
            where TView : Component, TIView
            where TIView : class, IViewBase
            where TIModel : class, IModel
            where TIAgent : class, IAgent
        {
            var obj = FindObjectOfType <TView>();

            if (obj == null)
            {
                Verbose(15, $"Failed to find instance of type {typeof(TView).Name}.");
                return(null);
            }

            if (obj.AgentBase != null)
            {
                return(obj);
            }

            Views.Bind <TIView, TView>(obj);

            var model = Models.Get <TIModel>(modelArgs);

            Assert.IsNotNull(model);

            var agent = Agents.Get <TIAgent>(model);

            Assert.IsNotNull(agent);

            obj.SetAgent(agent);
            obj.SetModel(model);

            return(obj);
        }
Esempio n. 3
0
 public TIView NewEntity <TIView, TIAgent, TIModel>(Object prefab)
     where TIView : class, IViewBase
     where TIAgent : class, IAgent
     where TIModel : class, IModel
 {
     return(Views.FromPrefab <TIView>(prefab, Agents.Get <TIAgent>(Models.Get <TIModel>())));
 }
Esempio n. 4
0
 public ReactiveAgent GetAgent(IAgentId agentId)
 {
     return(Agents.Get(agentId));
 }
Esempio n. 5
0
 public TAgent GetAgent <TAgent>(IAgentId agentId) where TAgent : ReactiveAgent
 {
     return(Agents.Get <TAgent>(agentId));
 }