Node.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System;
  6. namespace StateChartEditor
  7. {
  8. public class Node
  9. {
  10. String name;
  11. List<Edge> out_edges = new List<Edge>();
  12. List<Edge> in_edges = new List<Edge>();
  13. public Rect rect { get; private set; }
  14. public bool selected { get; private set; }
  15. public Node(Vector2 position, String name)
  16. {
  17. this.selected = false;
  18. var rect = new Rect(0,0,100,100);
  19. rect.center = position;
  20. this.rect = rect;
  21. this.name = name;
  22. }
  23. public Vector2 getPos()
  24. {
  25. return this.rect.center;
  26. }
  27. public void draw()
  28. {
  29. if(this.selected)
  30. {
  31. var old_color = GUI.backgroundColor;
  32. GUI.backgroundColor = Color.Lerp(GUI.backgroundColor,Color.green,0.5f);
  33. GUI.Box(this.rect, name);
  34. GUI.backgroundColor = old_color;
  35. }
  36. else
  37. {
  38. GUI.Box(this.rect, name);
  39. }
  40. /*
  41. IOPositions = new Vector2[] { new Vector2(rect.center.x ,rect.y ),
  42. new Vector2(rect.x + rect.width ,rect.center.y ),
  43. new Vector2(rect.center.x ,rect.y + rect.height ),
  44. new Vector2(rect.x ,rect.center.y )};
  45. */
  46. }
  47. public void setSelected()
  48. {
  49. this.selected = true;
  50. }
  51. public bool checkMouseOver(Vector2 mousePosition)
  52. {
  53. if(rect.Contains(mousePosition)){
  54. return true;
  55. }
  56. return false;
  57. }
  58. public void move(Vector2 offset)
  59. {
  60. this.rect = new Rect(this.rect.x + offset [0], this.rect.y + offset [1], this.rect.width, this.rect.height);
  61. }
  62. public void unSelect()
  63. {
  64. this.selected = false;
  65. }
  66. public void addInput(Edge edge)
  67. {
  68. in_edges.Add (edge);
  69. }
  70. public void addOutput(Edge edge)
  71. {
  72. out_edges.Add (edge);
  73. }
  74. }
  75. }