PivotPointCollection.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace O3DWB
  6. {
  7. [Serializable]
  8. public class PivotPointCollection
  9. {
  10. #region Protected Variables
  11. [SerializeField]
  12. private int _indexOfActivePoint = 0;
  13. [SerializeField]
  14. private List<Vector3> _pivotPoints = new List<Vector3> { Vector3.zero };
  15. #endregion
  16. #region Public Properties
  17. public int IndexOfActivePoint { get { return _indexOfActivePoint; } }
  18. public Vector3 ActivePoint { get { return _pivotPoints[_indexOfActivePoint]; } }
  19. public List<Vector3> AllPoints { get { return new List<Vector3>(_pivotPoints); } }
  20. public int NumberOfPoints { get { return _pivotPoints.Count; } }
  21. #endregion
  22. #region Public Methods
  23. public PivotPointCollection TakeSnapshot()
  24. {
  25. var pivotPointCollection = new PivotPointCollection();
  26. pivotPointCollection._indexOfActivePoint = IndexOfActivePoint;
  27. pivotPointCollection._pivotPoints = new List<Vector3>(AllPoints);
  28. return pivotPointCollection;
  29. }
  30. public Vector3 GetPointByIndex(int pointIndex)
  31. {
  32. return _pivotPoints[pointIndex];
  33. }
  34. public void SetPivotPoints(List<Vector3> pivotPoints, int indexOfSelectedPoint)
  35. {
  36. if (pivotPoints.Count != 0)
  37. {
  38. _pivotPoints = new List<Vector3>(pivotPoints);
  39. _indexOfActivePoint = Mathf.Clamp(indexOfSelectedPoint, 0, _pivotPoints.Count);
  40. }
  41. }
  42. public void ActivatePoint(int pointIndex)
  43. {
  44. _indexOfActivePoint = pointIndex;
  45. }
  46. public void ActivateNextPoint()
  47. {
  48. ++_indexOfActivePoint;
  49. _indexOfActivePoint %= _pivotPoints.Count;
  50. }
  51. public void MovePoints(Vector3 moveVector)
  52. {
  53. _pivotPoints = Vector3Extensions.ApplyOffsetToPoints(_pivotPoints, moveVector);
  54. }
  55. #endregion
  56. }
  57. }
  58. #endif