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 itemSprite = itemData.FindPropertyRelative("m_ImageData.m_Sprite"); 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 = new GUIStyle { font = (Font)itemData.FindPropertyRelative("m_ImageData.m_VectorImageData.m_Font").objectReferenceValue }; SerializedProperty itemImageType = itemData.FindPropertyRelative("m_ImageData.m_ImageDataType"); RectOffset offset = new RectOffset(0, 0, -1, -3); rect = offset.Add(rect); rect.height = EditorGUIUtility.singleLineHeight; float offsetH = 0; EditorGUI.LabelField(new Rect(rect.x, 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) { EditorGUI.PropertyField(new Rect(rect.x + offsetH, rect.y, rect.width - offsetH, rect.height), itemSprite, GUIContent.none); } else { if (!string.IsNullOrEmpty(itemName.stringValue)) { EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 16, rect.height), IconDecoder.Decode(itemCode.stringValue), 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); } if (GUI.Button(new Rect(rect.width + 16, rect.y, 18, rect.height), IconDecoder.Decode(@"\ue14c"), new GUIStyle { font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName) })) { IOptionDataListContainer optionDataListContainer = itemData.serializedObject.targetObject as IOptionDataListContainer; VectorImageData data = optionDataListContainer.optionDataList.options[index].imageData.vectorImageData; data.font = null; data.glyph = null; EditorUtility.SetDirty(itemData.serializedObject.targetObject); } } }
private void DrawIconList() { if (m_GlyphArray.Length == 0) { GUIStyle guiStyle = new GUIStyle(); guiStyle.fontStyle = FontStyle.Bold; guiStyle.alignment = TextAnchor.MiddleCenter; EditorGUILayout.LabelField("No icon found for your search term: " + m_SearchText, guiStyle, GUILayout.Height(Screen.height - 80f)); return; } float padded = m_PreviewSize + 5f; int columns = Mathf.FloorToInt((Screen.width - 25f) / padded); if (columns < 1) columns = 1; int offset = 0; Rect rect = new Rect(0f, 0, m_PreviewSize, m_PreviewSize); GUILayout.Space(5f); using (GUILayout.ScrollViewScope scrollViewScope = new GUILayout.ScrollViewScope(m_IconViewScrollPosition, GUILayout.Height(Screen.height - 80f))) { m_IconViewScrollPosition = scrollViewScope.scrollPosition; while (offset < m_GlyphArray.Length) { using (new GUILayout.HorizontalScope()) { int col = 0; rect.x = 0f; for (; offset < m_GlyphArray.Length; ++offset) { // Change color of the selected VectorImage if (m_VectorImageDatas[0].glyph.name == m_GlyphArray[offset].name) { GUI.backgroundColor = MaterialColor.iconDark; } if (GUI.Button(rect, new GUIContent("", m_GlyphArray[offset].name))) { if (Event.current.button == 0) { SetGlyph(offset); if (Time.realtimeSinceStartup - m_LastClickTime < 0.3f) { Close(); } m_LastClickTime = Time.realtimeSinceStartup; } } if (Event.current.type == EventType.Repaint) { drawTiledTexture(rect); m_GuiStyle.fontSize = m_PreviewSize; string iconText = IconDecoder.Decode(@"\u" + m_GlyphArray[offset].unicode); Vector2 size = m_GuiStyle.CalcSize(new GUIContent(iconText)); float maxSide = size.x > size.y ? size.x : size.y; float scaleFactor = (m_PreviewSize / maxSide) * 0.9f; m_GuiStyle.fontSize = Mathf.RoundToInt(m_PreviewSize * scaleFactor); size *= scaleFactor; Vector2 padding = new Vector2(rect.width - size.x, rect.height - size.y); Rect iconRect = new Rect(rect.x + (padding.x / 2f), rect.y + (padding.y / 2f), rect.width - padding.x, rect.height - padding.y); GUI.Label(iconRect, new GUIContent(iconText), m_GuiStyle); } GUI.backgroundColor = Color.white; if (++col >= columns) { ++offset; break; } rect.x += padded; } } GUILayout.Space(padded); rect.y += padded; } } }