-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Emission.cs
173 lines (160 loc) · 4.89 KB
/
Emission.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using UdonSharp;
using UnityEngine;
using UnityEngine.UI;
using VRC.SDKBase;
using VRC.Udon;
using VRC.SDK3.Video.Components.AVPro;
namespace UdonVR.Childofthebeast
{
public class Emission : UdonSharpBehaviour
{
#if UNITY_ANDROID
private bool isQuest = true;
#else
private bool isQuest = false;
#endif
public MeshRenderer ScreenMesh;
public int Material_Index;
public bool SharedMerial = false;
public bool DefaultOff = false;
public bool UpdateRealtimeGI = false;
public GameObject[] ButtonFills;
public int FrameSkip = 5;
public GameObject FrameSkipUI;
private Material _ScreenMaterial;
private float _CurrentEmission = 1;
private bool _IsOn = true;
private int _Frame = 0;
public InputField FrameSkipFeild;
public Text FramSkipText;
private void Start()
{
if (UpdateRealtimeGI && FrameSkipUI != null) FrameSkipUI.SetActive(true);
if (!isQuest) InitPC();
if (ScreenMesh == null) ScreenMesh = gameObject.GetComponent<MeshRenderer>();
if (SharedMerial)
{
_ScreenMaterial = ScreenMesh.sharedMaterials[Material_Index];
}
else
{
_ScreenMaterial = ScreenMesh.materials[Material_Index];
}
_ScreenMaterial.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive;
if (DefaultOff) SetHide();
}
public void SetHide()
{
if (!_IsOn)
{
SetEmission();
}
else
{
_ScreenMaterial.SetFloat("_Emission", 0);
_IsOn = false;
if (ScreenMesh != null)
RendererExtensions.UpdateGIMaterials(ScreenMesh);
}
}
public void SetOff()
{
if (_CurrentEmission != .1f)
{
ButtonFills[0].SetActive(true);
ButtonFills[1].SetActive(false);
ButtonFills[2].SetActive(false);
_CurrentEmission = .1f;
SetEmission();
}
else Set0();
}
public void Set1()
{
if (_CurrentEmission != 1f)
{
ButtonFills[1].SetActive(true);
ButtonFills[0].SetActive(false);
ButtonFills[2].SetActive(false);
_CurrentEmission = 1f;
SetEmission();
}
else Set0();
}
public void Set2()
{
if (_CurrentEmission != 2f)
{
ButtonFills[2].SetActive(true);
ButtonFills[1].SetActive(false);
ButtonFills[0].SetActive(false);
_CurrentEmission = 2f;
SetEmission();
}
else Set0();
}
public void Set0()
{
ButtonFills[2].SetActive(false);
ButtonFills[1].SetActive(false);
ButtonFills[0].SetActive(false);
_CurrentEmission = 0f;
_ScreenMaterial.SetFloat("_Emission", _CurrentEmission);
_IsOn = false;
RendererExtensions.UpdateGIMaterials(ScreenMesh);
}
public void SetEmission()
{
_ScreenMaterial.SetFloat("_Emission", _CurrentEmission);
_IsOn = true;
}
private void Update()
{
if (_Frame >= FrameSkip)
{
if (ScreenMesh != null && _IsOn && UpdateRealtimeGI)
RendererExtensions.UpdateGIMaterials(ScreenMesh);
_Frame = 0;
}
else
{
_Frame++;
}
}
public void FrameUp()
{
FrameSkip++;
UpdateFeild(FrameSkip.ToString());
}
public void FrameDown()
{
if (FrameSkip <= 0) return;
FrameSkip--;
UpdateFeild(FrameSkip.ToString());
}
public void FrameSet()
{
int _var = 0;
int.TryParse(FrameSkipFeild.text, out _var);
if (_var <= 0) _var = 0;
FrameSkip = _var;
UpdateFeild(FrameSkip.ToString());
}
private void UpdateFeild(string _str)
{
if (isQuest)
{
FramSkipText.text = _str;
}
else
{
FrameSkipFeild.text = _str;
}
}
private void InitPC()
{
if (UpdateRealtimeGI && FrameSkipUI != null) FrameSkipFeild.interactable = true;
}
}
}