示例#1
0
        void SetupConfigs()
        {
            IUnitConfigDataProvider database;

            //todo guard
            if (LSDatabaseManager.TryGetDatabase(out database))
            {
                ConfigElementData = database.UnitConfigElementData;
                ConfigElementMap  = new Dictionary <string, UnitConfigElementDataItem>();
                for (int i = 0; i < ConfigElementData.Length; i++)
                {
                    var item = ConfigElementData[i];
                    ConfigElementMap.Add(item.Name, item);
                }
                ConfigData = database.UnitConfigData;
                for (int i = 0; i < ConfigData.Length; i++)
                {
                    IUnitConfigDataItem item  = ConfigData[i];
                    LSAgent             agent = AgentController.GetAgentTemplate(item.Target);
                    for (int j = 0; j < item.Stats.Length; j++)
                    {
                        Stat stat = item.Stats[j];
                        //todo guard
                        var       element   = ConfigElementMap[stat.ConfigElement];
                        Component component = agent.GetComponent(element.ComponentType);
                        SetField(component, element.Field, stat.Value);
                    }
                }
            }
        }
        /// <summary>
        /// Create an uninitialized LSAgent
        /// </summary>
        /// <returns>The raw agent.</returns>
        /// <param name="agentCode">Agent code.</param>
        /// <param name="isBare">If set to <c>true</c> is bare.</param>
        public static LSAgent CreateRawAgent(string agentCode)
        {
            if (!IsValidAgentCode(agentCode))
            {
                throw new System.ArgumentException(string.Format("Agent code '{0}' not found.", agentCode));
            }
            FastStack <LSAgent> cache    = CachedAgents [agentCode];
            LSAgent             curAgent = null;

            if (cache.IsNotNull() && cache.Count > 0)
            {
                curAgent = cache.Pop();
                ushort agentCodeID = AgentController.GetAgentCodeIndex(agentCode);
                Debug.Log(curAgent.TypeIndex);
                TypeAgentsActive [agentCodeID] [curAgent.TypeIndex] = true;
            }
            else
            {
                IAgentData interfacer = AgentController.CodeInterfacerMap [agentCode];

                curAgent = GameObject.Instantiate(AgentController.GetAgentTemplate(agentCode).gameObject).GetComponent <LSAgent> ();
                curAgent.Setup(interfacer);

                RegisterRawAgent(curAgent);
            }
            return(curAgent);
        }
        public LSAgent CreateAgent(
            string agentCode,
            Vector2d position,
            Vector2d rotation
            )
        {
            Vector2d pos = position;
            Vector2d rot = rotation;


            if (!IsValidAgentCode(agentCode))
            {
                throw new System.ArgumentException(string.Format("Agent code '{0}' not found.", agentCode));
            }


            FastStack <LSAgent> cache    = CachedAgents [agentCode];
            LSAgent             curAgent = null;
            ushort agentCodeID           = AgentController.GetAgentCodeIndex(agentCode);

            if (cache.IsNotNull() && cache.Count > 0)
            {
                curAgent = cache.Pop();

                TypeAgentsActive [agentCodeID] [curAgent.TypeIndex] = true;
            }
            else
            {
                IAgentData interfacer = AgentController.CodeInterfacerMap [agentCode];

                curAgent = GameObject.Instantiate(AgentController.GetAgentTemplate(agentCode).gameObject).GetComponent <LSAgent> ();
                curAgent.Setup(interfacer);


                FastList <bool> typeActive;
                if (!AgentController.TypeAgentsActive.TryGetValue(agentCodeID, out typeActive))
                {
                    typeActive = new FastList <bool> ();
                    TypeAgentsActive.Add(agentCodeID, typeActive);
                }
                FastList <LSAgent> typeAgents;
                if (!TypeAgents.TryGetValue(agentCodeID, out typeAgents))
                {
                    typeAgents = new FastList <LSAgent> ();
                    TypeAgents.Add(agentCodeID, typeAgents);
                }

                curAgent.TypeIndex = (ushort)typeAgents.Count;
                typeAgents.Add(curAgent);
                typeActive.Add(true);
            }
            InitializeAgent(curAgent, pos, rot);
            return(curAgent);
        }