Tanoda
LeapUnityWindow.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEditor;
10using UnityEngine;
11using Leap.Unity;
12
13namespace Leap.Unity {
14
15 [InitializeOnLoad]
16 public class LeapUnityWindow : EditorWindow {
17
18 #region Settings & Init
19
20 private const string WINDOW_TITLE = "Leap Motion Unity Modules";
21 private static readonly Vector2 WINDOW_MIN_SIZE = new Vector2(600f, 600f);
22 private static LeapUnityWindow _currentWindow = null;
23
29 private const string LEAP_UNITY_WINDOW_LAUNCHED_PREF = "Leap Unity Window Launched";
34 static LeapUnityWindow() {
35 EditorApplication.delayCall += () => {
36 if (!EditorPrefs.GetBool(LEAP_UNITY_WINDOW_LAUNCHED_PREF)) {
37 EditorPrefs.SetBool(LEAP_UNITY_WINDOW_LAUNCHED_PREF, true);
38 Init();
39 }
40 };
41 }
42
43 [MenuItem("Window/Leap Motion")]
44 public static void Init() {
45 var window = (LeapUnityWindow)GetWindow(typeof(LeapUnityWindow),
46 utility: true, title: WINDOW_TITLE, focus: true);
47 window.name = "Leap Motion Unity Modules Window";
48 window.minSize = WINDOW_MIN_SIZE;
49 _currentWindow = window;
50 }
51
52 #endregion
53
54 #region Resources
55
56 private string leapLogoResourceName {
57 get {
58 if (EditorGUIUtility.isProSkin) return "LM_Logo_White";
59 else return "LM_Logo_Black";
60 }
61 }
62
63 private Texture2D _backingLeapTex = null;
64 private Texture2D leapTex {
65 get {
66 if (_backingLeapTex == null) {
67 _backingLeapTex = EditorResources.Load<Texture2D>(leapLogoResourceName);
68 }
69 return _backingLeapTex;
70 }
71 }
72
73 private static GUISkin s_backingWindowSkin;
74 public static GUISkin windowSkin {
75 get {
76 if (s_backingWindowSkin == null) {
77 s_backingWindowSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);
78 }
79 return s_backingWindowSkin;
80 }
81 }
82
83 #endregion
84
85 #region Window State
86
87 public static bool isWindowOpen {
88 get {
89 return _currentWindow != null;
90 }
91 }
92
93 private int _tabIndex = 0;
94 private static string[] _tabs = new string[] {
95 "Project Checks", "Rig Upgrader", "Preferences"
96 };
97 public static void ShowTab(int tabIndex) {
98 if (_currentWindow != null) {
99 _currentWindow._tabIndex = tabIndex;
100 }
101 }
102 public static int GetTabCount() { return _tabs.Length; }
103
104 private Vector2 _scrollPosition = Vector2.zero;
105
106 #endregion
107
108 #region OnGUI
109
110 private void OnGUI() {
111 var origSkin = GUI.skin;
112 try {
113 GUI.skin = windowSkin;
114
115 drawGUI();
116 }
117 finally {
118 GUI.skin = origSkin;
119 }
120 }
121
122 private void drawGUI() {
123 var boxStyle = windowSkin.box;
124 GUILayout.BeginVertical();
125
126 // Logo.
127 var logoStyle = windowSkin.box;
128 logoStyle.fixedHeight = 150;
129 logoStyle.stretchWidth = true;
130 logoStyle.alignment = TextAnchor.MiddleCenter;
131 logoStyle.margin = new RectOffset(0, 0, top: 20, bottom: 20);
132 GUILayout.Box(new GUIContent(leapTex), logoStyle, GUILayout.ExpandWidth(true),
133 GUILayout.MaxHeight(150f));
134
135 // Window tabs.
136 _tabIndex = GUILayout.Toolbar(_tabIndex, _tabs);
137 _scrollPosition = GUILayout.BeginScrollView(_scrollPosition,
138 GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
139 switch (_tabIndex) {
140 case 0:
141 LeapProjectChecks.DrawProjectChecksGUI();
142 break;
143 case 1:
144 LeapRigUpgrader.DrawUpgraderGUI();
145 break;
146 case 2:
147 float prevLabelWidth = EditorGUIUtility.labelWidth;
148 EditorGUIUtility.labelWidth = 200;
149 LeapPreferences.DrawPreferencesGUI();
150 EditorGUIUtility.labelWidth = prevLabelWidth;
151 break;
152 default:
153 _tabIndex = 0;
154 break;
155 }
156 GUILayout.EndScrollView();
157
158 GUILayout.EndVertical();
159 }
160
161 #endregion
162
163 }
164
165}
This attribute is used to add items to the Leap Motion preferences window. This allows each module to...
static void ShowTab(int tabIndex)