Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.2 KiB

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