public override void OnInspectorGUI() { GUILayout.Space(8); serializedObject.Update(); // Style Asset. var spStyleAsset = serializedObject.FindProperty("m_StyleAsset"); StyleAssetEditor.DrawStyleAssetField(spStyleAsset, style => { spStyleAsset.objectReferenceValue = style; spStyleAsset.serializedObject.ApplyModifiedProperties(); EditorApplication.delayCall += () => StyleAssetEditor.UpdateChangeListeners(style as StyleAsset); }); // Style Properties. if (!spStyleAsset.hasMultipleDifferentValues) { EditorGUI.BeginChangeCheck(); // Draw Toolbar. using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) { using (var cc = new EditorGUI.DisabledGroupScope(!current.styleAsset)) { // Save style property from target. if (GUILayout.Button(new GUIContent("Save"), EditorStyles.toolbarButton)) { foreach (var property in current.styleAsset.properties) { property.parameterList.FitSize(1); PropertyEditor.FillArgumentsByGetter(current, property.methodInfo, property.parameterList); } PropertyEditor.onPropertyChanged(); } // Load style property to target. if (GUILayout.Button(new GUIContent("Load"), EditorStyles.toolbarButton)) { current.LoadStyle(); } } GUILayout.FlexibleSpace(); // Default Toolbar. StyleAssetEditor.DrawStyleToolbar(current, current.styleAsset); } // Draw style detail. if (StyleAssetEditor.isShowProperties && current.styleAsset) { StyleAssetEditor.DrawProperties(current.styleAsset); } // When style has changed, apply the style to gameObject. if (EditorGUI.EndChangeCheck() && current.styleAsset) { Debug.Log("hogehoge"); EditorUtility.SetDirty(current.styleAsset); PropertyEditor.onPropertyChanged(); } } // Not support multiple StyleAssets. else { EditorGUILayout.HelpBox("Multi-StyleAssets editing is not supported.", MessageType.None); } // Ignore Properties. GUILayout.Space(6); EditorGUILayout.LabelField("Ignore Properties", EditorStyles.boldLabel); roIgnoreProperties.serializedProperty = serializedObject.FindProperty("m_IgnoreProperties"); roIgnoreProperties.DoLayoutList(); serializedObject.ApplyModifiedProperties(); }
/* * public static void DrawStyle(Style style, StyleAsset styleAsset) * { * // Toolbar. * EditorGUI.BeginChangeCheck(); * DrawStyleToolbar(style, styleAsset); * * // Draw style detail. * if (isShowProperties && styleAsset) * { * DrawProperties(styleAsset); * } * * // When style has changed, apply the style to gameObject. * if (EditorGUI.EndChangeCheck() && styleAsset) * { * EditorUtility.SetDirty(styleAsset); * PropertyEditor.onPropertyChanged(); * } * }*/ /// <summary> /// Draws the style full. /// </summary> /// <returns>The style full.</returns> /// <param name="styleSheetAsset">Style sheet asset.</param> public static StyleAsset DrawProperties(StyleAsset styleAsset) { if (!styleAsset) { return(styleAsset); } StyleAsset ret = styleAsset; // Draw all sheet. int depth = 0; foreach (var validStyleAsset in styleAsset.GetStyleAssetEnumerator()) { EditorGUI.BeginDisabledGroup(0 < depth); GUILayout.Space(-5); EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.ExpandWidth(true)); IEnumerable <Property> properties = validStyleAsset.properties; HashSet <string> ids = new HashSet <string>(properties.Select(x => x.methodId)); // Included all RectTransform common properties in style. if (s_RectTransformCommonProperties.All(ids.Contains)) { EditorGUILayout.LabelField("RectTransform Common Properties", EditorStyles.boldLabel); PropertyEditor.abbreviation = true; EditorGUI.indentLevel++; // Draw RectTransform common properties. foreach (var property in properties.Where(x => s_RectTransformCommonProperties.Contains(x.methodId))) { if (property.parameterList != null) { property.parameterList.FitSize(1); } PropertyEditor.DrawPropertyField(property, 0, true); } EditorGUI.indentLevel--; PropertyEditor.abbreviation = false; properties = properties.Where(x => !s_RectTransformCommonProperties.Contains(x.methodId)); GUILayout.Space(8); } // Draw all properties. foreach (var property in properties) { if (property.parameterList != null) { property.parameterList.FitSize(1); } PropertyEditor.DrawPropertyField(property, 0, true); } // If current sheet is main, draw base style sheet. using (new EditorGUI.DisabledGroupScope(validStyleAsset != styleAsset)) { var so = new SerializedObject(validStyleAsset); var spStyleAsset = so.FindProperty("m_BaseStyleAsset"); if (validStyleAsset == styleAsset || spStyleAsset.objectReferenceValue) { so.Update(); GUILayout.Space(22); DrawStyleAssetField(spStyleAsset, style => { spStyleAsset.objectReferenceValue = style; spStyleAsset.serializedObject.ApplyModifiedProperties(); }); } } EditorGUI.EndDisabledGroup(); depth++; } while (0 < depth--) { EditorGUILayout.EndVertical(); } return(ret); }