GraphObjectObserver.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using DunGen.Graph;
  2. using System;
  3. using UnityEngine;
  4. namespace DunGen.Editor
  5. {
  6. /**
  7. * For simplicity, I wanted to use Unity's inspector to edit the graph objects but didn't want to
  8. * save each object as a separate asset (as you would have to when deriving them from ScriptableObject.
  9. *
  10. * So, as a hacky solution, I create a GraphObjectObserver to act as a proxy for editing the nodes in
  11. * the inspector. It's not a pretty solution but it works.
  12. */
  13. [Serializable]
  14. public class GraphObjectObserver : ScriptableObject
  15. {
  16. public DungeonFlow Flow { get; set; }
  17. public GraphNode Node
  18. {
  19. get => node;
  20. private set => node = value;
  21. }
  22. public GraphLine Line
  23. {
  24. get => line;
  25. private set => line = value;
  26. }
  27. [SerializeField]
  28. private GraphNode node;
  29. [SerializeField]
  30. private GraphLine line;
  31. public void Inspect(GraphNode node)
  32. {
  33. Node = node;
  34. Line = null;
  35. }
  36. public void Inspect(GraphLine line)
  37. {
  38. Line = line;
  39. Node = null;
  40. }
  41. }
  42. }