forked from acidbubbles/vam-glance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlanceTarget.cs
58 lines (49 loc) · 1.72 KB
/
GlanceTarget.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
using System;
using System.Collections;
using UnityEngine;
public class GlanceTarget : MVRScript
{
private readonly JSONStorableBool _onJSON = new JSONStorableBool("GlanceOn", true);
private readonly JSONStorableFloat _weightJSON = new JSONStorableFloat("Weight", 0.8f, 0f, 1f, true);
private JSONStorableBool _glanceTargetJSON;
private Atom _containingAtom;
public override void Init()
{
_containingAtom = containingAtom;
_onJSON.setCallbackFunction = val => { StartCoroutine(TriggerRescanCo()); };
CreateToggle(_onJSON).label = "On (will be looked at)";
RegisterBool(_onJSON);
_weightJSON.setCallbackFunction = val => { StartCoroutine(TriggerRescanCo()); };
CreateSlider(_weightJSON).label = "Weight (probability/duration)";
RegisterFloat(_weightJSON);
OnEnable();
}
private void OnEnable()
{
if (_containingAtom == null) return;
if (!_containingAtom.IsBoolJSONParam("GlanceTarget"))
{
_glanceTargetJSON = new JSONStorableBool("GlanceTarget", true);
_containingAtom.RegisterBool(_glanceTargetJSON);
}
StartCoroutine(TriggerRescanCo());
}
private void OnDisable()
{
if (_glanceTargetJSON != null)
{
_containingAtom.DeregisterBool(_glanceTargetJSON);
_glanceTargetJSON = null;
}
TriggerRescan();
}
private IEnumerator TriggerRescanCo()
{
yield return new WaitForEndOfFrame();
TriggerRescan();
}
private static void TriggerRescan()
{
SuperController.singleton.transform.parent.BroadcastMessage("Refocus", SendMessageOptions.DontRequireReceiver);
}
}