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