SplineNode.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.Events;
  6. namespace SplineMesh {
  7. /// <summary>
  8. /// Spline node storing a position and a direction (tangent).
  9. /// Note : you shouldn't modify position and direction manualy but use dedicated methods instead, to insure event raising.
  10. /// </summary>
  11. [Serializable]
  12. public class SplineNode {
  13. /// <summary>
  14. /// Node position
  15. /// </summary>
  16. public Vector3 Position {
  17. get { return position; }
  18. set {
  19. if (position.Equals(value)) return;
  20. position.x = value.x;
  21. position.y = value.y;
  22. position.z = value.z;
  23. if(Changed != null) Changed(this, EventArgs.Empty);
  24. }
  25. }
  26. [SerializeField]
  27. private Vector3 position;
  28. /// <summary>
  29. /// Node direction
  30. /// </summary>
  31. public Vector3 Direction {
  32. get { return direction; }
  33. set {
  34. if (direction.Equals(value)) return;
  35. direction.x = value.x;
  36. direction.y = value.y;
  37. direction.z = value.z;
  38. if (Changed != null) Changed(this, EventArgs.Empty);
  39. }
  40. }
  41. [SerializeField]
  42. private Vector3 direction;
  43. /// <summary>
  44. /// Up vector to apply at this node.
  45. /// Usefull to specify the orientation when the tangent blend with the world UP (gimball lock)
  46. /// This value is not used on the spline itself but is commonly used on bended content.
  47. /// </summary>
  48. public Vector3 Up {
  49. get { return up; }
  50. set {
  51. if (up.Equals(value)) return;
  52. up.x = value.x;
  53. up.y = value.y;
  54. up.z = value.z;
  55. if (Changed != null) Changed(this, EventArgs.Empty);
  56. }
  57. }
  58. [SerializeField]
  59. private Vector3 up = Vector3.up;
  60. /// <summary>
  61. /// Scale to apply at this node.
  62. /// This value is not used on the spline itself but is commonly used on bended content.
  63. /// </summary>
  64. public Vector2 Scale {
  65. get { return scale; }
  66. set {
  67. if (scale.Equals(value)) return;
  68. scale.x = value.x;
  69. scale.y = value.y;
  70. if (Changed != null) Changed(this, EventArgs.Empty);
  71. }
  72. }
  73. [SerializeField]
  74. private Vector2 scale = Vector2.one;
  75. /// <summary>
  76. /// Roll to apply at this node.
  77. /// This value is not used on the spline itself but is commonly used on bended content.
  78. /// </summary>
  79. public float Roll {
  80. get { return roll; }
  81. set {
  82. if (roll == value) return;
  83. roll = value;
  84. if (Changed != null) Changed(this, EventArgs.Empty);
  85. }
  86. }
  87. [SerializeField]
  88. private float roll;
  89. public SplineNode(Vector3 position, Vector3 direction) {
  90. Position = position;
  91. Direction = direction;
  92. }
  93. /// <summary>
  94. /// Event raised when position, direction, scale or roll changes.
  95. /// </summary>
  96. [HideInInspector]
  97. public event EventHandler Changed;
  98. }
  99. }