예제 #1
0
 public bool ContainsData(bool checkCurrentTypeOnly)
 {
     if (checkCurrentTypeOnly)
     {
         if (m_ImageDataType == ImageDataType.Sprite)
         {
             return(m_Sprite != null);
         }
         else
         {
             return(m_VectorImageData != null && m_VectorImageData.ContainsData());
         }
     }
     else
     {
         return(m_Sprite != null || (m_VectorImageData != null && m_VectorImageData.ContainsData()));
     }
 }
예제 #2
0
 public bool ContainsData(bool checkCurrentTypeOnly)
 {
     if (checkCurrentTypeOnly)
     {
         if (m_ImageDataType == ImageDataType.Sprite)
         {
             return(!string.IsNullOrEmpty(m_ImgUrl) || m_Sprite != null);
         }
         else
         {
             return(m_VectorImageData != null && m_VectorImageData.ContainsData());
         }
     }
     else
     {
         return(m_Sprite != null || (m_VectorImageData != null && m_VectorImageData.ContainsData()) || !string.IsNullOrEmpty(m_ImgUrl));
     }
 }
        public override void Show()
        {
            var prefabAddress = cachedPrefabAddress == null || cachedPrefabAddress.IsEmpty() || !cachedPrefabAddress.IsResources() ?
                                PrefabManager.ResourcePrefabs.dialogTooltip : cachedPrefabAddress;

            if (prefabAddress == null ||
                (string.IsNullOrEmpty(m_TipText) && (m_TipImageData == null || !m_TipImageData.ContainsData())))
            {
                if (IsExpanded())
                {
                    Hide();
                }
                return;
            }

            ShowFrameActivity(_CacheDialogFrame, prefabAddress, (dialog, isDialog) =>
            {
                _CacheDialogFrame = dialog;
                if (dialog != null)
                {
                    dialog.Initialize("", null, null, m_TipText, new ImageData(m_TipImageData), null, null);
                }
            });
        }
예제 #4
0
        /// <summary>Inspector control (eg: EditorGUILayout.SpriteField) for VectorImageData. Supports undo/redo and multiple selected objects.</summary>
        /// <param name="label">The label to appear in the inspector control.</param>
        /// <param name="targetDatas">The VectorImageDatas to modify.</param>
        /// <param name="objectsToUndo">The objects to mark for undo/redo.</param>
        /// <param name="onIconPickAction">Action to call when an icon is picked.</param>
        /// <param name="visualReference">The VectorImageData to use for the 'current' values in the control if the VectorImageData values are different.</param>
        /// <returns>Whether the control was successfully able to be drawn.</returns>
        public static bool VectorImageDataMultiField(string label, VectorImageData[] targetDatas, Object[] objectsToUndo, Action onIconPickAction = null, VectorImageData visualReference = null)
        {
            if (targetDatas.ToList().TrueForAll(data => data == null))
            {
                return(false);
            }

            if (visualReference == null)
            {
                visualReference = targetDatas.ToList().First(data => data != null);
            }

            string code       = visualReference.glyph.unicode;
            string name       = visualReference.glyph.name;
            Font   font       = visualReference.font;
            var    vectorFont = visualReference.vectorFont;

            GUIStyle iconStyle = null;

            s_iconStyles.TryGetValue(visualReference, out iconStyle);
            if (iconStyle == null)
            {
                iconStyle = new GUIStyle {
                    font = font, fontSize = font != null && font.dynamic ? vectorIconSize : 0
                };
                if (iconStyle.font == null && vectorFont != null && vectorFont.fontTMPro != null)
                {
                    iconStyle.font = AssetDatabase.LoadAssetAtPath <Font>(AssetDatabase.GUIDToAssetPath(vectorFont.fontTMPro.creationSettings.sourceFontFileGUID));
                }
                s_iconStyles[visualReference] = iconStyle;
            }
            iconStyle.fontSize = iconStyle.font != null && iconStyle.font.dynamic ? vectorIconSize : 0;

            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.PrefixLabel(label);
                if (EditorGUI.indentLevel > 0)
                {
                    //  2 is a good 'base' offset when there are indents
                    EditorGUILayout.LabelField("", GUILayout.MaxWidth(-(2 + vectorImageDataIndentOffsetSize * EditorGUI.indentLevel)));
                }

                if (!string.IsNullOrEmpty(name))
                {
                    GUIContent iconGUIContent = new GUIContent(IconDecoder.Decode(code), name);

                    if (iconStyle.font != null && !iconStyle.font.dynamic)
                    {
                        CharacterInfo charInfo;
                        iconStyle.font.GetCharacterInfo(iconGUIContent.text[0], out charInfo);
                        var uvRect = Rect.MinMaxRect(charInfo.uvBottomLeft.x, charInfo.uvBottomLeft.y, charInfo.uvTopRight.x, charInfo.uvTopRight.y);

                        EditorGUILayout.LabelField("", GUILayout.Width(vectorIconSize), GUILayout.Height(vectorIconSize));
                        GUI.DrawTextureWithTexCoords(GUILayoutUtility.GetLastRect(), iconStyle.font.material.mainTexture, uvRect);
                    }
                    else
                    {
                        EditorGUILayout.LabelField(iconGUIContent, iconStyle, GUILayout.MaxWidth(iconStyle.CalcSize(iconGUIContent).x));
                    }

                    if (EditorGUI.indentLevel > 0)
                    {
                        EditorGUILayout.LabelField("", GUILayout.MaxWidth(vectorImageDataIndentOffsetSize * EditorGUI.indentLevel));
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("No icon selected", GUILayout.MaxWidth(vectorImageDataMaxLabelWidth));
                    GUILayout.FlexibleSpace();
                }

                if (GUILayout.Button("Pick Icon", EditorStyles.miniButton, GUILayout.MinHeight(miniButtonHeight)))
                {
                    VectorImagePickerWindow.Show(targetDatas, objectsToUndo, onIconPickAction);
                }
                if (visualReference != null && visualReference.ContainsData() &&
                    GUILayout.Button(IconDecoder.Decode(@"\ue14c"),
                                     new GUIStyle {
                    fontSize = iconStyle.fontSize, font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName)
                },
                                     GUILayout.MaxWidth(20)))
                {
                    if (objectsToUndo != null)
                    {
                        Undo.RecordObjects(objectsToUndo, "Set Icon");
                    }

                    foreach (var imageData in targetDatas)
                    {
                        imageData.glyph      = null;
                        imageData.vectorFont = null;
                    }
                }
            }

            return(true);
        }