コード例 #1
0
ファイル: Main.cs プロジェクト: JJJohan/RTS
        // Create a ghost building to show where it is being placed.
        public static void CreateBuildingGhost(SidePanel a_sidePanel, BuildingArgs a_events)
        {
            int cost = a_events.prefab.cost;
            if (InputHandler.m_cursorBuilding)
                cost += InputHandler.m_cursorBuilding.GetComponent<GhostBuilding>().m_prefab.cost;
            if (cost > m_res.funds)
                return;

            // Discard any previous ghost object.
            if (InputHandler.m_cursorBuilding != null)
            {
                m_res.funds += InputHandler.m_cursorBuilding.GetComponent<GhostBuilding>().m_prefab.cost;
                UnityEngine.Object.Destroy(InputHandler.m_cursorBuilding);
            }

            // Instantiate the ghost.
            m_res.funds -= cost;
            InputHandler.m_cursorMode = Cursor.BUILD;
            InputHandler.m_selectionType = Selection.NONE;
            InputHandler.m_cursorBuilding = new GameObject();
            GhostBuilding script = InputHandler.m_cursorBuilding.AddComponent<GhostBuilding>();
            script.Create(a_events.prefab);
        }
コード例 #2
0
ファイル: SidePanel.cs プロジェクト: JJJohan/RTS
        public void Update()
        {
            if (Main.m_res.buildings.Count != m_buildingCount)
            {
                m_buildingCount = Main.m_res.buildings.Count;
                if (m_display == Type.Building)
                    ListBuildings();
                else if (m_display == Type.Unit)
                    ListUnits();
            }

            // Update buttons
            if (Main.m_event != null)
            {
                // Left & Right Arrows
                if (m_index > 0)
                {
                    if (m_buttonLeft.Process(Main.m_event) == Button.MOUSE1UP)
                    {
                        --m_index;
                    }
                }
                if (m_index < m_prefabButtons.Count / 8)
                {
                    if (m_buttonRight.Process(Main.m_event) == Button.MOUSE1UP)
                    {
                        ++m_index;
                    }
                }

                // Update main buttons
                for (int i = 0; i < 8; ++i)
                {
                    int index = i + (m_index * 8);
                    if (index >= m_prefabButtons.Count)
                        break;

                    // Check if we can afford the building or unit.
                    m_buttons[index].Lock(Main.m_res.funds < m_prefabButtons[index].cost && m_prefabButtons[index].count < 20);

                    // Process buttons
                    int eventType = m_buttons[index].Process(Main.m_event);
                    if (eventType == Button.MOUSE1UP)
                    {
                        if (m_prefabButtons[index].type == Type.Building)
                        {
                            if (BuildingEvent != null)
                            {
                                BuildingArgs args = new BuildingArgs();
                                args.prefab = m_prefabButtons[index].building;
                                BuildingEvent(this, args);
                                break;
                            }
                        }
                        else
                        {
                            if (UnitEvent != null)
                            {
                                UnitArgs args = new UnitArgs();
                                args.prefab = m_prefabButtons[index].unit;
                                args.create = true;
                                UnitEvent(this, args);

                                PrefabButton button = m_prefabButtons[index];
                                ++button.count;
                                m_prefabButtons[index] = button;

                                break;
                            }
                        }
                    }
                    else if (eventType == Button.MOUSE2UP)
                    {
                        if (m_prefabButtons[index].type == Type.Unit && m_prefabButtons[index].count > 0)
                        {
                            UnitArgs args = new UnitArgs();
                            args.prefab = m_prefabButtons[index].unit;
                            args.create = false;
                            UnitEvent(this, args);

                            PrefabButton button = m_prefabButtons[index];
                            --button.count;
                            m_prefabButtons[index] = button;

                            break;
                        }
                    }
                }
            }
        }