-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
126 lines (113 loc) · 3.97 KB
/
Utils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityModManagerNet;
namespace walking_mod
{
public static class Utils
{
public static float map01(float value, float min, float max)
{
return (value - min) * 1f / (max - min);
}
public static float map(float value, float leftMin, float leftMax, float rightMin, float rightMax)
{
return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin);
}
public static Quaternion GetLocalRotationRelativeToRootParent(Transform transform)
{
if (transform.parent == null)
{
return transform.localRotation;
}
else
{
Quaternion rootParentRotation = Quaternion.identity;
Transform currentParent = transform.parent;
while (currentParent.parent != null)
{
rootParentRotation = currentParent.rotation * rootParentRotation;
currentParent = currentParent.parent;
}
return Quaternion.Inverse(rootParentRotation) * transform.rotation;
}
}
public static float WrapAngle(float angle)
{
angle %= 360;
if (angle > 180)
return angle - 360;
return angle;
}
public static float UnwrapAngle(float angle)
{
if (angle >= 0)
return angle;
angle = -angle % 360;
return 360 - angle;
}
public static Vector3 TranslateWithRotation(Vector3 input, Vector3 translation, Quaternion rotation)
{
Vector3 rotatedTranslation = rotation * translation;
Vector3 output = input + rotatedTranslation;
return output;
}
public static Quaternion SmoothDampQuaternion(Quaternion current, Quaternion target, ref Vector3 currentVelocity, float smoothTime)
{
Vector3 c = current.eulerAngles;
Vector3 t = target.eulerAngles;
return Quaternion.Euler(
Mathf.SmoothDampAngle(c.x, t.x, ref currentVelocity.x, smoothTime),
Mathf.SmoothDampAngle(c.y, t.y, ref currentVelocity.y, smoothTime),
Mathf.SmoothDampAngle(c.z, t.z, ref currentVelocity.z, smoothTime)
);
}
public static Quaternion EnsureQuaternionContinuity(Quaternion last, Quaternion curr)
{
if (last.x * curr.x + last.y * curr.y + last.z * curr.z + last.w * curr.w < 0f)
{
return new Quaternion(-curr.x, -curr.y, -curr.z, -curr.w);
}
return curr;
}
public static string[] hands_parts = new string[] {
"Skater_index_01_l",
"Skater_index_02_l",
"Skater_index_03_l",
"Skater_middle_01_l",
"Skater_middle_02_l",
"Skater_middle_03_l",
"Skater_pinky_01_l",
"Skater_pinky_02_l",
"Skater_pinky_03_l",
"Skater_ring_01_l",
"Skater_ring_02_l",
"Skater_ring_03_l",
"Skater_thumb_01_l",
"Skater_thumb_02_l",
"Skater_thumb_03_l",
"Skater_index_01_r",
"Skater_index_02_r",
"Skater_index_03_r",
"Skater_middle_01_r",
"Skater_middle_02_r",
"Skater_middle_03_r",
"Skater_pinky_01_r",
"Skater_pinky_02_r",
"Skater_pinky_03_r",
"Skater_ring_01_r",
"Skater_ring_02_r",
"Skater_ring_03_r",
"Skater_thumb_01_r",
"Skater_thumb_02_r",
"Skater_thumb_03_r"
};
public static void Log(object log)
{
UnityModManager.Logger.Log("[walking-mod] " + log.ToString());
}
}
}