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(); }
private void DrawBuildQueue(string[] buildQueue, float buildPercentage) { for (int i = 0; i < buildQueue.Length; i++) { float topPos = i * BUILD_IMAGE_HEIGHT - (i + 1) * BUILD_IMAGE_PADDING; Rect buildPos = new Rect(BUILD_IMAGE_PADDING, topPos, BUILD_IMAGE_WIDTH, BUILD_IMAGE_HEIGHT); GUI.DrawTexture(buildPos, GameResourceManager.GetBuildImage(buildQueue[i])); GUI.DrawTexture(buildPos, buildFrame); topPos += BUILD_IMAGE_PADDING; float width = BUILD_IMAGE_WIDTH - 2 * BUILD_IMAGE_PADDING; float height = BUILD_IMAGE_HEIGHT - 2 * BUILD_IMAGE_PADDING; if (i == 0) { // shrink the build mask on the item currently being built to give an idea of progress topPos += height * buildPercentage; height *= (1 - buildPercentage); } GUI.DrawTexture(new Rect(2 * BUILD_IMAGE_PADDING, topPos, width, height), buildMask); } }