public void CreateBuilding(RTSAgent agent, string buildingName)
    {
        Vector2d buildPoint = new Vector2d(agent.transform.position.x, agent.transform.position.z + 10);

        if (cachedCommander)
        {
            //cleanup later...
            CreateBuilding(buildingName, buildPoint, agent, agent.GetPlayerArea());
        }
    }
Beispiel #2
0
    private void DrawActions(string[] actions)
    {
        GUIStyle buttons = new GUIStyle();

        buttons.hover.background  = buttonHover;
        buttons.active.background = buttonClick;
        GUI.skin.button           = buttons;
        int numActions = actions.Length;

        //define the area to draw the actions inside
        GUI.BeginGroup(new Rect(BUILD_IMAGE_WIDTH, 0, ORDERS_BAR_WIDTH, buildAreaHeight));
        //draw scroll bar for the list of actions if need be
        if (numActions >= MaxNumRows(buildAreaHeight))
        {
            DrawSlider(buildAreaHeight, numActions / 2.0f);
        }
        //display possible actions as buttons and handle the button click for each
        for (int i = 0; i < numActions; i++)
        {
            int       column = i % 2;
            int       row    = i / 2;
            Rect      pos    = GetButtonPos(row, column);
            Texture2D action = GameResourceManager.GetBuildImage(actions[i]);

            if (action)
            {
                //create the button and handle the click of that button
                if (GUI.Button(pos, action))
                {
                    RTSAgent agent = Selector.MainSelectedAgent as RTSAgent;
                    if (agent)
                    {
                        PlayClick();

                        if (agent.MyAgentType == AgentType.Unit &&
                            agent.GetAbility <Construct>() &&
                            !ConstructionHandler.IsFindingBuildingLocation())
                        {
                            ConstructionHandler.CreateStructure(actions[i], agent, agent.GetPlayerArea());
                        }
                        else if (agent.MyAgentType == AgentType.Building &&
                                 !agent.GetAbility <Structure>().NeedsConstruction &&
                                 agent.GetAbility <Spawner>())
                        {
                            // send spawn command
                            Command spawnCom = new Command(AbilityDataItem.FindInterfacer("Spawner").ListenInputID);
                            spawnCom.Add <DefaultData>(new DefaultData(DataType.String, actions[i]));
                            UserInputHelper.SendCommand(spawnCom);
                        }
                    }
                }
            }
        }
        GUI.EndGroup();
    }
    // 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);
    }