예제 #1
0
        public static Image CreateAndGetMagicItemBackgroundImage(GameObject elementGo, GameObject equipped, bool isInventoryGrid)
        {
            var magicItemTransform = (RectTransform)elementGo.transform.Find("magicItem");

            if (magicItemTransform == null)
            {
                var magicItemObject = Object.Instantiate(equipped, equipped.transform.parent);
                magicItemObject.transform.SetSiblingIndex(EpicLoot.HasAuga ? equipped.transform.GetSiblingIndex() : equipped.transform.GetSiblingIndex() + 1);
                magicItemObject.name = "magicItem";
                magicItemObject.SetActive(true);
                magicItemTransform           = (RectTransform)magicItemObject.transform;
                magicItemTransform.anchorMin = magicItemTransform.anchorMax = new Vector2(0.5f, 0.5f);
                magicItemTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 64);
                magicItemTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 64);
                magicItemTransform.pivot            = new Vector2(0.5f, 0.5f);
                magicItemTransform.anchoredPosition = Vector2.zero;
                var magicItemInit = magicItemTransform.GetComponent <Image>();
                magicItemInit.color         = Color.white;
                magicItemInit.raycastTarget = false;
            }

            // Also add set item marker
            if (isInventoryGrid)
            {
                var setItemTransform = (RectTransform)elementGo.transform.Find("setItem");
                if (setItemTransform == null)
                {
                    var setItemObject = Object.Instantiate(equipped, equipped.transform.parent);
                    setItemObject.transform.SetAsLastSibling();
                    setItemObject.name = "setItem";
                    setItemObject.SetActive(true);
                    setItemTransform           = (RectTransform)setItemObject.transform;
                    setItemTransform.anchorMin = setItemTransform.anchorMax = new Vector2(0.5f, 0.5f);
                    setItemTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 64);
                    setItemTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 64);
                    setItemTransform.pivot            = new Vector2(0.5f, 0.5f);
                    setItemTransform.anchoredPosition = Vector2.zero;
                    var setItemInit = setItemTransform.GetComponent <Image>();
                    setItemInit.raycastTarget = false;
                    setItemInit.sprite        = EpicLoot.GetSetItemSprite();
                    setItemInit.color         = ColorUtility.TryParseHtmlString(EpicLoot.GetSetItemColor(), out var color) ? color : Color.white;
                }
            }

            // Also change equipped image
            var equippedImage = equipped.GetComponent <Image>();

            if (equippedImage != null && (!isInventoryGrid || !EpicLoot.HasAuga))
            {
                equippedImage.sprite        = EpicLoot.GetEquippedSprite();
                equippedImage.color         = Color.white;
                equippedImage.raycastTarget = false;
                var rectTransform = equipped.RectTransform();
                rectTransform.anchorMin        = new Vector2(0.5f, 0.5f);
                rectTransform.anchorMax        = new Vector2(0.5f, 0.5f);
                rectTransform.pivot            = new Vector2(0.5f, 0.5f);
                rectTransform.anchoredPosition = Vector2.zero;
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, equippedImage.sprite.texture.width);
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, equippedImage.sprite.texture.height);
            }

            return(magicItemTransform.GetComponent <Image>());
        }