A game about forced loneliness, made by TACStudios
1using System;
2using System.Linq;
3using System.Collections.Generic;
4using UnityEngine;
5using UnityEditor;
6using UnityEditor.EditorTools;
7using UnityEditor.U2D.Common.Path.GUIFramework;
8using UnityObject = UnityEngine.Object;
9
10namespace UnityEditor.U2D.Common.Path
11{
12 internal static class PathEditorToolExtensions
13 {
14 public static void CycleTangentMode<T>(this PathEditorTool<T> pathEditorTool) where T : ScriptablePath
15 {
16 var first = true;
17 var mixed = false;
18 var tangentMode = TangentMode.Linear;
19 var targets = pathEditorTool.targets;
20
21 foreach(var target in targets)
22 {
23 var path = pathEditorTool.GetPath(target);
24
25 if (path.selection.Count == 0)
26 continue;
27
28 for (var i = 0; i < path.pointCount; ++i)
29 {
30 if (!path.selection.Contains(i))
31 continue;
32
33 var point = path.GetPoint(i);
34
35 if (first)
36 {
37 first = false;
38 tangentMode = point.tangentMode;
39 }
40 else if (point.tangentMode != tangentMode)
41 {
42 mixed = true;
43 break;
44 }
45 }
46
47 if (mixed)
48 break;
49 }
50
51 if (mixed)
52 tangentMode = TangentMode.Linear;
53 else
54 tangentMode = GetNextTangentMode(tangentMode);
55
56 foreach(var target in targets)
57 {
58 var path = pathEditorTool.GetPath(target);
59
60 if (path.selection.Count == 0)
61 continue;
62
63 path.undoObject.RegisterUndo("Cycle Tangent Mode");
64
65 for (var i = 0; i < path.pointCount; ++i)
66 {
67 if (!path.selection.Contains(i))
68 continue;
69
70 path.SetTangentMode(i, tangentMode);
71 }
72
73 pathEditorTool.SetPath(target);
74 }
75 }
76
77 public static void MirrorTangent<T>(this PathEditorTool<T> pathEditorTool) where T : ScriptablePath
78 {
79 var targets = pathEditorTool.targets;
80
81 foreach(var target in targets)
82 {
83 var path = pathEditorTool.GetPath(target);
84
85 if (path.selection.Count == 0)
86 continue;
87
88 path.undoObject.RegisterUndo("Mirror Tangents");
89
90 for (var i = 0; i < path.pointCount; ++i)
91 {
92 if (!path.selection.Contains(i))
93 continue;
94
95 path.MirrorTangent(i);
96 }
97
98 pathEditorTool.SetPath(target);
99 }
100 }
101
102 private static TangentMode GetNextTangentMode(TangentMode tangentMode)
103 {
104 return (TangentMode)((((int)tangentMode) + 1) % Enum.GetValues(typeof(TangentMode)).Length);
105 }
106 }
107
108}