private void OnGUI() { DrawSizeAnalysis(); _serializedObject.Update(); // Iterate through serialized properties and draw them like the Inspector (But with ports) SerializedProperty componentProperty = _serializedObject.FindProperty(nameof(_componentDefinition)); // Directory EditorGUILayout.BeginHorizontal(); var directoryProperty = componentProperty.FindPropertyRelative("Directory"); GUIDrawers.DrawFieldWithLabel(directoryProperty); if (GUILayout.Button("\u27b1", GUILayout.Width(30))) { var dialogPath = EditorUtility.OpenFolderPanel("Code directory", "", ""); if (!string.IsNullOrWhiteSpace(dialogPath)) { directoryProperty.stringValue = PathExtension.AssetsPath(dialogPath); } } EditorGUILayout.EndHorizontal(); // Namespace var namespaceProperty = componentProperty.FindPropertyRelative("Namespace"); using (new GUIEnabledScope(false)) { if (!namespaceProperty.stringValue.EndsWith(".Components", StringComparison.InvariantCultureIgnoreCase)) { EditorGUILayout.TextArea("Remember, if namespace do not ends with \".Components\" system will automatically add it", EditorStyles.helpBox); } } EditorGUILayout.BeginHorizontal(); GUIDrawers.DrawFieldWithLabel(namespaceProperty); var selectedNamespace = DrawNamespacesPopup(namespaceProperty.stringValue); if (!string.IsNullOrWhiteSpace(selectedNamespace)) { namespaceProperty.stringValue = selectedNamespace; } EditorGUILayout.EndHorizontal(); // Type & Name EditorGUILayout.BeginHorizontal(); GUIDrawers.DrawFieldWithLabel(componentProperty.FindPropertyRelative("ComponentType")); GUIDrawers.DrawFieldWithLabel(componentProperty.FindPropertyRelative("ComponentName")); EditorGUILayout.EndHorizontal(); // Fields GUIDrawers.DrawArray <object>(componentProperty.FindPropertyRelative("Fields")); _serializedObject.ApplyModifiedProperties(); DrawActionButtons(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); var wasChanged = GUI.changed; GUI.changed = false; PropertyRect propertyRect = new PropertyRect(position); // Draw name var nameProp = property.FindPropertyRelative("_name"); EditorGUI.PropertyField(propertyRect.AllocateLine(), nameProp); // Draw array var componentsProp = property.FindPropertyRelative("_components"); s_cache.Clear(); GUIDrawers.DrawArray(ref propertyRect, componentsProp, s_cache); // Draw additional settings propertyRect.AllocateLine(); var parallelScheduling = property.FindPropertyRelative("_parallelSchedule"); EditorGUI.LabelField(propertyRect.AllocateWidthFlat(105), s_parallelContent); EditorGUI.PropertyField(propertyRect.AllocateWidthFlat(25), parallelScheduling, EmptyContent); var structuralChanges = property.FindPropertyRelative("_hasStructuralChanges"); EditorGUI.LabelField(propertyRect.AllocateWidthFlat(115), s_structuralChangesContent); EditorGUI.PropertyField(propertyRect.AllocateWidthFlat(25), structuralChanges, EmptyContent); propertyRect.AllocateLine(); var queryField = property.FindPropertyRelative("_queryField"); EditorGUI.LabelField(propertyRect.AllocateWidthFlat(75), s_queryFieldContent); EditorGUI.PropertyField(propertyRect.AllocateRestOfLine(), queryField, EmptyContent); propertyRect.AllocateLine(); var sharedFilter = property.FindPropertyRelative("_sharedFilter").GetPropertyValue <SharedComponentFilter>(); EditorGUI.LabelField(propertyRect.AllocateWidthFlat(75), s_sharedFilterContent); if (sharedFilter.IsValid) { EditorGUI.LabelField(propertyRect.AllocateWidthWithAscesorFlat(25), sharedFilter.FilterName, s_BoldLabelStyle); } else { EditorGUI.LabelField(propertyRect.AllocateWidthWithAscesorFlat(25), EmptyContent); } if (!sharedFilter.IsValid && GUI.Button(propertyRect.AllocateRestOfLine(), PlusContent)) { SharedComponentFilterWindow.ShowWindow((name, declaration) => { property.serializedObject.ApplyModifiedProperties(); sharedFilter.FilterName = name; sharedFilter.ComponentDeclaration = declaration; property.serializedObject.Update(); }); } else if (sharedFilter.IsValid && GUI.Button(propertyRect.AllocateRestOfLine(), MinusContent)) { sharedFilter.Invalid(); } EditorGUI.EndProperty(); if (GUI.changed) { // We can have some structural changes so we need to sync with Unity serialized side property.serializedObject.ApplyModifiedProperties(); SystemLambdaAction systemLambdaAction = property.GetPropertyValue() as SystemLambdaAction; systemLambdaAction?.PropertiesChanged(s_cache); property.serializedObject.Update(); } GUI.changed |= wasChanged; }