Ejemplo n.º 1
0
        private void UpdateFontPackInfo()
        {
            string name = m_VectorImageDatas[0].vectorFont.FontName;

            m_IconFont = VectorImageManager.GetIconFont(name);
            m_GuiStyle = new GUIStyle {
                font = m_IconFont
            };
            if (m_GuiStyle.font == null)
            {
                m_GuiStyle.font = GetSourceFont(m_VectorImageDatas[0].vectorFont.fontTMPro);
            }
            m_GuiStyle.normal.textColor = Color.white;
            CreateGlyphInvertedTexture(m_GuiStyle);

            UpdateGlyphList();

            // Assign the very first icon of the imageSet if the glyph is null
            Glyph glyph = m_IconFont != null?m_IconFont.GetGlyphByName(m_VectorImageDatas[0].glyph.name) : null;

            if (glyph == null)
            {
                SetGlyph(0);
            }
            Repaint();
        }
 static MaterialUIIconHelper()
 {
     if (m_Font == null)
     {
         m_Font = VectorImageManager.GetIconFont(VectorImageManager.materialUIIconsFontName);
     }
 }
Ejemplo n.º 3
0
        public VectorImageData(Glyph glyph, VectorImageFont vectorFont)
        {
            m_Glyph = glyph;
            if (!m_Glyph.unicode.StartsWith(@"\u"))
            {
                m_Glyph.unicode = @"\u" + m_Glyph.unicode;
            }

            m_Font = vectorFont;
        }
        static MaterialIconHelper()
        {
            if (m_Font == null)
            {
                m_Font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName);
            }

            if (m_IconSet == null)
            {
                m_IconSet = VectorImageManager.GetIconSet(VectorImageManager.materialDesignIconsFontName);
            }
        }
Ejemplo n.º 5
0
        private void DrawOptionData(Rect rect, int index, bool isActive, bool isFocused)
        {
            SerializedProperty itemData      = m_ReorderableList.serializedProperty.GetArrayElementAtIndex(index);
            SerializedProperty itemText      = itemData.FindPropertyRelative("m_Text");
            SerializedProperty onSelectEvent = itemData.FindPropertyRelative("onOptionSelected");

            SerializedProperty itemSprite = itemData.FindPropertyRelative("m_ImageData.m_Sprite");
            SerializedProperty imgUrl     = itemData.FindPropertyRelative("m_ImageData.m_ImgUrl");

            SerializedProperty itemCode  = itemData.FindPropertyRelative("m_ImageData.m_VectorImageData.m_Glyph.m_Unicode");
            SerializedProperty itemName  = itemData.FindPropertyRelative("m_ImageData.m_VectorImageData.m_Glyph.m_Name");
            GUIStyle           iconStyle = null;

            if (iconStyle == null)
            {
                object          v_asset    = itemData.FindPropertyRelative("m_ImageData.m_VectorImageData.m_Font").objectReferenceValue;
                VectorImageFont vectorFont = v_asset as VectorImageFont;
                iconStyle = new GUIStyle {
                    font = vectorFont != null ? vectorFont.font : v_asset as Font
                };
                if (iconStyle.font == null && vectorFont != null && vectorFont.fontTMPro != null)
                {
                    iconStyle.font = AssetDatabase.LoadAssetAtPath <Font>(AssetDatabase.GUIDToAssetPath(vectorFont.fontTMPro.creationSettings.sourceFontFileGUID));
                }
            }

            SerializedProperty itemImageType = itemData.FindPropertyRelative("m_ImageData.m_ImageDataType");

            RectOffset offset = new RectOffset(-5, 0, -1, -3);

            rect        = offset.Add(rect);
            rect.height = EditorGUIUtility.singleLineHeight;

            float offsetH = 2;

            EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 16, rect.height), index.ToString());
            offsetH += 16;

            EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 35, rect.height), "Text", EditorStyles.boldLabel);
            offsetH += 35;

            EditorGUI.PropertyField(new Rect(rect.x + offsetH, rect.y, (rect.width / 3) - offsetH, rect.height), itemText, GUIContent.none);
            offsetH += (rect.width / 3) - offsetH + 8;

            EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 32, rect.height), "Icon", EditorStyles.boldLabel);
            offsetH += 32;

            itemImageType.enumValueIndex = m_ImageType.enumValueIndex;


            if (m_ImageType.enumValueIndex == 0)
            {
                var itemSpriteRect = new Rect(rect.x + offsetH, rect.y, rect.width - offsetH, rect.height);
                EditorGUI.PropertyField(itemSpriteRect, itemSprite, GUIContent.none);
            }
            else
            {
                if (!string.IsNullOrEmpty(itemName.stringValue))
                {
                    var iconText = IconDecoder.Decode(itemCode.stringValue);
                    //EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 16, rect.height), IconDecoder.Decode(itemCode.stringValue), iconStyle);
                    if (iconStyle.font != null && !iconStyle.font.dynamic)
                    {
                        CharacterInfo charInfo;
                        iconStyle.font.GetCharacterInfo(iconText[0], out charInfo);
                        var uvRect = Rect.MinMaxRect(charInfo.uvBottomLeft.x, charInfo.uvBottomLeft.y, charInfo.uvTopRight.x, charInfo.uvTopRight.y);

                        GUI.DrawTextureWithTexCoords(new Rect(rect.x + offsetH, rect.y, 16, rect.height), iconStyle.font.material.mainTexture, uvRect);
                    }
                    else
                    {
                        iconStyle.fontSize = (int)rect.height;
                        EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 16, rect.height), iconText, iconStyle);
                    }

                    offsetH += 16;
                    EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, rect.width - offsetH - 80, rect.height), itemName.stringValue);
                }
                else
                {
                    EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, rect.width - offsetH - 80, rect.height), "No icon selected");
                }

                if (GUI.Button(new Rect(rect.width - 60, rect.y, 70, rect.height), "Pick Icon"))
                {
                    IOptionDataListContainer optionDataListContainer = itemData.serializedObject.targetObject as IOptionDataListContainer;
                    VectorImagePickerWindow.Show(optionDataListContainer.optionDataList.options[index].imageData.vectorImageData, itemData.serializedObject.targetObject);
                }

                var fontStyle = new GUIStyle {
                    font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName)
                };
                if (fontStyle.font != null && fontStyle.font.dynamic)
                {
                    fontStyle.fontSize = (int)rect.height;
                }
                if (GUI.Button(new Rect(rect.width + 16, rect.y, 18, rect.height), IconDecoder.Decode(@"\ue14c"), fontStyle))
                {
                    IOptionDataListContainer optionDataListContainer = itemData.serializedObject.targetObject as IOptionDataListContainer;
                    if (optionDataListContainer != null && optionDataListContainer.optionDataList.options[index].imageData != null)
                    {
                        VectorImageData data = optionDataListContainer.optionDataList.options[index].imageData.vectorImageData;
                        if (data != null)
                        {
                            data.vectorFont = null;
                            data.glyph      = null;
                        }
                    }
                    EditorUtility.SetDirty(itemData.serializedObject.targetObject);
                }
            }

            EditorGUI.PropertyField(rect, itemData, new GUIContent(string.Empty), false);
            //itemData.isExpanded = EditorGUI.Foldout(rect, itemData.isExpanded, string.Empty);
            if (itemData.isExpanded)
            {
                var drawUrl = m_ImageType.enumValueIndex == 0;
                rect.y += EditorGUIUtility.singleLineHeight + 3;
                if (drawUrl)
                {
                    var itemSpriteRect = new Rect(rect.x + offsetH, rect.y, rect.width - offsetH, rect.height);

                    EditorGUI.LabelField(new Rect(itemSpriteRect.x - 32, rect.y, 32, rect.height), "Url", EditorStyles.boldLabel);
                    EditorGUI.PropertyField(itemSpriteRect, imgUrl, GUIContent.none);

                    rect.y += EditorGUIUtility.singleLineHeight + 7;
                }
                EditorGUI.PropertyField(rect, onSelectEvent);
            }
        }