示例#1
0
    // Update is called once per frame
    void Update()
    {
        if (initialized)
        {
            if (lastCredits != player.GetCredits())
            {
                int diff = player.GetCredits() - lastCredits;
                marker.DisplayText(diff);
            }
            lastCredits = player.GetCredits();
            var texts = GetComponentsInChildren <UnityEngine.UI.Text>();
            texts[1].text = player.GetPower() + "";
            texts[3].text = player.unitsCommanding.Count + "/" + player.GetTotalCommandLimit();
            texts[5].text = GetCreditString(player.GetCredits()) + "";
            var rect = texts[5].rectTransform.rect;
            rect.center = texts[5].rectTransform.position;
            tooltipManager.AddBounds(rect, $"CREDITS: {player.GetCredits()}");

            UpdatePrimaryTargetInfo();

            foreach (var infos in secondaryInfosByEntity)
            {
                UpdateInfo(infos.Key ? infos.Key.gameObject : null, infos.Value);
            }
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (initialized)
        {
            if (lastCredits != player.credits)
            {
                int diff = player.credits - lastCredits;
                marker.DisplayText(diff);
            }
            lastCredits = player.credits;
            var texts = GetComponentsInChildren <UnityEngine.UI.Text>();
            texts[1].text = player.GetPower() + "";
            texts[3].text = player.unitsCommanding.Count + "/" + player.GetTotalCommandLimit();
            texts[5].text = GetCreditString(player.credits) + "";

            UpdatePrimaryTargetInfo();

            foreach (var infos in secondaryInfosByEntity)
            {
                UpdateInfo(infos.Key ? infos.Key.gameObject : null, infos.Value);
            }
        }
    }
示例#3
0
    public void openUI()
    {
        if (opened)
        {
            var vendor = this.vendor;
            var player = this.player;
            CloseUI();
            SetVendor(vendor, player);
        }

        if (!blueprint)
        {
            Debug.Log("No blueprint!");
            return;
        }
        if (!UIPrefab)
        {
            UIPrefab = ResourceManager.GetAsset <GameObject>("vendor_ui");
        }
        if (!buttonPrefab)
        {
            buttonPrefab = ResourceManager.GetAsset <GameObject>("vendor_button");
        }
        UI = Instantiate(UIPrefab);
        UI.GetComponentInChildren <GUIWindowScripts>().Activate();
        instance   = this;
        background = UI.transform.Find("Container").Find("Background");
        Button close = background.transform.Find("Close").GetComponent <Button>();

        close.onClick.AddListener(CloseUI);
        costInfo      = background.transform.Find("Cost").GetComponent <Text>();
        nameInfo      = background.transform.Find("Name").GetComponent <Text>();
        costInfo.text = "";
        range         = blueprint.range;


        buttons = new GameObject[blueprint.items.Count];
        for (int i = 0; i < blueprint.items.Count; i++)
        {
            int index = i;
            buttons[i] = Instantiate(buttonPrefab);

            RectTransform rt = buttons[i].GetComponent <RectTransform>();
            rt.SetParent(background, false);
            rt.anchoredPosition = new Vector2(185 + (i % 5) * 64, -40 - (i > 4 ? 64 : 0));

            Button button = buttons[i].GetComponent <Button>();
            button.onClick.AddListener(() => { onButtonPressed(index); });

            VendorUIButton vendorUIButton = buttons[i].GetComponent <VendorUIButton>();

            if (player.GetPower() < blueprint.items[i].cost)
            {
                buttons[i].GetComponent <Image>().color = new Color(0, 0, 0.4F);
            }

            vendorUIButton.blueprint       = blueprint.items[i].entityBlueprint;
            vendorUIButton.costText        = "POWER COST: <color=cyan>" + blueprint.items[i].cost + "</color>";
            vendorUIButton.descriptionText = blueprint.items[i].description;
            vendorUIButton.tooltipPrefab   = tooltipPrefab;
            vendorUIButton.costInfo        = costInfo;
            vendorUIButton.nameInfo        = nameInfo;
            vendorUIButton.handler         = UI.GetComponentInChildren <SelectionDisplayHandler>();

            Image sr = buttons[i].transform.Find("Icon").GetComponent <Image>();
            sr.sprite = blueprint.items[i].icon;

            Text[] texts = buttons[i].GetComponentsInChildren <Text>();
            texts[0].text  = i + 1 + "";
            texts[1].text  = blueprint.items[i].cost + "";
            texts[1].color = Color.cyan;
        }
        opened = true;
    }