コード例 #1
0
        /// <summary>
        /// Sets an element's color on all referenced buttons.
        /// </summary>
        /// <param name="buttonIndex">The index of the button array to modify.</param>
        /// <param name="color">The color to set the button element.</param>
        /// <param name="element">The element of the buttons to modify.</param>
        /// <param name="animate">Animate the transition? Always false if in edit mode.</param>
        public void SetButtonGraphicColor(int buttonIndex, Color color, ButtonElement element, bool animate = true)
        {
            MaterialButton button = m_Buttons[buttonIndex];

            if (button != null)
            {
                Graphic graphic = element == ButtonElement.Text ? button.text : (element == ButtonElement.Icon ? button.icon : button.backgroundImage);

                if (graphic == null)
                {
                    return;
                }

                TweenGraphicColor(graphic, color, animate, () => button.RefreshRippleMatchColor());
            }
        }
コード例 #2
0
        void OnEnable()
        {
            OnBaseEnable();

            m_SelectedMaterialButton  = (MaterialButton)target;
            m_SelectedMaterialButtons = new TargetArray <MaterialButton>(targets);

            m_Interactable = serializedObject.FindProperty("m_Interactable");

            m_ResetRippleOnDisable = serializedObject.FindProperty("m_ResetRippleOnDisable");

            m_ShadowsCanvasGroup   = serializedObject.FindProperty("m_ShadowsCanvasGroup");
            m_ContentRectTransform = serializedObject.FindProperty("m_ContentRectTransform");

            m_BackgroundImage = serializedObject.FindProperty("m_BackgroundImage");
            m_Text            = serializedObject.FindProperty("m_Text");
            m_Icon            = serializedObject.FindProperty("m_Icon");

            m_ContentPaddingX = serializedObject.FindProperty("m_ContentPadding.x");
            m_ContentPaddingY = serializedObject.FindProperty("m_ContentPadding.y");

            m_FitWidthToContent  = serializedObject.FindProperty("m_FitWidthToContent");
            m_FitHeightToContent = serializedObject.FindProperty("m_FitHeightToContent");
        }
コード例 #3
0
        /// <summary>Inspector control (eg: EditorGUILayout.SpriteField) for all of MaterialButton's external values. Supports undo/redo.</summary>
        /// <param name="materialButton">The MaterialButton to modify.</param>
        /// <param name="showBox">Whether to surround the inspector controls with a box.</param>
        /// <returns>Whether the control was successfully able to be drawn.</returns>
        public static bool MaterialButtonField(MaterialButton materialButton, bool showBox = true)
        {
            if (materialButton == null)
            {
                return(false);
            }

            string nameLabel = "'" + materialButton.name + "' ";

            bool result = false;

            if (materialButton.text == null && materialButton.icon == null && materialButton.backgroundImage == null)
            {
                return(false);
            }

            using (showBox ? new EditorGUILayout.VerticalScope("Box") : new EditorGUILayout.VerticalScope())
            {
                if (GraphicColorField(nameLabel + "Text", materialButton.text))
                {
                    nameLabel = showBox ? "" : "^ ";
                    result    = true;
                }
                if (GraphicColorField(nameLabel + "Icon", materialButton.icon))
                {
                    nameLabel = showBox ? "" : "^ ";
                    result    = true;
                }
                if (GraphicColorField(nameLabel + "Background", materialButton.backgroundImage))
                {
                    result = true;
                }
            }

            return(result);
        }
コード例 #4
0
        /// <summary>Inspector control (eg: EditorGUILayout.SpriteField) for all of MaterialButton's external values. Supports undo/redo and multiple selected objects.</summary>
        /// <param name="materialButtons">The MaterialButtons to modify.</param>
        /// <param name="showBox">Whether to surround the inspector controls with a box</param>
        /// <param name="visualReference">The MaterialButton to use for the 'current' values in the control if the MaterialButton values are different.</param>
        /// <returns>Whether the control was successfully able to be drawn.</returns>
        public static bool MaterialButtonMultiField(MaterialButton[] materialButtons, bool showBox = true, MaterialButton visualReference = null)
        {
            if (materialButtons.ToList().TrueForAll(materialButton => materialButton == null))
            {
                return(false);
            }

            if (visualReference == null)
            {
                visualReference = materialButtons.ToList().First(materialButton => materialButton != null);
            }

            string nameLabel = "'" + visualReference.name + "' ";

            bool result = false;

            bool hasText       = false;
            bool hasIcon       = false;
            bool hasBackground = false;

            List <Graphic> textGraphics       = new List <Graphic>();
            List <Graphic> iconGraphics       = new List <Graphic>();
            List <Graphic> backgroundGraphics = new List <Graphic>();

            for (int i = 0; i < materialButtons.Length; i++)
            {
                MaterialButton button = materialButtons[i];
                if (button == null)
                {
                    continue;
                }

                if (button.text != null)
                {
                    textGraphics.Add(button.text);
                    hasText = true;
                }

                if (button.icon != null)
                {
                    iconGraphics.Add(button.icon);
                    hasIcon = true;
                }

                if (button.backgroundImage != null)
                {
                    backgroundGraphics.Add(button.backgroundImage);
                    hasBackground = true;
                }
            }

            if (!hasText && !hasIcon && !hasBackground)
            {
                return(false);
            }

            using (showBox ? new EditorGUILayout.VerticalScope("Box") : new EditorGUILayout.VerticalScope())
            {
                if (hasText)
                {
                    GraphicColorMultiField(nameLabel + "Text", textGraphics.ToArray());
                    nameLabel = showBox ? "" : "^ ";
                    result    = true;
                }

                if (hasIcon)
                {
                    GraphicColorMultiField(nameLabel + "Icon", iconGraphics.ToArray());
                    nameLabel = showBox ? "" : "^ ";
                    result    = true;
                }

                if (hasBackground)
                {
                    GraphicColorMultiField(nameLabel + "Background", backgroundGraphics.ToArray());
                    result = true;
                }
            }

            return(result);
        }
コード例 #5
0
 /// <summary>Inspector control (eg: EditorGUILayout.SpriteField) for all of MaterialButton's external values. Supports undo/redo and multiple selected objects.</summary>
 /// <param name="getReferenceFunc">The function used to get each Graphic reference from each selected GameObject.</param>
 /// <param name="showBox">Whether to surround the inspector controls with a box</param>
 /// <param name="visualReference">The MaterialButton to use for the 'current' values in the control if the MaterialButton values are different.</param>
 /// <returns>Whether the control was successfully able to be drawn.</returns>
 public static bool MaterialButtonMultiField(Func <GameObject, MaterialButton> getReferenceFunc, bool showBox = true, MaterialButton visualReference = null)
 {
     return(MaterialButtonMultiField(Selection.gameObjects.Select(getReferenceFunc).ToArray(), showBox, visualReference));
 }