public override void OnInspectorGUI() { serializedObject.Update(); // Draw inspector for each filter for (int i = 0; i < Filters.arraySize; i++) { SerializedProperty currentf = Filters.GetArrayElementAtIndex(i); GUILayout.BeginHorizontal(); currentf.isExpanded = EditorGUILayout.Foldout(currentf.isExpanded, new GUIContent(ObjectNames.NicifyVariableName(currentf.objectReferenceValue.GetType().Name))); GUILayout.FlexibleSpace(); if (GUILayout.Button("Remove", EditorStyles.miniButton)) { DestroyImmediate(currentf.objectReferenceValue, true); AssetDatabase.SaveAssets(); Filters.DeleteArrayElementAtIndex(i); Filters.DeleteArrayElementAtIndex(i); serializedObject.ApplyModifiedProperties(); continue; } GUILayout.EndHorizontal(); if (currentf.isExpanded) { Editor m_editor = CreateEditor(currentf.objectReferenceValue); GUILayout.Space(5); m_editor.OnInspectorGUI(); } MoonGUILayout.Separator(); } GUILayout.Space(5); // add buttun filter if (GUILayout.Button("Add Filter", GUILayout.Height(20))) { GenericMenu Menu = new GenericMenu(); // Gets all aviable filters via reflection List <System.Type> m_types = MoonReflection.GetAllDerivedTypes(typeof(SensorFilter)).ToList(); for (int i = 0; i < m_types.Count; i++) { System.Type currt = m_types[i]; if (currt != null) { Menu.AddItem(new GUIContent(currt.Name), false, new GenericMenu.MenuFunction(() => { int index = Filters.arraySize; SensorFilter filter = CreateInstance(currt) as SensorFilter; filter.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector; AssetDatabase.AddObjectToAsset(filter, target); AssetDatabase.SaveAssets(); Filters.InsertArrayElementAtIndex(index); SerializedProperty curr = Filters.GetArrayElementAtIndex(index); curr.objectReferenceValue = filter; serializedObject.ApplyModifiedProperties(); })); } } Menu.ShowAsContext(); } serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(tooltipPosition); EditorGUILayout.PropertyField(Tooltip); if (GUI.changed) { serializedObject.ApplyModifiedProperties(); } MoonGUILayout.Separator(); if (TaskInfo != null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(TaskInfo.Name, new GUIStyle(EditorStyles.label) { fontStyle = FontStyle.Bold }); GUILayout.FlexibleSpace(); if (Nodedoc != null) { if (GUILayout.Button(new GUIContent("?", "Open documentation"), EditorStyles.miniButton)) { Application.OpenURL(Nodedoc.URL); } } EditorGUILayout.EndHorizontal(); if (!string.IsNullOrEmpty(TaskInfo.Description)) { EditorGUILayout.HelpBox(TaskInfo.Description, MessageType.Info); } } if (TaskInspector != null) { if (!EditorApplication.isPlaying) { // Draw task inspector TaskInspector.OnInspectorGUI(); } else if (n != null) { GUILayout.BeginVertical("Debug mode", GUI.skin.box, GUILayout.ExpandWidth(true)); GUILayout.Space(15); if (!n.Task) { return; } FieldInfo[] fields = n.Task.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); PropertyInfo[] props = n.Task.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); for (int i = 0; i < fields.Length; i++) { FieldInfo currentField = fields[i]; if (!ValidName(currentField.Name)) { continue; } object[] atrs = currentField.GetCustomAttributes(typeof(HideOnDebugAttribute), true); if (atrs != null && atrs.Length > 0) { continue; } object currentValue = currentField.GetValue(n.Task); if (currentValue != null) { GUILayout.Label(ObjectNames.NicifyVariableName(currentField.Name) + ": " + currentValue.ToString()); } else { GUILayout.Label(ObjectNames.NicifyVariableName(currentField.Name) + ": null"); } } for (int i = 0; i < props.Length; i++) { PropertyInfo currentProp = props[i]; object currentValue = currentProp.GetValue(n.Task, null); if (!ValidName(currentProp.Name)) { continue; } object[] atrs = currentProp.GetCustomAttributes(typeof(HideOnDebugAttribute), true); if (atrs != null && atrs.Length > 0) { continue; } if (currentValue != null) { GUILayout.Label(ObjectNames.NicifyVariableName(currentProp.Name) + ": " + currentValue.ToString()); } else { GUILayout.Label(ObjectNames.NicifyVariableName(currentProp.Name) + ": null"); } } GUILayout.EndVertical(); Repaint(); } } }