No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GenericScriptablePath.cs 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace UnityEditor.U2D.Common.Path
  5. {
  6. internal class GenericScriptablePath<T> : ScriptablePath
  7. {
  8. [SerializeField]
  9. private List<T> m_Data = new List<T>();
  10. public T[] data
  11. {
  12. get { return m_Data.ToArray(); }
  13. set
  14. {
  15. if (value.Length != pointCount)
  16. throw new Exception("Custom data count does not match control point count");
  17. m_Data.Clear();
  18. m_Data.AddRange(value);
  19. }
  20. }
  21. public override void Clear()
  22. {
  23. base.Clear();
  24. m_Data.Clear();
  25. }
  26. public override void AddPoint(ControlPoint controlPoint)
  27. {
  28. base.AddPoint(controlPoint);
  29. m_Data.Add(Create());
  30. }
  31. public override void InsertPoint(int index, ControlPoint controlPoint)
  32. {
  33. base.InsertPoint(index, controlPoint);
  34. m_Data.Insert(index, Create());
  35. }
  36. public override void RemovePoint(int index)
  37. {
  38. base.RemovePoint(index);
  39. Destroy(m_Data[index]);
  40. m_Data.RemoveAt(index);
  41. }
  42. public T GetData(int index)
  43. {
  44. return m_Data[index];
  45. }
  46. public void SetData(int index, T data)
  47. {
  48. m_Data[index] = data;
  49. }
  50. protected virtual T Create()
  51. {
  52. return Activator.CreateInstance<T>();
  53. }
  54. protected virtual void Destroy(T data) { }
  55. }
  56. }