ControlPoint.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace UnityEditor.Experimental.Rendering.Universal.Path2D
  6. {
  7. internal enum TangentMode
  8. {
  9. Linear = 0,
  10. Continuous = 1,
  11. Broken = 2
  12. }
  13. [Serializable]
  14. internal struct TangentCache
  15. {
  16. public Vector3 leftTangent;
  17. public Vector3 rightTangent;
  18. }
  19. [Serializable]
  20. internal struct ControlPoint
  21. {
  22. public Vector3 position;
  23. public Vector3 localLeftTangent;
  24. public Vector3 localRightTangent;
  25. public TangentMode tangentMode;
  26. public TangentCache continuousCache;
  27. public TangentCache brokenCache;
  28. public bool mirrorLeft;
  29. public Vector3 leftTangent
  30. {
  31. get { return localLeftTangent + position; }
  32. set { localLeftTangent = value - position; }
  33. }
  34. public Vector3 rightTangent
  35. {
  36. get { return localRightTangent + position; }
  37. set { localRightTangent = value - position; }
  38. }
  39. public void StoreTangents()
  40. {
  41. if (tangentMode == TangentMode.Continuous)
  42. {
  43. continuousCache.leftTangent = localLeftTangent;
  44. continuousCache.rightTangent = localRightTangent;
  45. }
  46. else if (tangentMode == TangentMode.Broken)
  47. {
  48. brokenCache.leftTangent = localLeftTangent;
  49. brokenCache.rightTangent = localRightTangent;
  50. }
  51. }
  52. public void RestoreTangents()
  53. {
  54. if (tangentMode == TangentMode.Continuous)
  55. {
  56. localLeftTangent = continuousCache.leftTangent;
  57. localRightTangent = continuousCache.rightTangent;
  58. }
  59. else if (tangentMode == TangentMode.Broken)
  60. {
  61. localLeftTangent = brokenCache.leftTangent;
  62. localRightTangent = brokenCache.rightTangent;
  63. }
  64. }
  65. }
  66. }