public override void OnInspectorGUI() { serializedObject.Update(); HedgehogEditorGUIUtility.DrawProperties(serializedObject, "PaletteMaterial", "IgnoreTransparent"); Instance.SetColorFrom = EditorGUILayout.Toggle("Set Color From", Instance.SetColorFrom); if (Instance.SetColorFrom) { HedgehogEditorGUIUtility.DrawProperties(serializedObject, "ColorFromIndex"); } ShowPalettes = EditorGUILayout.Foldout(ShowPalettes, "Palettes"); if (ShowPalettes) { Palettes.DoLayoutList(); if (!Application.isPlaying && Palettes.HasKeyboardControl()) { Instance.SetPalette(Palettes.index); } } serializedObject.ApplyModifiedProperties(); }
public static void DoFoldoutsLayout(Dictionary <string, List <SerializedProperty> > data) { var first = data.Values.FirstOrDefault(); if (first == null || first.Count == 0) { return; } var serializedObject = first.First().serializedObject; serializedObject.Update(); var objectName = serializedObject.targetObject.GetType().Name; foreach (var foldoutName in data.Keys) { var entryName = objectName + ".Show" + foldoutName; var state = EditorPrefs.GetBool(entryName, false); state = EditorGUILayout.Foldout(state, foldoutName); if (state) { HedgehogEditorGUIUtility.DrawProperties(data[foldoutName].ToArray()); } EditorPrefs.SetBool(entryName, state); } serializedObject.ApplyModifiedProperties(); }
public static Dictionary <string, List <SerializedProperty> > GatherProperties( SerializedObject serializedObject, string defaultFoldoutName = "Misc") { var results = new Dictionary <string, List <SerializedProperty> >(); var it = serializedObject.GetIterator(); it.Next(true); while (it.NextVisible(false)) { if (it.name == HedgehogEditorGUIUtility.ScriptPropertyName) { continue; } var attr = HedgehogEditorGUIUtility.GetAttribute <FoldoutAttribute>(it); var type = attr == null ? defaultFoldoutName : attr.Name; (results.ContainsKey(type) ? results[type] : (results[type] = new List <SerializedProperty>())) .Add(it.Copy()); } foreach (var field in serializedObject.targetObject.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.Instance)) { var property = serializedObject.FindProperty(field.Name); if (property == null) { continue; } if (HedgehogEditorGUIUtility.GetAttribute <HideInInspector>(field) != null) { continue; } foreach (var propertyLists in results.Values) { if (propertyLists.Contains(property)) { continue; } } var attr = HedgehogEditorGUIUtility.GetAttribute <FoldoutAttribute>(field); var type = attr == null ? defaultFoldoutName : attr.Name; (results.ContainsKey(type) ? results[type] : (results[type] = new List <SerializedProperty>())) .Add(property); } return(results); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var tooltip = HedgehogEditorGUIUtility.GetAttribute <TooltipAttribute>(property); if (tooltip != null) { property.stringValue = EditorGUI.TagField(position, new GUIContent(ObjectNames.NicifyVariableName(property.name), tooltip.tooltip), property.stringValue); } else { property.stringValue = EditorGUI.TagField(position, ObjectNames.NicifyVariableName(property.name), property.stringValue); } }
public static void DoFoldoutsLayout(SerializedObject serializedObject, string noFoldoutName = "Misc") { serializedObject.Update(); var data = GatherProperties(serializedObject, noFoldoutName); List <SerializedProperty> noFoldout; if (data.TryGetValue(noFoldoutName, out noFoldout)) { data.Remove(noFoldoutName); HedgehogEditorGUIUtility.DrawProperties(noFoldout.ToArray()); serializedObject.ApplyModifiedProperties(); } DoFoldoutsLayout(data); }
private bool IsFirst(SerializedProperty property, string foldoutName) { var it = property.serializedObject.GetIterator(); it.Next(true); while (it.NextVisible(true)) { if (it.name == property.name) { break; } var attr = HedgehogEditorGUIUtility.GetAttribute <FoldoutAttribute>(it); if (attr != null && attr.Name == foldoutName) { return(false); } } return(true); }