コード例 #1
0
        public void AddListenerToShipSystems()
        {
            for (int i = 0; i < GameManager.shipSystems.Count; i++)
            {
                ShipSystem shipSystem = GameManager.shipSystems[i].GetComponent <ShipSystem>();

                GameObject systemButtonGO = systemPanel.transform.GetChild(i).gameObject;

                CustomButton systemButton = systemButtonGO.GetComponent <CustomButton>();
                // remove all previous functionalities from weapon button
                systemButton.onTap.RemoveAllListeners();
                systemButton.onDoubleTap.RemoveAllListeners();
                systemButton.onLongTap.RemoveAllListeners();

                // add functionality to system's button (except for weapons system)
                if (!shipSystem.GetComponent <Weapons>())
                {
                    systemButton.onTap.AddListener(delegate() {
                        shipSystem.ToggleSelectSystem();
                    });
                    // systemButton.onDoubleTap.AddListener(delegate () {
                    //     shipSystem.AddFullPower();
                    //     });
                    systemButton.onDoubleTap.AddListener(delegate() {
                        shipSystem.OpenSystemPowerUI();
                    });
                }
            }
        }
コード例 #2
0
        public void RefreshPowerUsageUI(ShipSystem shipSystem)
        {
            RefreshMaxPowerUsageUI();

            if (IsPowered)
            {
                for (int i = 0; i < powerBars.Count; i++)
                {
                    Image powerBarImg = powerBars[i].GetComponent <Image>();
                    if (i < usage)
                    {
                        powerBarImg.sprite = powerBarOn;
                        powerBarImg.color  = NORMAL_COLOR;
                    }
                    else
                    {
                        powerBarImg.sprite = powerBarOff;

                        // had to use this due to a unity bug (in order to refresh the changed color)
                        powerBarImg.DisableSpriteOptimizations();

                        int systemHP;

                        if (shipSystem.Room == null)
                        {
                            systemHP = shipSystem.GetComponent <Weaponry>().hp;
                        }
                        else
                        {
                            systemHP = shipSystem.Room.CurrentHP;
                        }

                        if (i >= systemHP)
                        {
                            powerBarImg.color = DAMAGED_COLOR;
                        }
                        else
                        {
                            powerBarImg.color = NORMAL_COLOR;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < powerBars.Count; i++)
                {
                    Image powerBarImg = powerBars[i].GetComponent <Image>();

                    powerBarImg.sprite = powerBarOff;

                    // had to use this due to a unity bug (in order to refresh the changed color)
                    powerBarImg.DisableSpriteOptimizations();

                    int systemHP;

                    if (shipSystem.Room == null)
                    {
                        systemHP = shipSystem.GetComponent <Weaponry>().hp;
                    }
                    else
                    {
                        systemHP = shipSystem.Room.CurrentHP;
                    }

                    if (i >= systemHP)
                    {
                        powerBarImg.color = DAMAGED_COLOR;
                    }
                    else
                    {
                        powerBarImg.color = NORMAL_COLOR;
                    }
                }
            }
        }