コード例 #1
0
        private static void DestroyAgentBuffer(DeactivationData data)
        {
            RTSAgent agent = data.Agent;

            if (agent.IsActive == false)
            {
                return;
            }
            bool immediate = data.Immediate;

            agent.Deactivate(immediate);
            ChangeController(agent, null);

            //Pool if the agent is registered
            ushort agentCodeID;

            if (agent.TypeIndex != UNREGISTERED_TYPE_INDEX)
            {
                // if (CodeIndexMap.TryGetValue(agent.MyAgentCode, out agentCodeID))
                // {
                agentCodeID = GameResourceManager.GetAgentCodeIndex(agent.MyAgentCode);
                if (agentCodeID.IsNotNull())
                {
                    TypeAgentsActive[agentCodeID][agent.TypeIndex] = false;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Create an uninitialized RTSAgent
        /// </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 RTSAgent CreateRawAgent(string agentCode, Vector2d startPosition = default(Vector2d), Vector2d startRotation = default(Vector2d))
        {
            if (!GameResourceManager.IsValidAgentCode(agentCode))
            {
                throw new System.ArgumentException(string.Format("Agent code '{0}' not found.", agentCode));
            }
            FastStack <RTSAgent> cache    = CachedAgents[agentCode];
            RTSAgent             curAgent = null;

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

                Vector3    pos = startPosition.ToVector3();
                Quaternion rot = new Quaternion(0, startRotation.y, 0, startRotation.x);

                curAgent = GameObject.Instantiate(GameResourceManager.GetAgentTemplate(agentCode).gameObject, pos, rot).GetComponent <RTSAgent>();
                curAgent.Setup(interfacer);

                RegisterRawAgent(curAgent);
            }
            return(curAgent);
        }
コード例 #3
0
        public static void RegisterRawAgent(RTSAgent agent)
        {
            var             agentCodeID = GameResourceManager.GetAgentCodeIndex(agent.MyAgentCode);
            FastList <bool> typeActive;

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

            if (!TypeAgents.TryGetValue(agentCodeID, out typeAgents))
            {
                typeAgents = new FastList <RTSAgent>();
                TypeAgents.Add(agentCodeID, typeAgents);
            }

            //TypeIndex of ushort.MaxValue means that this agent isn't registered for the pool
            agent.TypeIndex = (ushort)(typeAgents.Count);
            typeAgents.Add(agent);
            typeActive.Add(true);
        }