Exemple #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];
                    RTSAgent            agent = GameResourceManager.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 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);
        }
Exemple #3
0
        public void CreateUnit(string unitName)
        {
            GameObject unit       = GameResourceManager.GetAgentTemplate(unitName).gameObject;
            RTSAgent   unitObject = unit.GetComponent <RTSAgent>();

            // check that the Player has the resources available before allowing them to create a new Unit / Building
            if (Agent.GetCommander() && unitObject)
            {
                if (Agent.GetCommander().CachedResourceManager.CheckResources(unitObject))
                {
                    Agent.GetCommander().CachedResourceManager.RemoveResources(unitObject);
                    spawnQueue.Enqueue(unitName);
                }
                else
                {
                    //    Debug.Log("not enough resources!");
                }
            }
        }