GraphObjectInspector.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using DunGen.Graph;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace DunGen.Editor.Inspectors
  6. {
  7. [CustomEditor(typeof(GraphObjectObserver))]
  8. public sealed class GraphObjectInspector : UnityEditor.Editor
  9. {
  10. public override void OnInspectorGUI()
  11. {
  12. var data = target as GraphObjectObserver;
  13. if (data == null)
  14. return;
  15. serializedObject.Update();
  16. if (data.Node != null && data.Node.TileSets != null)
  17. DrawNodeGUI(data.Node);
  18. else if (data.Line != null)
  19. DrawLineGUI(data.Line);
  20. if (GUI.changed)
  21. EditorUtility.SetDirty(data.Flow);
  22. serializedObject.ApplyModifiedProperties();
  23. }
  24. private void DrawNodeGUI(GraphNode node)
  25. {
  26. var data = target as GraphObjectObserver;
  27. node.Graph = data.Flow;
  28. var nodeProp = serializedObject.FindProperty("node");
  29. if (string.IsNullOrEmpty(node.Label))
  30. EditorGUILayout.LabelField("Node", EditorStyles.boldLabel);
  31. else
  32. EditorGUILayout.LabelField("Node: " + node.Label, EditorStyles.boldLabel);
  33. if (node.NodeType == NodeType.Normal)
  34. node.Label = EditorGUILayout.TextField("Label", node.Label);
  35. EditorUtil.DrawObjectList<TileSet>("Tile Sets", node.TileSets, GameObjectSelectionTypes.Prefab, target);
  36. EditorGUILayout.Space();
  37. // Straightening Section
  38. EditorGUILayout.BeginVertical("box");
  39. {
  40. var straightenSettingsProp = nodeProp.FindPropertyRelative(nameof(GraphNode.StraighteningSettings));
  41. EditorGUILayout.LabelField(new GUIContent("Path Straightening"), EditorStyles.boldLabel);
  42. EditorUtil.DrawStraightenSettingsWithOverrides(straightenSettingsProp, false);
  43. }
  44. EditorGUILayout.EndVertical();
  45. if (data.Flow.KeyManager == null)
  46. return;
  47. EditorGUILayout.Space();
  48. DrawKeys(node.Graph.KeyManager, node.Keys, node.Locks, true);
  49. node.LockPlacement = (NodeLockPlacement)EditorGUILayout.EnumFlagsField("Lock Placement", node.LockPlacement);
  50. }
  51. private void DrawLineGUI(GraphLine line)
  52. {
  53. var data = target as GraphObjectObserver;
  54. line.Graph = data.Flow;
  55. EditorGUILayout.LabelField("Line Segment", EditorStyles.boldLabel);
  56. EditorUtil.DrawObjectList<DungeonArchetype>("Dungeon Archetypes", line.DungeonArchetypes, GameObjectSelectionTypes.Prefab, target);
  57. EditorGUILayout.Space();
  58. DrawKeys(line.Graph.KeyManager, line.Keys, line.Locks, false);
  59. }
  60. private void DrawKeys(KeyManager manager, List<KeyLockPlacement> keyIDs, List<KeyLockPlacement> lockIDs, bool isNode)
  61. {
  62. if (manager == null)
  63. return;
  64. if (manager == null)
  65. EditorGUILayout.HelpBox("Key Manager not set in Dungeon Flow", MessageType.Info);
  66. else if (manager.Keys.Count == 0)
  67. EditorGUILayout.HelpBox("Key Manager has no keys", MessageType.Info);
  68. else
  69. {
  70. EditorUtil.DrawKeySelection("Keys", manager, keyIDs, false);
  71. EditorUtil.DrawKeySelection("Locks", manager, lockIDs, !isNode);
  72. }
  73. }
  74. }
  75. }