Esempio n. 1
0
    private void LoadRTSAgents(JsonTextReader reader)
    {
        if (reader == null)
        {
            return;
        }
        RTSAgents agents = GetComponentInChildren <RTSAgents>();
        string    currValue = "", type = "";

        while (reader.Read())
        {
            if (reader.Value != null)
            {
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    currValue = (string)reader.Value;
                }
                else if (currValue == "Type")
                {
                    type = (string)reader.Value;
                    // need to create unit via commander controller...
                    GameObject newObject = Instantiate(ResourceManager.GetAgentTemplate(type).gameObject);
                    RTSAgent   agent     = newObject.GetComponent <RTSAgent>();
                    agent.name = agent.name.Replace("(Clone)", "").Trim();
                    agent.LoadDetails(reader);
                    agent.transform.parent = agents.transform;
                    agent.SetCommander();
                    agent.SetTeamColor();

                    if (agent.GetAbility <Structure>().UnderConstruction())
                    {
                        agent.SetTransparentMaterial(CachedBuilderManager.allowedMaterial, true);
                    }
                }
            }
            else if (reader.TokenType == JsonToken.EndArray)
            {
                return;
            }
        }
    }
Esempio n. 2
0
    // move to build ability?
    public void StartConstruction()
    {
        findingPlacement = false;
        Vector2d buildPoint  = new Vector2d(tempBuilding.transform.position.x, tempBuilding.transform.position.z);
        RTSAgent newBuilding = cachedCommander.CachedController.CreateAgent(tempBuilding.gameObject.name, buildPoint, Vector2d.right) as RTSAgent;

        Destroy(tempBuilding.gameObject);

        newBuilding.SetState(AnimState.Building);
        newBuilding.RestoreMaterials();
        newBuilding.SetPlayingArea(tempCreator.GetPlayerArea());
        newBuilding.GetAbility <Health>().HealthAmount = FixedMath.Create(0);
        newBuilding.SetCommander();

        // send build command
        Command buildCom = new Command(AbilityDataItem.FindInterfacer("Construct").ListenInputID);

        buildCom.Add <DefaultData>(new DefaultData(DataType.UShort, newBuilding.GlobalID));
        UserInputHelper.SendCommand(buildCom);

        newBuilding.GetAbility <Structure>().StartConstruction();
        // check that the Player has the resources available before allowing them to create a new Unit / Building
        cachedCommander.RemoveResource(ResourceType.Gold, newBuilding.cost);
    }