Skip to content

Commit

Permalink
adding immediate-mode GUI property drawer for system graph fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tbg10101 committed Jul 31, 2023
1 parent c632d76 commit 041b6f5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
26 changes: 19 additions & 7 deletions Editor/Scripts/Drawers/GraphSystemGroupDataDrawer.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
using Software10101.DOTS.Editor.GraphEditor;
using Software10101.DOTS.MonoBehaviours;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace Software10101.DOTS.Editor.Drawers {
[CustomPropertyDrawer(typeof(WorldBehaviour.GraphSystemGroupData))]
public class GraphSystemGroupDataDrawer : PropertyDrawer {
public override VisualElement CreatePropertyGUI(SerializedProperty property) {
// Create property container element.
VisualElement container = new();

// Create property fields.
Button editButton = new(() => {
GraphSystemGroupEditorWindow window = EditorWindow.GetWindow<GraphSystemGroupEditorWindow>();

WorldBehaviour wb = (WorldBehaviour)property.serializedObject.targetObject;
window.Initialize(wb, property.name);
OpenGraph(property);
}) {
text = $"Edit {property.displayName}"
};

// Add fields to the container.
container.Add(editButton);

return container;
}

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
EditorGUI.BeginProperty(position, label, property);

if (GUILayout.Button($"Edit {property.displayName}")) {
OpenGraph(property);
}

EditorGUI.EndProperty();
}

private static void OpenGraph(SerializedProperty property) {
GraphSystemGroupEditorWindow window = EditorWindow.GetWindow<GraphSystemGroupEditorWindow>();

WorldBehaviour wb = (WorldBehaviour)property.serializedObject.targetObject;
window.Initialize(wb, property.name);
}
}
}
2 changes: 1 addition & 1 deletion Runtime/Scripts/MonoBehaviours/WorldBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed class WorldBehaviour : MonoBehaviour {
public EntityManager EntityManager => _world.EntityManager;

[SerializeField]
private WorldFlags _flags = WorldFlags.Live | WorldFlags.Game;
private WorldFlags _flags = WorldFlags.Game;

[SerializeField]
private GraphSystemGroupData _simResetGroup = GraphSystemGroupData.CreateEmpty();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.10101software.dots.hybridsimulation",
"displayName": "DOTS Hybrid Simulation Worlds",
"description": "A framework for using FixedUpdate in a simulation world which is linked to a GameObject-based presentation layer.",
"version": "1.0.0",
"version": "1.0.1",
"unity": "2022.3",
"dependencies": {
"com.unity.entities": "1.0.11"
Expand Down

0 comments on commit 041b6f5

Please sign in to comment.