StickyNoteView.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #if UNITY_2020_1_OR_NEWER
  2. using UnityEngine;
  3. using UnityEditor.Experimental.GraphView;
  4. using UnityEditor.UIElements;
  5. using UnityEngine.UIElements;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. namespace GraphProcessor
  10. {
  11. public class StickyNoteView : UnityEditor.Experimental.GraphView.StickyNote
  12. {
  13. public BaseGraphView owner;
  14. public StickyNote note;
  15. Label titleLabel;
  16. ColorField colorField;
  17. public StickyNoteView()
  18. {
  19. fontSize = StickyNoteFontSize.Small;
  20. theme = StickyNoteTheme.Classic;
  21. }
  22. public void Initialize(BaseGraphView graphView, StickyNote note)
  23. {
  24. this.note = note;
  25. owner = graphView;
  26. this.Q<TextField>("title-field").RegisterCallback<ChangeEvent<string>>(e => {
  27. note.title = e.newValue;
  28. });
  29. this.Q<TextField>("contents-field").RegisterCallback<ChangeEvent<string>>(e => {
  30. note.content = e.newValue;
  31. });
  32. title = note.title;
  33. contents = note.content;
  34. SetPosition(note.position);
  35. }
  36. public override void SetPosition(Rect newPos)
  37. {
  38. base.SetPosition(newPos);
  39. if (note != null)
  40. note.position = newPos;
  41. }
  42. public override void OnResized()
  43. {
  44. note.position = layout;
  45. }
  46. }
  47. }
  48. #endif