Skip to content

Commit cf97e8a

Browse files
1.8.0
1 parent eb94b34 commit cf97e8a

24 files changed

+611
-418
lines changed

Classes/ButtonCollider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace StupidTemplate.Classes
77
{
8-
internal class Button : MonoBehaviour
8+
public class Button : MonoBehaviour
99
{
1010
public string relatedText;
1111

@@ -17,7 +17,7 @@ public void OnTriggerEnter(Collider collider)
1717
{
1818
buttonCooldown = Time.time + 0.2f;
1919
GorillaTagger.Instance.StartVibration(rightHanded, GorillaTagger.Instance.tagHapticStrength / 2f, GorillaTagger.Instance.tagHapticDuration / 2f);
20-
GorillaTagger.Instance.offlineVRRig.PlayHandTapLocal(8, rightHanded, 0.4f);
20+
VRRig.LocalRig.PlayHandTapLocal(8, rightHanded, 0.4f);
2121
Toggle(this.relatedText);
2222
}
2323
}

Classes/ColorChanger.cs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
1-
using UnityEngine;
1+
using StupidTemplate.Menu;
2+
using UnityEngine;
23

34
namespace StupidTemplate.Classes
45
{
5-
public class ColorChanger : TimedBehaviour
6+
public class ColorChanger : MonoBehaviour
67
{
7-
public override void Start()
8+
public void Start()
89
{
9-
base.Start();
10-
renderer = base.GetComponent<Renderer>();
10+
if (colors == null)
11+
{
12+
Destroy(this);
13+
return;
14+
}
15+
16+
targetRenderer = GetComponent<Renderer>();
17+
18+
if (colors.IsFlat())
19+
{
20+
Update();
21+
Destroy(this);
22+
return;
23+
}
24+
1125
Update();
1226
}
1327

14-
public override void Update()
28+
public void Update()
1529
{
16-
base.Update();
17-
if (colorInfo != null)
18-
{
19-
if (!colorInfo.copyRigColors)
20-
{
21-
Color color = new Gradient { colorKeys = colorInfo.colors }.Evaluate((Time.time / 2f) % 1);
22-
if (colorInfo.isRainbow)
23-
{
24-
float h = (Time.frameCount / 180f) % 1f;
25-
color = UnityEngine.Color.HSVToRGB(h, 1f, 1f);
26-
}
27-
renderer.material.color = color;
28-
}
29-
else
30-
{
31-
renderer.material = GorillaTagger.Instance.offlineVRRig.mainSkin.material;
32-
}
33-
}
30+
targetRenderer.enabled = !colors.transparent;
31+
32+
if (colors.transparent)
33+
return;
34+
35+
targetRenderer.material.color = colors.GetCurrentColor();
3436
}
3537

36-
public Renderer renderer;
37-
public ExtGradient colorInfo;
38+
public Renderer targetRenderer;
39+
public ExtGradient colors;
3840
}
3941
}

Classes/ExtGradient.cs

Lines changed: 130 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,140 @@
1-
using System;
1+
using StupidTemplate.Menu;
2+
using System;
3+
using System.Linq;
24
using UnityEngine;
35

46
namespace StupidTemplate.Classes
57
{
68
public class ExtGradient
79
{
8-
public GradientColorKey[] colors = new GradientColorKey[]
10+
public static GradientColorKey[] GetSolidGradient(Color color) =>
11+
new GradientColorKey[] { new GradientColorKey(color, 0f), new GradientColorKey(color, 1f) };
12+
13+
public static GradientColorKey[] GetSimpleGradient(Color a, Color b) =>
14+
new GradientColorKey[] { new GradientColorKey(a, 0f), new GradientColorKey(b, 0.5f), new GradientColorKey(a, 1f) };
15+
16+
public GradientColorKey[] colors = GetSolidGradient(Color.magenta);
17+
18+
public Color GetColor(int index)
919
{
10-
new GradientColorKey(Color.black, 0f),
11-
new GradientColorKey(Color.magenta, 0.5f),
12-
new GradientColorKey(Color.black, 1f)
13-
};
20+
if (rainbow)
21+
return Color.HSVToRGB((Time.time + (index / 8)) % 1f, 1f, 1f);
22+
23+
if (pastelRainbow)
24+
return Color.HSVToRGB((Time.time + (index / 8)), 0.3f, 1f);
25+
26+
if (epileptic)
27+
return Main.RandomColor();
28+
29+
if (copyRigColor)
30+
return RigManager.GetPlayerColor(VRRig.LocalRig);
31+
32+
if (transparent)
33+
{
34+
Color targetColor = colors[index].color;
35+
targetColor.a = 0f;
36+
37+
return targetColor;
38+
}
39+
40+
if (customColor != null)
41+
return customColor?.Invoke() ?? Color.magenta;
42+
43+
return colors[index].color;
44+
}
45+
46+
public void SetColor(int index, Color color, bool setMirror = true)
47+
{
48+
rainbow = false;
49+
pastelRainbow = false;
50+
51+
epileptic = false;
52+
copyRigColor = false;
53+
54+
customColor = null;
55+
56+
if (colors.Length <= 2)
57+
colors = GetSimpleGradient(colors[0].color, colors[^1].color);
58+
59+
if (setMirror && index == 0)
60+
{
61+
colors[0].color = color;
62+
colors[^1].color = color;
63+
}
64+
else
65+
colors[index].color = color;
66+
}
67+
68+
public void SetColors(Color color)
69+
{
70+
rainbow = false;
71+
pastelRainbow = false;
72+
73+
epileptic = false;
74+
copyRigColor = false;
75+
76+
customColor = null;
77+
78+
for (int i = 0; i < colors.Length; i++)
79+
colors[i].color = color;
80+
}
81+
82+
public Color GetColorTime(float time)
83+
{
84+
if (rainbow)
85+
return Color.HSVToRGB(time, 1f, 1f);
86+
87+
if (pastelRainbow)
88+
return Color.HSVToRGB(time, 0.3f, 1f);
89+
90+
if (epileptic)
91+
return Main.RandomColor();
92+
93+
if (copyRigColor)
94+
return RigManager.GetPlayerColor(VRRig.LocalRig);
95+
96+
if (transparent)
97+
{
98+
Color targetColor = new Gradient { colorKeys = colors }.Evaluate(time);
99+
targetColor.a = 0f;
100+
101+
return targetColor;
102+
}
103+
104+
if (customColor != null)
105+
return customColor?.Invoke() ?? Color.magenta;
106+
107+
return new Gradient { colorKeys = colors }.Evaluate(time);
108+
}
109+
110+
public Color GetCurrentColor(float offset = 0f) =>
111+
GetColorTime((offset + (Time.time * Settings.gradientSpeed)) % 1f);
112+
113+
public bool IsFlat() =>
114+
!rainbow && !pastelRainbow && !epileptic && !copyRigColor &&
115+
colors.Length > 0 && colors.All(key => key.color == colors[0].color);
116+
117+
public ExtGradient Clone()
118+
{
119+
return new ExtGradient
120+
{
121+
rainbow = rainbow,
122+
pastelRainbow = pastelRainbow,
123+
epileptic = epileptic,
124+
copyRigColor = copyRigColor,
125+
customColor = customColor,
126+
colors = colors.Select(c => new GradientColorKey(c.color, c.time)).ToArray()
127+
};
128+
}
129+
130+
public bool rainbow;
131+
public bool pastelRainbow;
132+
133+
public bool epileptic;
134+
public bool copyRigColor;
135+
136+
public bool transparent;
14137

15-
public bool isRainbow = false;
16-
public bool copyRigColors = false;
138+
public Func<Color> customColor;
17139
}
18140
}

Classes/RigManager.cs

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,22 @@
66

77
namespace StupidTemplate.Classes
88
{
9-
internal class RigManager : BaseUnityPlugin
9+
public class RigManager
1010
{
11-
public static VRRig GetVRRigFromPlayer(Player p)
12-
{
13-
return GorillaGameManager.instance.FindPlayerVRRig(p);
14-
}
11+
public static VRRig GetVRRigFromPlayer(Player p) =>
12+
GorillaGameManager.instance.FindPlayerVRRig(p);
1513

1614
public static VRRig GetRandomVRRig(bool includeSelf)
1715
{
18-
VRRig random = GorillaParent.instance.vrrigs[UnityEngine.Random.Range(0, GorillaParent.instance.vrrigs.Count - 1)];
16+
VRRig random = GorillaParent.instance.vrrigs[Random.Range(0, GorillaParent.instance.vrrigs.Count - 1)];
1917
if (includeSelf)
20-
{
2118
return random;
22-
}
2319
else
2420
{
25-
if (random != GorillaTagger.Instance.offlineVRRig)
26-
{
21+
if (random != VRRig.LocalRig)
2722
return random;
28-
}
2923
else
30-
{
3124
return GetRandomVRRig(includeSelf);
32-
}
3325
}
3426
}
3527

@@ -48,31 +40,24 @@ public static VRRig GetClosestVRRig()
4840
return outRig;
4941
}
5042

51-
public static PhotonView GetPhotonViewFromVRRig(VRRig p)
52-
{
53-
return (PhotonView)Traverse.Create(p).Field("photonView").GetValue();
54-
}
43+
public static PhotonView GetPhotonViewFromVRRig(VRRig p) =>
44+
(PhotonView)Traverse.Create(p).Field("photonView").GetValue();
5545

56-
public static Photon.Realtime.Player GetRandomPlayer(bool includeSelf)
46+
public static Player GetRandomPlayer(bool includeSelf)
5747
{
5848
if (includeSelf)
59-
{
60-
return PhotonNetwork.PlayerList[UnityEngine.Random.Range(0, PhotonNetwork.PlayerList.Length - 1)];
61-
} else
62-
{
63-
return PhotonNetwork.PlayerListOthers[UnityEngine.Random.Range(0, PhotonNetwork.PlayerListOthers.Length - 1)];
64-
}
49+
return PhotonNetwork.PlayerList[Random.Range(0, PhotonNetwork.PlayerList.Length - 1)];
50+
else
51+
return PhotonNetwork.PlayerListOthers[Random.Range(0, PhotonNetwork.PlayerListOthers.Length - 1)];
6552
}
6653

67-
public static Photon.Realtime.Player GetPlayerFromVRRig(VRRig p)
68-
{
69-
return GetPhotonViewFromVRRig(p).Owner;
70-
}
54+
public static Player GetPlayerFromVRRig(VRRig p) =>
55+
GetPhotonViewFromVRRig(p).Owner;
7156

72-
public static Photon.Realtime.Player GetPlayerFromID(string id)
57+
public static Player GetPlayerFromID(string id)
7358
{
74-
Photon.Realtime.Player found = null;
75-
foreach (Photon.Realtime.Player target in PhotonNetwork.PlayerList)
59+
Player found = null;
60+
foreach (Player target in PhotonNetwork.PlayerList)
7661
{
7762
if (target.UserId == id)
7863
{
@@ -82,5 +67,27 @@ public static Photon.Realtime.Player GetPlayerFromID(string id)
8267
}
8368
return found;
8469
}
70+
71+
public static Color GetPlayerColor(VRRig Player)
72+
{
73+
if (Player.bodyRenderer.cosmeticBodyType == GorillaBodyType.Skeleton)
74+
return Color.green;
75+
76+
switch (Player.setMatIndex)
77+
{
78+
case 1:
79+
return Color.red;
80+
case 2:
81+
case 11:
82+
return new Color32(255, 128, 0, 255);
83+
case 3:
84+
case 7:
85+
return Color.blue;
86+
case 12:
87+
return Color.green;
88+
default:
89+
return Player.playerColor;
90+
}
91+
}
8592
}
8693
}

Classes/TimedBehaviour.cs

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)