Пример #1
0
        private void SetupPieceInfo(Piece piece)
        {
            Player localPlayer = Player.m_localPlayer;

            Hud.instance.m_buildSelection.text   = Localization.instance.Localize(piece.m_name);
            Hud.instance.m_pieceDescription.text = Localization.instance.Localize(piece.m_description);
            Hud.instance.m_buildIcon.enabled     = true;
            Hud.instance.m_buildIcon.sprite      = piece.m_icon;
            GameObject[] uiRequirementPanels = Hud.instance.m_requirementItems;
            for (int j = 0; j < uiRequirementPanels.Length; j++)
            {
                if (j < piece.m_resources.Length)
                {
                    Piece.Requirement req = piece.m_resources[j];
                    uiRequirementPanels[j].SetActive(value: true);
                    SetupRequirement(uiRequirementPanels[j].transform, req, GetResourceCount(GetResourceName(req)));
                }
                else
                {
                    uiRequirementPanels[j].SetActive(value: false);
                }
            }
            if ((bool)piece.m_craftingStation)
            {
                CraftingStation craftingStation = CraftingStation.HaveBuildStationInRange(piece.m_craftingStation.m_name, localPlayer.transform.position);
                GameObject      obj             = uiRequirementPanels[piece.m_resources.Length];
                obj.SetActive(value: true);
                Image     component  = obj.transform.Find("res_icon").GetComponent <Image>();
                Text      component2 = obj.transform.Find("res_name").GetComponent <Text>();
                Text      component3 = obj.transform.Find("res_amount").GetComponent <Text>();
                UITooltip component4 = obj.GetComponent <UITooltip>();
                component.sprite  = piece.m_craftingStation.m_icon;
                component2.text   = Localization.instance.Localize(piece.m_craftingStation.m_name);
                component4.m_text = piece.m_craftingStation.m_name;
                if (craftingStation != null)
                {
                    craftingStation.ShowAreaMarker();
                    component.color  = Color.white;
                    component3.text  = "";
                    component3.color = Color.white;
                }
                else
                {
                    component.color  = Color.gray;
                    component3.text  = "None";
                    component3.color = ((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : Color.white);
                }
            }
        }
Пример #2
0
        public bool SetupRequirement(Transform elementRoot, Piece.Requirement req, int currentAmount)
        {
            Image     imageResIcon  = elementRoot.transform.Find("res_icon").GetComponent <Image>();
            Text      textResName   = elementRoot.transform.Find("res_name").GetComponent <Text>();
            Text      textResAmount = elementRoot.transform.Find("res_amount").GetComponent <Text>();
            UITooltip uiTooltip     = elementRoot.GetComponent <UITooltip>();

            if (req.m_resItem != null)
            {
                imageResIcon.gameObject.SetActive(value: true);
                textResName.gameObject.SetActive(value: true);
                textResAmount.gameObject.SetActive(value: true);
                imageResIcon.sprite = req.m_resItem.m_itemData.GetIcon();
                imageResIcon.color  = Color.white;

                uiTooltip.m_text = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name);
                textResName.text = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name);

                int requiredAmount = req.GetAmount(0);

                int playerAmount = PlayerGetResourceCount(Player.m_localPlayer, req.m_resItem.m_itemData.m_shared.m_name);
                int remaining    = requiredAmount - currentAmount;

                textResAmount.text = currentAmount + "/" + requiredAmount;
                if (remaining > 0 && playerAmount == 0)
                {
                    imageResIcon.color  = Color.gray;
                    textResAmount.color = ((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : Color.white);
                }
                else
                {
                    imageResIcon.color  = Color.white;
                    textResAmount.color = Color.white;
                }
            }
            return(true);
        }