| 1 | #if UNITY_EDITOR |
| 2 | using UnityEngine; |
| 3 | using System.Collections; |
| 4 | using UnityEditor; |
| 5 | using Oculus.Avatar; |
| 6 | |
| 7 | [CustomEditor(typeof(OvrAvatarSettings))] |
| 8 | [InitializeOnLoadAttribute] |
| 9 | public class OvrAvatarSettingsEditor : Editor { |
| 10 | GUIContent appIDLabel = new GUIContent("Oculus Rift App Id [?]", |
| 11 | "This AppID will be used for OvrAvatar registration."); |
| 12 | |
| 13 | GUIContent mobileAppIDLabel = new GUIContent("Oculus Go/Quest or Gear VR [?]", |
| 14 | "This AppID will be used when building to the Android target"); |
| 15 | |
| 16 | [UnityEditor.MenuItem("Oculus/Avatars/Edit Settings")] |
| 17 | public static void Edit() |
| 18 | { |
| 19 | var settings = OvrAvatarSettings.Instance; |
| 20 | UnityEditor.Selection.activeObject = settings; |
| 21 | CAPI.SendEvent("edit_settings"); |
| 22 | } |
| 23 | |
| 24 | static OvrAvatarSettingsEditor() |
| 25 | { |
| 26 | #if UNITY_2017_2_OR_NEWER |
| 27 | EditorApplication.playModeStateChanged += HandlePlayModeState; |
| 28 | #else |
| 29 | EditorApplication.playmodeStateChanged += () => |
| 30 | { |
| 31 | if (EditorApplication.isPlaying) |
| 32 | { |
| 33 | CAPI.SendEvent("load", CAPI.AvatarSDKVersion.ToString()); |
| 34 | } |
| 35 | }; |
| 36 | #endif |
| 37 | } |
| 38 | |
| 39 | #if UNITY_2017_2_OR_NEWER |
| 40 | private static void HandlePlayModeState(PlayModeStateChange state) |
| 41 | { |
| 42 | if (state == PlayModeStateChange.EnteredPlayMode) |
| 43 | { |
| 44 | CAPI.SendEvent("load", CAPI.AvatarSDKVersion.ToString()); |
| 45 | } |
| 46 | } |
| 47 | #endif |
| 48 | |
| 49 | private static string MakeTextBox(GUIContent label, string variable) { |
| 50 | EditorGUILayout.BeginHorizontal(); |
| 51 | EditorGUILayout.LabelField(label); |
| 52 | GUI.changed = false; |
| 53 | var result = EditorGUILayout.TextField(variable); |
| 54 | if (GUI.changed) |
| 55 | { |
| 56 | EditorUtility.SetDirty(OvrAvatarSettings.Instance); |
| 57 | GUI.changed = false; |
| 58 | } |
| 59 | EditorGUILayout.EndHorizontal(); |
| 60 | return result; |
| 61 | } |
| 62 | public override void OnInspectorGUI() |
| 63 | { |
| 64 | EditorGUILayout.BeginVertical(); |
| 65 | OvrAvatarSettings.AppID = |
| 66 | OvrAvatarSettingsEditor.MakeTextBox(appIDLabel, OvrAvatarSettings.AppID); |
| 67 | OvrAvatarSettings.MobileAppID = |
| 68 | OvrAvatarSettingsEditor.MakeTextBox(mobileAppIDLabel, OvrAvatarSettings.MobileAppID); |
| 69 | EditorGUILayout.EndVertical(); |
| 70 | } |
| 71 | } |
| 72 | #endif |