OvrAvatarSettingsEditor.cs
2.21 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
#if UNITY_EDITOR
using UnityEngine;
using System.Collections;
using UnityEditor;
using Oculus.Avatar;
[CustomEditor(typeof(OvrAvatarSettings))]
[InitializeOnLoadAttribute]
public class OvrAvatarSettingsEditor : Editor {
GUIContent appIDLabel = new GUIContent("Oculus Rift App Id [?]",
"This AppID will be used for OvrAvatar registration.");
GUIContent mobileAppIDLabel = new GUIContent("Oculus Go/Quest or Gear VR [?]",
"This AppID will be used when building to the Android target");
[UnityEditor.MenuItem("Oculus/Avatars/Edit Settings")]
public static void Edit()
{
var settings = OvrAvatarSettings.Instance;
UnityEditor.Selection.activeObject = settings;
CAPI.SendEvent("edit_settings");
}
static OvrAvatarSettingsEditor()
{
#if UNITY_2017_2_OR_NEWER
EditorApplication.playModeStateChanged += HandlePlayModeState;
#else
EditorApplication.playmodeStateChanged += () =>
{
if (EditorApplication.isPlaying)
{
CAPI.SendEvent("load", CAPI.AvatarSDKVersion.ToString());
}
};
#endif
}
#if UNITY_2017_2_OR_NEWER
private static void HandlePlayModeState(PlayModeStateChange state)
{
if (state == PlayModeStateChange.EnteredPlayMode)
{
CAPI.SendEvent("load", CAPI.AvatarSDKVersion.ToString());
}
}
#endif
private static string MakeTextBox(GUIContent label, string variable) {
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(label);
GUI.changed = false;
var result = EditorGUILayout.TextField(variable);
if (GUI.changed)
{
EditorUtility.SetDirty(OvrAvatarSettings.Instance);
GUI.changed = false;
}
EditorGUILayout.EndHorizontal();
return result;
}
public override void OnInspectorGUI()
{
EditorGUILayout.BeginVertical();
OvrAvatarSettings.AppID =
OvrAvatarSettingsEditor.MakeTextBox(appIDLabel, OvrAvatarSettings.AppID);
OvrAvatarSettings.MobileAppID =
OvrAvatarSettingsEditor.MakeTextBox(mobileAppIDLabel, OvrAvatarSettings.MobileAppID);
EditorGUILayout.EndVertical();
}
}
#endif