/// This method creates the inspector when the program is running. In this mode we /// only show information on what is initialized, valid etc. but allow no changes. protected void RunInspector() { // for easy access to the object NITEHandsManager handsManagerObject = target as NITEHandsManager; // basic test. If the object is invalid, nothing else matters. if (handsManagerObject.ValidWithInit == false) { EditorGUILayout.LabelField("NI was not initialized and therefore everything is invalid!", ""); return; } EditorGUILayout.LabelField("Hands control is ", handsManagerObject.ValidWithInit ? "Valid" : "not valid"); // the foldout allows to see just relevant info (and order it a bit). // note that even if the hands control is invalid, data exists here EditorGUILayout.LabelField("Focus Gesture used:", handsManagerObject.m_focusGesture); EditorGUILayout.LabelField("Refocus Gesture used:", handsManagerObject.m_refocusGesture); EditorGUILayout.LabelField("Current state: ", "" + handsManagerObject.Hands.CurrentState); EditorGUILayout.Space(); }
/// the goal of this method is to initialize the indices based on the target object. protected void InitFromTarget() { // for easy access to the object NITEHandsManager handsManagerObject = target as NITEHandsManager; if (handsManagerObject == null) { if (target != null) { Debug.Log(target.GetType()); } else { Debug.Log("target is null!"); } } bool shouldFocus = handsManagerObject.m_focusGesture == null || handsManagerObject.m_focusGesture.CompareTo("") != 0; int focusGesture = -1; if (shouldFocus) { focusGesture = FindIndexInList(m_defaultVersionGestureList, handsManagerObject.m_focusGesture); } bool shouldRefocus = handsManagerObject.m_refocusGesture == null || handsManagerObject.m_refocusGesture.CompareTo("") != 0; int refocusGesture = -1; if (shouldRefocus) { refocusGesture = FindIndexInList(m_defaultVersionGestureList, handsManagerObject.m_refocusGesture); } if ((shouldFocus == false || focusGesture >= 0) && (shouldRefocus == false || refocusGesture >= 0)) { // this is a good find m_refocusGestureChoice = refocusGesture; m_focusGestureChoice = focusGesture; m_useFocus = shouldFocus; m_useRefocus = shouldRefocus; m_useBasicGestureList = true; return; } // if we are here then we couldn't find a good match, lets try the same with the current version if (InitGestures() == false) { // can't find a good choice at all. Lets reinitialize to nothing m_refocusGestureChoice = -1; m_focusGestureChoice = -1; m_useFocus = false; m_useRefocus = false; m_useBasicGestureList = true; return; } focusGesture = -1; if (shouldFocus) { focusGesture = FindIndexInList(m_currentVersionGestureList, handsManagerObject.m_focusGesture); } refocusGesture = -1; if (shouldRefocus) { refocusGesture = FindIndexInList(m_currentVersionGestureList, handsManagerObject.m_refocusGesture); } if ((shouldFocus == false || focusGesture >= 0) && (shouldRefocus == false || refocusGesture >= 0)) { // this is a good find m_refocusGestureChoice = refocusGesture; m_focusGestureChoice = focusGesture; m_useFocus = shouldFocus; m_useRefocus = shouldRefocus; m_useBasicGestureList = false; return; } // if we are here neither was a good choice so lets reinitialize m_refocusGestureChoice = -1; m_focusGestureChoice = -1; m_useRefocus = false; m_useFocus = false; m_useBasicGestureList = true; }
/// This method creates the inspector when the program is NOT running. In this mode we /// allow initialization but do not show any running information protected void InitInspector() { // for easy access to the object NITEHandsManager handsManagerObject = target as NITEHandsManager; // using hands control if (m_initializedFromBefore == false) { InitFromTarget(); m_initializedFromBefore = true; } // choose gestures. m_myContent.text = "Use basic gesture list"; m_myContent.tooltip = "The basic gesture list is supported by all implementation, If false this uses the values available on the local machine"; bool useBasicGestureList = EditorGUILayout.Toggle(m_myContent, m_useBasicGestureList); string[] gestures = m_defaultVersionGestureList; if (useBasicGestureList == false) { // if we are here we need to make sure m_currentVersionGestureList holds the current list // of gestures. if (InitGestures()) { gestures = m_currentVersionGestureList; } else { Debug.Log("Can't initialize current version!!!!!, defaulting to regular version!"); m_useBasicGestureList = false; } } // we changed the gesture list so we need to find the new index which corresponds to // the previous choices if (m_useBasicGestureList != useBasicGestureList) { m_focusGestureChoice = FindIndexInList(gestures, handsManagerObject.m_focusGesture); m_useFocus = m_focusGestureChoice >= 0; m_refocusGestureChoice = FindIndexInList(gestures, handsManagerObject.m_refocusGesture); m_useRefocus = m_refocusGestureChoice >= 0; m_useBasicGestureList = useBasicGestureList; } bool useFocus = EditorGUILayout.Toggle("Use Focus?", m_useFocus); if (useFocus != m_useFocus) { if (useFocus == false) { handsManagerObject.m_focusGesture = ""; m_focusGestureChoice = -1; } else { m_focusGestureChoice = 0; } } m_useFocus = useFocus; if (m_useFocus) { EditorGUI.indentLevel += 2; m_focusGestureChoice = EditorGUILayout.Popup("Gesture to use", m_focusGestureChoice, gestures); EditorGUI.indentLevel -= 2; handsManagerObject.m_focusGesture = gestures[m_focusGestureChoice]; } // we might not want to use refocus (which will make it into ""). bool useRefocus = EditorGUILayout.Toggle("Use refocus?", m_useRefocus); if (useRefocus != m_useRefocus) { if (useRefocus == false) { handsManagerObject.m_refocusGesture = ""; m_refocusGestureChoice = -1; } else { m_refocusGestureChoice = 0; } } m_useRefocus = useRefocus; if (m_useRefocus) { EditorGUI.indentLevel += 2; m_refocusGestureChoice = EditorGUILayout.Popup("Gesture to use", m_refocusGestureChoice, gestures); EditorGUI.indentLevel -= 2; handsManagerObject.m_refocusGesture = gestures[m_refocusGestureChoice]; } if (GUI.changed) { EditorUtility.SetDirty(target); } }