예제 #1
0
        /// <summary>Alternative inspector control (eg: EditorGUILayout.SpriteField) for Image.sprite/VectorImage.vectorImageData/Text.text. Supports undo/redo and multiple selected objects.</summary>
        /// <param name="label">The label to appear in the inspector control.</param>
        /// <param name="graphics">The Graphics that the modifications will be applied to.</param>
        /// <param name="visualReference">The Graphic to use for the 'current' values in the control if the Graphic values are different.</param>
        /// <returns>Whether the control was successfully able to be drawn.</returns>
        public static bool GraphicMultiField(string label, Graphic[] graphics, Graphic visualReference = null)
        {
            if (visualReference == null)
            {
                visualReference = graphics[0];
            }

            Image image = visualReference as Image;

            if (image != null)
            {
                ImageMultiField(label, graphics.Select(graphic => graphic as Image).ToArray(), visualReference as Image);
                return(true);
            }

            VectorImage vectorImage = visualReference as VectorImage;

            if (vectorImage != null)
            {
                VectorImageMultiField(label, graphics.Select(graphic => graphic as VectorImage).ToArray(), visualReference as VectorImage);
                return(true);
            }

            Text text = visualReference as Text;

            if (text != null)
            {
                TextMultiField(label, graphics.Select(graphic => graphic as Text).ToArray(), visualReference as Text);
                return(true);
            }

            return(true);
        }
예제 #2
0
        /// <summary>Alternative inspector control (eg: EditorGUILayout.SpriteField) for Image.sprite/VectorImage.vectorImageData/Text.text. Supports undo/redo.</summary>
        /// <param name="label">The label to appear in the inspector control.</param>
        /// <param name="graphic">The Graphic to modify.</param>
        /// <param name="disableIfMultipleObjectsSelected">Is this field drawn disabled if multiple GameObjects are selected?</param>
        /// <returns>Whether the control was successfully able to be drawn.</returns>
        public static bool GraphicField(string label, Graphic graphic, bool disableIfMultipleObjectsSelected = true)
        {
            using (new DisabledScope(TooManySelected(!disableIfMultipleObjectsSelected)))
            {
                Image image = graphic as Image;
                if (image != null)
                {
                    ImageField(label, image, disableIfMultipleObjectsSelected);
                    return(true);
                }

                VectorImage vectorImage = graphic as VectorImage;
                if (vectorImage != null)
                {
                    VectorImageField(label, vectorImage, disableIfMultipleObjectsSelected);
                    return(true);
                }

                Text text = graphic as Text;
                if (text != null)
                {
                    TextField(label, text);
                    return(true);
                }
            }

            return(false);
        }
예제 #3
0
        /// <summary>
        /// Sets the image of a Graphic (must be of type VectorImage).
        /// </summary>
        /// <param name="graphic">The graphic to modify.</param>
        /// <param name="vectorImageData">The vector image data to set.</param>
        public static void SetImage(this Graphic graphic, VectorImageData vectorImageData)
        {
            VectorImage imageToSet = graphic as VectorImage;

            if (imageToSet != null)
            {
                imageToSet.vectorImageData = vectorImageData;
            }
        }
예제 #4
0
        /// <summary>
        /// Gets the vector image.
        /// </summary>
        /// <param name="graphic">The graphic to check.</param>
        /// <returns>The VectorImageData of the Graphic, if applicable and one exists.</returns>
        public static VectorImageData GetVectorImage(this Graphic graphic)
        {
            VectorImage imageToGet = graphic as VectorImage;

            if (imageToGet != null)
            {
                return(imageToGet.vectorImageData);
            }

            return(null);
        }
예제 #5
0
        private bool ExternalPropertiesSection()
        {
            bool result = false;

            //  Content

            Text text = m_Text.objectReferenceValue as Text;
            if (text != null)
            {
                NonSerializedPropertyField(text, () => text.text = EditorGUILayout.TextField("Button Text", text.text));
                result = true;
            }

            Graphic iconGraphic = null;

            Image image = m_Icon.objectReferenceValue as Image;
            if (image != null)
            {
                NonSerializedPropertyField(image, () => image.sprite = (Sprite)EditorGUILayout.ObjectField(new GUIContent("Button Icon"), image.sprite, typeof(Sprite), true));
                iconGraphic = image;
                result = true;
            }

            VectorImage vectorImage = m_Icon.objectReferenceValue as VectorImage;
            if (vectorImage != null)
            {
                NonSerializedPropertyField(vectorImage, () => MaterialUIInspectorFields.VectorImageDataField("Button Icon", vectorImage.vectorImageData, vectorImage));
                iconGraphic = vectorImage;
                result = true;
            }

            //  Color

            Image backgroundImage = m_BackgroundImage.objectReferenceValue as Image;
            if (backgroundImage != null)
            {
                NonSerializedPropertyField(backgroundImage, () => backgroundImage.color = EditorGUILayout.ColorField("Button Color", backgroundImage.color));
            }

            if (text != null)
            {
                NonSerializedPropertyField(text, () => text.color = EditorGUILayout.ColorField("Text Color", text.color));
            }

            if (iconGraphic != null)
            {
                NonSerializedPropertyField(iconGraphic, () => iconGraphic.color = EditorGUILayout.ColorField("Icon Color", iconGraphic.color));
            }

            return result;
        }
        public void Initialize(OptionDataList optionDataList, Action <int> onItemClick, string titleText, ImageData icon)
        {
            m_TitleSection.SetTitle(titleText, icon);

            m_OptionDataList = optionDataList;
            m_SelectionItems = new List <DialogSimpleOption>();

            Image       imageIcon  = m_OptionTemplate.GetChildByName <Image>("Icon");
            VectorImage vectorIcon = m_OptionTemplate.GetChildByName <VectorImage>("Icon");

            if (m_OptionDataList.options.Count > 0 && m_OptionDataList.options[0].imageData != null)
            {
                if (m_OptionDataList.options[0].imageData.imageDataType == ImageDataType.Sprite)
                {
                    DestroyImmediate(vectorIcon.gameObject);
                }
                else
                {
                    DestroyImmediate(imageIcon.gameObject);
                }
            }
            else
            {
                DestroyImmediate(imageIcon.gameObject);
            }

            for (int i = 0; i < m_OptionDataList.options.Count; i++)
            {
                m_SelectionItems.Add(CreateSelectionItem(i));
            }

            float availableHeight = DialogManager.rectTransform.rect.height;

            LayoutGroup textAreaRectTransform = m_TitleSection.text.transform.parent.GetComponent <LayoutGroup>();

            if (textAreaRectTransform.gameObject.activeSelf)
            {
                textAreaRectTransform.CalculateLayoutInputVertical();
                availableHeight -= textAreaRectTransform.preferredHeight;
            }

            m_ListScrollLayoutElement.maxHeight = availableHeight - 48f;

            Destroy(m_OptionTemplate);

            m_OnItemClick = onItemClick;

            Initialize();
        }
예제 #7
0
        public void Create(int id, VectorImageData imageData)
        {
            if (m_Id != 0)
            {
                Debug.Log("Cannot Setup a Ripple more than once");
                return;
            }

            m_Id = id;
            m_RectTransform = GetComponent<RectTransform>();
            m_Image = GetComponent<VectorImage>();
            m_CanvasGroup = GetComponent<CanvasGroup>();
            m_Image.vectorImageData = imageData;
            m_CanvasGroup.blocksRaycasts = false;
            m_CanvasGroup.interactable = false;
            gameObject.AddComponent<LayoutElement>().ignoreLayout = true;
        }
예제 #8
0
        public void Create(int id, VectorImageData imageData)
        {
            if (m_Id != 0)
            {
                Debug.Log("Cannot Setup a Ripple more than once");
                return;
            }

            m_Id                         = id;
            m_RectTransform              = GetComponent <RectTransform>();
            m_Image                      = GetComponent <VectorImage>();
            m_CanvasGroup                = GetComponent <CanvasGroup>();
            m_Image.vectorImageData      = imageData;
            m_CanvasGroup.blocksRaycasts = false;
            m_CanvasGroup.interactable   = false;
            gameObject.AddComponent <LayoutElement>().ignoreLayout = true;
        }
예제 #9
0
        /// <summary>
        /// Sets the image of a Graphic (must be of type Image if imageData has type Sprite, or VectorImage if imageData has type VectorImageData).
        /// </summary>
        /// <param name="graphic">The graphic to modify.</param>
        /// <param name="imageData">The image data to set.</param>
        public static void SetImage(this Graphic graphic, ImageData imageData)
        {
            VectorImage vectorImage = graphic as VectorImage;

            if (vectorImage != null && imageData != null)
            {
                if (imageData.imageDataType == ImageDataType.VectorImage)
                {
                    vectorImage.vectorImageData = imageData.vectorImageData;
                }
                return;
            }

            Image spriteImage = graphic as Image;

            if (spriteImage != null && imageData != null)
            {
                if (imageData.imageDataType == ImageDataType.Sprite)
                {
                    spriteImage.sprite = imageData.sprite;
                }
            }
        }
        /// <summary>Inspector control (eg: EditorGUILayout.SpriteField) for VectorImage.vectorImageData. Supports undo/redo.</summary>
        /// <param name="label">The label to appear in the inspector control.</param>
        /// <param name="vectorImages">The VectorImages to modify.</param>
        /// <param name="visualReference">
        ///     The VectorImage to use for the 'current' values in the control if the VectorImage values
        ///     are different.
        /// </param>
        /// <returns>Whether the control was successfully able to be drawn.</returns>
        public static bool VectorImageMultiField(string label, VectorImage[] vectorImages,
                                                 VectorImage visualReference = null)
        {
            if (vectorImages.ToList().TrueForAll(vectorImage => vectorImage == null))
            {
                return(false);
            }

            if (visualReference == null)
            {
                visualReference = vectorImages.ToList().First(vectorImage => vectorImage != null);
            }

            var vectorImageDatas = new List <VectorImageData>();

            for (var i = 0; i < vectorImages.Length; i++)
            {
                if (vectorImages[i] != null && vectorImages[i].vectorImageData != null)
                {
                    vectorImageDatas.Add(vectorImages[i].vectorImageData);
                }
            }

            Action iconPickAction = () =>
            {
                for (var i = 0; i < vectorImages.Length; i++)
                {
                    if (vectorImages[i] != null)
                    {
                        vectorImages[i].Refresh();
                    }
                }
            };

            return(VectorImageDataMultiField(label, vectorImageDatas.ToArray(), vectorImages, iconPickAction,
                                             visualReference.vectorImageData));
        }
예제 #11
0
        public void Convert(bool noExitGUI = false)
        {
#if UNITY_EDITOR
            string flatRoundedSquare   = "Assets/MaterialUI/Images/RoundedSquare/roundedsquare_";
            string raisedRoundedSquare = "Assets/MaterialUI/Images/RoundedSquare_Stroke/roundedsquare_stroke_";

            string imagePath = "";

            if (!isCircularButton)
            {
                imagePath = isRaisedButton ? flatRoundedSquare : raisedRoundedSquare;
            }

            if (isRaisedButton)
            {
                DestroyImmediate(m_ShadowsCanvasGroup.gameObject);
                m_ShadowsCanvasGroup = null;

                if (materialShadow)
                {
                    DestroyImmediate(materialShadow);
                }

                if (materialRipple != null)
                {
                    materialRipple.highlightWhen = MaterialRipple.HighlightActive.Hovered;
                }
            }
            else
            {
                string path = isCircularButton ? pathToCirclePrefab : pathToRectPrefab;

                GameObject tempButton = Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>(path));

                GameObject newShadow = tempButton.transform.Find("Shadows").gameObject;

                m_ShadowsCanvasGroup = newShadow.GetComponent <CanvasGroup>();

                RectTransform newShadowRectTransform = (RectTransform)newShadow.transform;

                newShadowRectTransform.SetParent(rectTransform);
                newShadowRectTransform.SetAsFirstSibling();
                newShadowRectTransform.localScale       = Vector3.one;
                newShadowRectTransform.localEulerAngles = Vector3.zero;

                RectTransform tempRectTransform = m_BackgroundImage != null
                    ? (RectTransform)m_BackgroundImage.transform
                    : rectTransform;

                if (isCircularButton)
                {
                    newShadowRectTransform.anchoredPosition = Vector2.zero;
                    RectTransformSnap newSnapper = newShadow.GetAddComponent <RectTransformSnap>();
                    newSnapper.sourceRectTransform = tempRectTransform;
                    newSnapper.valuesArePercentage = true;
                    newSnapper.snapWidth           = true;
                    newSnapper.snapHeight          = true;
                    newSnapper.snapEveryFrame      = true;
                    newSnapper.paddingPercent      = new Vector2(225, 225);
                    Vector3 tempVector3 = rectTransform.GetPositionRegardlessOfPivot();
                    tempVector3.y -= 1f;
                    newShadowRectTransform.position = tempVector3;
                }
                else
                {
                    newShadowRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, tempRectTransform.GetProperSize().x + 54);
                    newShadowRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, tempRectTransform.GetProperSize().y + 54);
                    Vector3 tempVector3 = rectTransform.GetPositionRegardlessOfPivot();
                    newShadowRectTransform.position = tempVector3;
                }

                DestroyImmediate(tempButton);

                gameObject.AddComponent <MaterialShadow>();

                materialShadow.shadowsActiveWhen = MaterialShadow.ShadowsActive.Hovered;

                materialShadow.animatedShadows = newShadow.GetComponentsInChildren <AnimatedShadow>();

                materialShadow.isEnabled = true;

                if (materialRipple != null)
                {
                    materialRipple.highlightWhen = MaterialRipple.HighlightActive.Clicked;
                }
            }

            if (!isCircularButton)
            {
                SpriteSwapper spriteSwapper = GetComponent <SpriteSwapper>();

                if (spriteSwapper != null)
                {
                    spriteSwapper.sprite1X = AssetDatabase.LoadAssetAtPath <Sprite>(imagePath + "100%.png");
                    spriteSwapper.sprite2X = AssetDatabase.LoadAssetAtPath <Sprite>(imagePath + "200%.png");
                    spriteSwapper.sprite4X = AssetDatabase.LoadAssetAtPath <Sprite>(imagePath + "400%.png");
                }
                else
                {
                    if (m_BackgroundImage != null)
                    {
                        ((Image)m_BackgroundImage).sprite = AssetDatabase.LoadAssetAtPath <Sprite>(imagePath + "100%.png");
                    }
                }
            }
            else
            {
                if (!isRaisedButton)
                {
                    RectTransform tempRectTransform = (RectTransform) new GameObject("Stroke", typeof(VectorImage)).transform;

                    tempRectTransform.SetParent(m_BackgroundImage.rectTransform);
                    tempRectTransform.localScale       = Vector3.one;
                    tempRectTransform.localEulerAngles = Vector3.zero;
                    tempRectTransform.anchorMin        = Vector2.zero;
                    tempRectTransform.anchorMax        = Vector2.one;
                    tempRectTransform.anchoredPosition = Vector2.zero;
                    tempRectTransform.sizeDelta        = Vector2.zero;

                    VectorImage vectorImage = tempRectTransform.GetComponent <VectorImage>();
                    vectorImage.vectorImageData = MaterialUIIconHelper.GetIcon("circle_stroke_thin").vectorImageData;
                    vectorImage.sizeMode        = VectorImage.SizeMode.MatchMin;
                    vectorImage.color           = new Color(0f, 0f, 0f, 0.125f);

                    tempRectTransform.name = "Stroke";
                }
                else
                {
                    VectorImage[] images = backgroundImage.GetComponentsInChildren <VectorImage>();

                    for (int i = 0; i < images.Length; i++)
                    {
                        if (images[i].name == "Stroke")
                        {
                            DestroyImmediate(images[i].gameObject);
                        }
                    }
                }
            }

            name = isRaisedButton ? name.Replace("Raised", "Flat") : name.Replace("Flat", "Raised");

            if (m_BackgroundImage != null)
            {
                if (!isRaisedButton)
                {
                    if (m_BackgroundImage.color == Color.clear)
                    {
                        m_BackgroundImage.color = Color.white;
                    }
                }
                else
                {
                    if (m_BackgroundImage.color == Color.white)
                    {
                        m_BackgroundImage.color = Color.clear;
                    }
                }
            }

            m_IsRaisedButton = !m_IsRaisedButton;

            if (!noExitGUI)
            {
                GUIUtility.ExitGUI();
            }
#endif
        }
 /// <summary>Inspector control (eg: EditorGUILayout.SpriteField) for VectorImage.vectorImageData. Supports undo/redo.</summary>
 /// <param name="label">The label to appear in the inspector control.</param>
 /// <param name="getReferenceFunc">The function used to get each VectorImage reference from each selected GameObject.</param>
 /// <param name="visualReference">
 ///     The VectorImage to use for the 'current' values in the control if the VectorImage values
 ///     are different.
 /// </param>
 /// <returns>Whether the control was successfully able to be drawn.</returns>
 public static bool VectorImageMultiField(string label, Func <GameObject, VectorImage> getReferenceFunc,
                                          VectorImage visualReference = null)
 {
     return(VectorImageMultiField(label, Selection.gameObjects.Select(getReferenceFunc).ToArray(),
                                  visualReference));
 }
 /// <summary>Inspector control (eg: EditorGUILayout.SpriteField) for VectorImage.vectorImageData. Supports undo/redo.</summary>
 /// <param name="label">The label to appear in the inspector control.</param>
 /// <param name="vectorImage">The VectorImage to modify.</param>
 /// <param name="disableIfMultipleObjectsSelected">Is this field drawn disabled if multiple GameObjects are selected?</param>
 /// <returns>Whether the control was successfully able to be drawn.</returns>
 public static bool VectorImageField(string label, VectorImage vectorImage,
                                     bool disableIfMultipleObjectsSelected = true)
 {
     return(VectorImageDataField(label, vectorImage.vectorImageData, vectorImage, vectorImage.Refresh,
                                 disableIfMultipleObjectsSelected));
 }