-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorShift.cs
More file actions
138 lines (125 loc) · 4.19 KB
/
Copy pathColorShift.cs
File metadata and controls
138 lines (125 loc) · 4.19 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
using UdonSharp;
using UnityEngine;
using VRC.SDK3.Components;
using VRC.SDKBase;
using VRC.Udon;
namespace UdonVR
{
/// <summary>
///
/// </summary>
public class ColorShift : UdonSharpBehaviour
{
[Tooltip("The object to apply ColorShift to.")]
public Renderer TargetObj;
[Tooltip("Target colors to use for cycling.")]
public Color32[] Colors = { Color.red, Color.magenta, Color.blue, Color.cyan, Color.green, new Color(1,1,0,1)};
[Tooltip("Typically you want this set to '_Color' or '_EmissionColor'")]
public string TargetProperty = "_Color";
[Tooltip("Ammount of time in secconds it takes to transistion to the next color.")]
public float TargetTime = 3;
[Tooltip("Makes it so the colors randomly cycle.")]
public bool isRandom;
public bool isShared;
private Material _mat;
private int _CurrentColor = 0;
private int _TargetColor = 1;
private int _OldColor = -1;
private int _NextColor = -1;
private float _R;
private float _G;
private float _B;
private float _A;
private float _r;
private float _g;
private float _b;
private float _a;
private float _tr;
private float _tg;
private float _tb;
private float _ta;
private float _Lerp;
private Color _tempColor;
public void ToggleRandom()
{
isRandom = !isRandom;
}
public void Start()
{
if (TargetObj == null)
{
TargetObj = gameObject.GetComponent<Renderer>();
}
if (isShared)
{
_mat = TargetObj.sharedMaterial;
} else
{
_mat = TargetObj.material;
}
_r = Colors[_CurrentColor].r;
_g = Colors[_CurrentColor].g;
_b = Colors[_CurrentColor].b;
_a = Colors[_CurrentColor].a;
}
public void Update()
{
if (_tr == _R && _tg == _G && _tb == _B && _ta == _A)
{
NextColor();
} else
{
Debug.LogWarning((Time.deltaTime / TargetTime).ToString());
_Lerp = _Lerp + (Time.deltaTime / TargetTime);
_tr = Mathf.Lerp(_r, _R, _Lerp);
_tg =Mathf.Lerp(_g, _G, _Lerp);
_tb =Mathf.Lerp(_b, _B, _Lerp);
_ta =Mathf.Lerp(_a, _A, _Lerp);
}
_tr = Mathf.RoundToInt(_tr);
_tg = Mathf.RoundToInt(_tg);
_tb = Mathf.RoundToInt(_tb);
_ta = Mathf.RoundToInt(_ta);
Debug.Log("Lerp: " + _Lerp + " R: " + _tr + " G: " + _tg + " B: " + _tb + " A: " + _ta);
_tempColor = new Color32((byte) (_tr),(byte) (_tg),(byte) (_tb),(byte) (_ta));
_mat.SetColor(TargetProperty, _tempColor);
}
public void NextColor()
{
_OldColor = _TargetColor;
_Lerp = 0;
if (isRandom)
{
_PickRandom();
} else
{
_NextColor = _TargetColor + 1;
if (_NextColor >= Colors.Length) _NextColor = 0;
}
_TargetColor = _NextColor;
InitColor();
}
private void _PickRandom()
{
_NextColor = Random.Range(0, Colors.Length);
if (_NextColor == _OldColor)
{
Debug.Log("Random Pick Failed, Picking new color.");
_PickRandom();
}
return;
}
private void InitColor()
{
Debug.Log("Setting Target Color to: " + _TargetColor);
_r = Colors[_OldColor].r;
_g = Colors[_OldColor].g;
_b = Colors[_OldColor].b;
_a = Colors[_OldColor].a;
_R = Colors[_TargetColor].r;
_G = Colors[_TargetColor].g;
_B = Colors[_TargetColor].b;
_A = Colors[_TargetColor].a;
}
}
}