A game about forced loneliness, made by TACStudios
at master 4.1 kB view raw
1using System; 2using System.Collections.Generic; 3using UnityEngine; 4 5namespace UnityEditor.U2D.Common.Path 6{ 7 internal class MultipleEditablePathController : IEditablePathController 8 { 9 private IEditablePathController m_Controller = new EditablePathController(); 10 private List<IEditablePath> m_Paths = new List<IEditablePath>(); 11 private float m_ClosestDistance = float.MaxValue; 12 private IEditablePath m_ClosestPath; 13 14 public IEditablePath editablePath 15 { 16 get { return m_Controller.editablePath; } 17 set { m_Controller.editablePath = value; } 18 } 19 20 public IEditablePath closestEditablePath { get; private set; } 21 22 public ISnapping<Vector3> snapping 23 { 24 get { return m_Controller.snapping; } 25 set { m_Controller.snapping = value; } 26 } 27 28 public bool enableSnapping 29 { 30 get { return EditorSnapSettings.gridSnapEnabled; } 31 } 32 33 public void ClearPaths() 34 { 35 m_Paths.Clear(); 36 } 37 38 public void AddPath(IEditablePath path) 39 { 40 if (!m_Paths.Contains(path)) 41 m_Paths.Add(path); 42 } 43 44 public void RemovePath(IEditablePath path) 45 { 46 m_Paths.Remove(path); 47 } 48 49 public void RegisterUndo(string name) 50 { 51 var current = editablePath; 52 53 ForEach((s) => 54 { 55 editablePath = s; 56 m_Controller.RegisterUndo(name); 57 }); 58 59 editablePath = current; 60 } 61 62 public void ClearSelection() 63 { 64 var current = editablePath; 65 66 ForEach((s) => 67 { 68 editablePath = s; 69 m_Controller.ClearSelection(); 70 }); 71 72 editablePath = current; 73 } 74 75 public void SelectPoint(int index, bool select) 76 { 77 m_Controller.SelectPoint(index, select); 78 } 79 80 public void CreatePoint(int index, Vector3 position) 81 { 82 m_Controller.CreatePoint(index, position); 83 } 84 85 public void RemoveSelectedPoints() 86 { 87 var current = editablePath; 88 89 ForEach((s) => 90 { 91 editablePath = s; 92 m_Controller.RemoveSelectedPoints(); 93 }); 94 95 editablePath = current; 96 } 97 98 public void MoveSelectedPoints(Vector3 delta) 99 { 100 var current = editablePath; 101 102 ForEach((s) => 103 { 104 editablePath = s; 105 m_Controller.MoveSelectedPoints(delta); 106 }); 107 108 editablePath = current; 109 } 110 111 public void MoveEdge(int index, Vector3 delta) 112 { 113 m_Controller.MoveEdge(index, delta); 114 } 115 116 public void SetLeftTangent(int index, Vector3 position, bool setToLinear, bool mirror, Vector3 cachedRightTangent, TangentMode cachedTangentMode) 117 { 118 m_Controller.SetLeftTangent(index, position, setToLinear, mirror, cachedRightTangent, cachedTangentMode); 119 } 120 121 public void SetRightTangent(int index, Vector3 position, bool setToLinear, bool mirror, Vector3 cachedLeftTangent, TangentMode cachedTangentMode) 122 { 123 m_Controller.SetRightTangent(index, position, setToLinear, mirror, cachedLeftTangent, cachedTangentMode); 124 } 125 126 public void ClearClosestPath() 127 { 128 m_ClosestDistance = float.MaxValue; 129 closestEditablePath = null; 130 } 131 132 public void AddClosestPath(float distance) 133 { 134 if (distance <= m_ClosestDistance) 135 { 136 m_ClosestDistance = distance; 137 closestEditablePath = editablePath; 138 } 139 } 140 141 private void ForEach(Action<IEditablePath> action) 142 { 143 foreach(var path in m_Paths) 144 { 145 if (path == null) 146 continue; 147 148 action(path); 149 } 150 } 151 } 152}