-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.cs
122 lines (103 loc) · 4.54 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
using HarmonyLib;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityModManagerNet;
namespace fro_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 bool AlmostEquals(this float double1, float double2, float precision)
{
return (Mathf.Abs(double1 - double2) <= precision);
}
public static bool IsGrabbing()
{
return PlayerController.Instance.currentStateEnum == PlayerController.CurrentState.Grabs || EventManager.Instance.IsGrabbing;
}
public static void Log(object arg)
{
UnityModManager.Logger.Log(arg.ToString());
}
public static bool isOllie()
{
if (PlayerController.Instance.boardController.firstVel <= -1.7f || PlayerController.Instance.boardController.firstVel >= 1.7f) return false;
if (PlayerController.Instance.boardController.thirdVel <= -1f || PlayerController.Instance.boardController.thirdVel >= 1f) return false;
if (Main.controller.target_left <= .01f && Main.controller.target_right <= .01f) return true;
else return false;
}
public static bool isOneFootOllie()
{
bool flip = PlayerController.Instance.boardController.thirdVel <= -1f || PlayerController.Instance.boardController.thirdVel >= 1f;
bool oneFootOff = (Main.controller.target_left <= .01f && Main.controller.target_right >= .99f) || (Main.controller.target_left >= .99f && Main.controller.target_right <= .01f);
return !flip && oneFootOff;
}
public static Vector3 getDeltas()
{
float first = PlayerController.Instance.boardController.firstVel;
float second = PlayerController.Instance.boardController.secondVel;
float third = PlayerController.Instance.boardController.thirdVel;
return new Vector3(first, second, third);
}
public static bool CanConfig()
{
return !Main.controller.IsGrabbing() && (PlayerController.Instance.currentStateEnum == PlayerController.CurrentState.Pushing || PlayerController.Instance.currentStateEnum == PlayerController.CurrentState.Riding || PlayerController.Instance.currentStateEnum == PlayerController.CurrentState.Impact);
}
}
}