Ejemplo n.º 1
0
    private void DrawOrdersBar()
    {
        if (Selector.MainSelectedAgent.GetAbility <Structure>() && Selector.MainSelectedAgent.GetAbility <Structure>().UnderConstruction())
        {
            return;
        }
        GUI.skin = ordersSkin;
        GUI.BeginGroup(new Rect(Screen.width - ORDERS_BAR_WIDTH - BUILD_IMAGE_WIDTH, RESOURCE_BAR_HEIGHT, ORDERS_BAR_WIDTH + BUILD_IMAGE_WIDTH, Screen.height - RESOURCE_BAR_HEIGHT));
        GUI.Box(new Rect(BUILD_IMAGE_WIDTH + SCROLL_BAR_WIDTH, 0, ORDERS_BAR_WIDTH, Screen.height - RESOURCE_BAR_HEIGHT), "");
        string selectionName = "";

        RTSAgent selectedAgent = Selector.MainSelectedAgent as RTSAgent;

        selectionName = selectedAgent.GetComponent <RTSAgent>().objectName;
        if (selectedAgent.IsOwnedBy(cachedCommander.CachedController))
        {
            // reset slider value if the selected object has changed
            if (lastSelection && lastSelection != Selector.MainSelectedAgent)
            {
                sliderValue = 0.0f;
            }
            if (selectedAgent.MyAgentType == AgentType.Unit && selectedAgent.GetAbility <Construct>())
            {
                DrawActions(selectedAgent.GetAbility <Construct>().GetBuildActions());
            }
            else if (selectedAgent.MyAgentType == AgentType.Building && selectedAgent.GetAbility <Spawner>())
            {
                DrawActions(selectedAgent.GetAbility <Spawner>().GetSpawnActions());
            }
            // store the current selection
            lastSelection = selectedAgent;
            if (lastSelection.MyAgentType == AgentType.Building)
            {
                if (lastSelection.GetAbility <Spawner>())
                {
                    DrawBuildQueue(lastSelection.GetAbility <Spawner>().getBuildQueueValues(), lastSelection.GetAbility <Spawner>().getBuildPercentage());
                }
                DrawStandardBuildingOptions(lastSelection as RTSAgent);
            }
        }
        if (!selectionName.Equals(""))
        {
            int leftPos = BUILD_IMAGE_WIDTH + SCROLL_BAR_WIDTH / 2;
            int topPos  = buildAreaHeight + BUTTON_SPACING;
            GUI.Label(new Rect(leftPos, topPos, ORDERS_BAR_WIDTH, SELECTION_NAME_HEIGHT), selectionName);
        }
        GUI.EndGroup();
    }
Ejemplo n.º 2
0
    public static void CreateStructure(string buildingName, RTSAgent constructingAgent, Rect playingArea)
    {
        Vector2d buildPoint       = new Vector2d(constructingAgent.transform.position.x, constructingAgent.transform.position.z + 10);
        RTSAgent buildingTemplate = GameResourceManager.GetAgentTemplate(buildingName);

        if (buildingTemplate.MyAgentType == AgentType.Building && buildingTemplate.GetComponent <Structure>())
        {
            // check that the Player has the resources available before allowing them to create a new structure
            if (!_cachedCommander.CachedResourceManager.CheckResources(buildingTemplate))
            {
                Debug.Log("Not enough resources!");
            }
            else
            {
                tempObject = Object.Instantiate(buildingTemplate.gameObject, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                if (tempObject)
                {
                    _findingPlacement = true;
                    SetTransparentMaterial(tempObject, GameResourceManager.AllowedMaterial);
                    tempObject.gameObject.name = buildingName;

                    tempStructure = tempObject.GetComponent <Structure>();
                    if (tempStructure.StructureType == StructureType.Wall)
                    {
                        // walls require a little help since they are click and drag
                        _constructingWall       = true;
                        tempStructure.IsOverlay = true;
                        WallPositioningHelper.Setup();
                    }

                    tempStructureBody = tempObject.GetComponent <UnityLSBody>().InternalBody;

                    // structure size is 2 times the size of halfwidth & halfheight
                    tempStructure.BuildSizeLow  = (tempStructureBody.HalfWidth.CeilToInt() * 2);
                    tempStructure.BuildSizeHigh = (tempStructureBody.HalfLength.CeilToInt() * 2);

                    cachedAgent = constructingAgent;

                    tempStructure.gameObject.transform.position = Positioning.GetSnappedPosition(buildPoint.ToVector3());
                }
            }
        }
    }