コード例 #1
0
        /// <summary>
        /// Sets the matter and quantity to display.
        /// </summary>
        /// <param name="matter">The matter to display.</param>
        /// <param name="quantity">The quantity to display.</param>
        public void SetDisplay(Matter matter, int quantity)
        {
            this.matterToDisplay   = matter;
            this.quantityToDisplay = quantity;

            this.matterIcon.enabled = matter != null;
            this.matterIcon.sprite  = matter != null?matter.GetIcon() : null;

            this.quantityGameObject.SetActive(quantity > 1);
            this.quantityText.text = quantity.ToString();
        }
コード例 #2
0
        /// <summary>
        /// Sets the matter to display on this UI element.
        /// </summary>
        /// <param name="matter">The matter to display. `null` will hide the icon.</param>
        /// <param name="showRequiredComponents">Whether to display the required components for the given <paramref name="matter"/>.</param>
        public void SetMatter(Matter matter, bool showRequiredComponents = true)
        {
            if (matter != null)
            {
                this.iconUI.sprite  = matter.GetIcon();
                this.iconUI.enabled = true;

                if (showRequiredComponents && matter is MatterCompound)
                {
                    this.ClearRequiredComponents();
                    this.requiredMatterContainer.SetActive(true);

                    Dictionary <Matter, int> requiredMatters = new Dictionary <Matter, int>();
                    foreach (Matter component in ((MatterCompound)matter).Components)
                    {
                        if (!requiredMatters.ContainsKey(component))
                        {
                            requiredMatters.Add(component, 1);
                        }
                        else
                        {
                            requiredMatters[component]++;
                        }
                    }

                    var enumerator = requiredMatters.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        GameObject uiElement  = GameObject.Instantiate(this.matterIconPrefab, Vector3.zero, Quaternion.identity, this.requiredMatterContainer.transform);
                        MatterIcon matterIcon = uiElement.GetComponent <MatterIcon>();
                        matterIcon?.SetDisplay(enumerator.Current.Key, enumerator.Current.Value);
                    }
                }
                else
                {
                    this.requiredMatterContainer.SetActive(false);
                }
            }
            else
            {
                this.iconUI.enabled = false;
            }
        }
コード例 #3
0
 /// <summary>
 /// Sets the given matter as the contained matter of this supplybox.
 /// Updates the displayed matter texture to show the new matter icon.
 /// </summary>
 /// <param name="matter">Matter to be contained in this supplybox or `null`.</param>
 public void SetContainedMatter(Matter matter)
 {
     this.containedMatter = matter;
     if (this.matterDisplayMaterial != null)
     {
         this.matterDisplayMaterial.SetTexture(this.matterDisplayTextureField, matter != null ? matter.GetIcon().texture : null);
     }
 }