Esempio n. 1
0
        /**
         * <summary>Links the UI GameObjects to the class, based on the supplied uiButtonID.</summary>
         * <param name = "canvas">The Canvas that contains the UI GameObjects</param>
         * <param name = "linkUIGraphic">What Image component the Element's Graphics should be linked to (ImageComponent, ButtonTargetGraphic)</param>
         * <param name = "emptySlotTexture">If set, the texture to use when a slot is considered empty</param>
         */
        public void LinkUIElements(Canvas canvas, LinkUIGraphic linkUIGraphic, Texture2D emptySlotTexture = null)
        {
            if (canvas != null)
            {
                uiButton = Serializer.GetGameObjectComponent <UnityEngine.UI.Button> (uiButtonID, canvas.gameObject);
            }
            else
            {
                uiButton = null;
            }

            if (uiButton)
            {
                                #if TextMeshProIsPresent
                uiText = uiButton.GetComponentInChildren <TMPro.TextMeshProUGUI>();
                                #else
                uiText = uiButton.GetComponentInChildren <Text>();
                                #endif
                uiRawImage = uiButton.GetComponentInChildren <RawImage>();

                if (linkUIGraphic == LinkUIGraphic.ImageComponent)
                {
                    uiImage = uiButton.GetComponentInChildren <Image>();
                }
                else if (linkUIGraphic == LinkUIGraphic.ButtonTargetGraphic)
                {
                    if (uiButton.targetGraphic != null)
                    {
                        if (uiButton.targetGraphic is Image)
                        {
                            uiImage = uiButton.targetGraphic as Image;
                        }
                        else
                        {
                            ACDebug.LogWarning("Cannot assign UI Image for " + uiButton.name + "'s target graphic as " + uiButton.targetGraphic + " is not an Image component.", canvas);
                        }
                    }
                    else
                    {
                        ACDebug.LogWarning("Cannot assign UI Image for " + uiButton.name + "'s target graphic because it has none.", canvas);
                    }
                }

                originalColour = uiButton.colors.normalColor;
            }

            if (emptySlotTexture != null)
            {
                emptySprite = Sprite.Create(emptySlotTexture, new Rect(0f, 0f, emptySlotTexture.width, emptySlotTexture.height), new Vector2(0.5f, 0.5f), 100f, 0, SpriteMeshType.FullRect);
            }
        }
Esempio n. 2
0
        protected T LinkUIElement <T> (Canvas canvas) where T : Behaviour
        {
            if (canvas != null)
            {
                T field = Serializer.GetGameObjectComponent <T> (linkedUiID, canvas.gameObject);

                if (field == null)
                {
                    ACDebug.LogWarning("Cannot find linked UI Element for " + title, canvas);
                }
                return(field);
            }
            return(null);
        }
Esempio n. 3
0
        /**
         * <summary>Links the UI GameObjects to the class, based on the supplied uiButtonID.</summary>
         * <param name = "canvas">The Canvas that contains the UI GameObjects</param>
         * <param name = "linkUIGraphic">What Image component the Element's Graphics should be linked to (ImageComponent, ButtonTargetGraphic)</param>
         */
        public void LinkUIElements(Canvas canvas, LinkUIGraphic linkUIGraphic)
        {
            if (canvas != null)
            {
                uiButton = Serializer.GetGameObjectComponent <UnityEngine.UI.Button> (uiButtonID, canvas.gameObject);
            }
            else
            {
                uiButton = null;
            }

            if (uiButton)
            {
                if (uiButton.GetComponentInChildren <Text>())
                {
                    uiText = uiButton.GetComponentInChildren <Text>();
                }
                if (uiButton.GetComponentInChildren <RawImage>())
                {
                    uiRawImage = uiButton.GetComponentInChildren <RawImage>();
                }
                if (linkUIGraphic == LinkUIGraphic.ImageComponent && uiButton.GetComponentInChildren <Image>())
                {
                    uiImage = uiButton.GetComponentInChildren <Image>();
                }
                else if (linkUIGraphic == LinkUIGraphic.ButtonTargetGraphic)
                {
                    if (uiButton.targetGraphic != null)
                    {
                        if (uiButton.targetGraphic is Image)
                        {
                            uiImage = uiButton.targetGraphic as Image;
                        }
                        else
                        {
                            ACDebug.LogWarning("Cannot assign UI Image for " + uiButton.name + "'s target graphic as " + uiButton.targetGraphic + " is not an Image component.", canvas);
                        }
                    }
                    else
                    {
                        ACDebug.LogWarning("Cannot assign UI Image for " + uiButton.name + "'s target graphic because it has none.", canvas);
                    }
                }

                originalColour = uiButton.colors.normalColor;
            }
        }