// Draw the property inside the given rect
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (enumItems == null || enumItems.Length == 0)
            {
                Awake();
            }

            // Using BeginProperty / EndProperty on the parent property means that
            // prefab override logic works on the entire property.
            EditorGUI.BeginProperty(position, label, property);


            if (property.objectReferenceValue != null)
            {
                var actionSet = (SteamVR_ActionSet)property.objectReferenceValue;

                if (string.IsNullOrEmpty(actionSet.fullPath) == false)
                {
                    for (var actionSetIndex = 0; actionSetIndex < actionSets.Length; actionSetIndex++)
                    {
                        if (actionSets[actionSetIndex].fullPath == actionSet.fullPath)
                        {
                            selectedIndex = actionSetIndex + 1;
                            break;
                        }
                    }
                }
            }

            if (selectedIndex == notInitializedIndex)
            {
                selectedIndex = 0;
            }


            var labelPosition = position;

            labelPosition.width = EditorGUIUtility.labelWidth;
            EditorGUI.LabelField(labelPosition, label);

            var fieldPosition = position;

            fieldPosition.x     = (labelPosition.x + labelPosition.width);
            fieldPosition.width = EditorGUIUtility.currentViewWidth - (labelPosition.x + labelPosition.width) - 5 - 16;

            var objectRect = position;

            objectRect.x     = fieldPosition.x + fieldPosition.width + 15;
            objectRect.width = 10;

            if (property.objectReferenceValue != null)
            {
                var selectObject = EditorGUI.Foldout(objectRect, false, GUIContent.none);
                if (selectObject)
                {
                    Selection.activeObject = property.objectReferenceValue;
                }
            }


            var wasSelected = selectedIndex;

            selectedIndex = EditorGUI.Popup(fieldPosition, selectedIndex, enumItems);
            if (selectedIndex != wasSelected)
            {
                if (selectedIndex == noneIndex || selectedIndex == notInitializedIndex)
                {
                    selectedIndex = noneIndex;
                    property.objectReferenceValue = null;
                }
                else if (selectedIndex == addIndex)
                {
                    selectedIndex = wasSelected;             // don't change the index
                    SteamVR_Input_EditorWindow.ShowWindow(); //show the input window so they can add one
                }
                else
                {
                    property.objectReferenceValue = actionSets[selectedIndex - 1];
                }
            }

            EditorGUI.EndProperty();
        }
예제 #2
0
        // Draw the property inside the given rect
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (SteamVR_Input.actions == null || SteamVR_Input.actions.Length == 0)
            {
                EditorGUI.BeginProperty(position, label, property);
                EditorGUI.LabelField(position, "Please generate SteamVR Input actions");
                EditorGUI.EndProperty();
                return;
            }

            if (enumItems == null || enumItems.Length == 0)
            {
                Awake();
            }

            // Using BeginProperty / EndProperty on the parent property means that
            // prefab override logic works on the entire property.
            EditorGUI.BeginProperty(position, label, property);

            SerializedProperty actionPathProperty = property.FindPropertyRelative("actionPath");
            string             currentPath        = null;

            if (actionPathProperty != null)
            {
                currentPath = actionPathProperty.stringValue;

                if (string.IsNullOrEmpty(currentPath) == false)
                {
                    SteamVR_Action existingAction = SteamVR_Action.FindExistingActionForPartialPath(currentPath);
                    if (existingAction != null)
                    {
                        if (currentPath != existingAction.GetPath())
                        {
                            actionPathProperty.stringValue = existingAction.GetPath();
                            property.serializedObject.ApplyModifiedProperties();
                        }

                        currentPath = existingAction.GetPath();
                    }

                    for (int actionsIndex = 0; actionsIndex < actions.Length; actionsIndex++)
                    {
                        if (actions[actionsIndex].fullPath == currentPath)
                        {
                            selectedIndex = actionsIndex + 1; // account for none option
                            break;
                        }
                    }
                }
            }

            if (selectedIndex == notInitializedIndex)
            {
                selectedIndex = 0;
            }


            Rect labelPosition = position;

            labelPosition.width = EditorGUIUtility.labelWidth;
            EditorGUI.LabelField(labelPosition, label);

            Rect fieldPosition = position;

            fieldPosition.x     = (labelPosition.x + labelPosition.width);
            fieldPosition.width = EditorGUIUtility.currentViewWidth - (labelPosition.x + labelPosition.width) - 5;

            if (selectedIndex == 0 && string.IsNullOrEmpty(currentPath) == false)
            {
                if (defaultPathLabel == null)
                {
                    defaultPathLabel = string.Format(defaultPathTemplate, currentPath);
                }

                Rect defaultLabelPosition = position;
                defaultLabelPosition.y = position.y + fieldPosition.height / 2f;

                if (defaultPathLabel == null)
                {
                    defaultPathLabel = string.Format(defaultPathTemplate, actionPathProperty.stringValue);
                }

                EditorGUI.LabelField(defaultLabelPosition, defaultPathLabel);
            }

            bool showInputWindow = false;

            int wasSelected = selectedIndex;

            selectedIndex = EditorGUI.Popup(fieldPosition, selectedIndex, enumItems);
            if (selectedIndex != wasSelected)
            {
                if (selectedIndex == noneIndex || selectedIndex == notInitializedIndex)
                {
                    selectedIndex = noneIndex;

                    actionPathProperty.stringValue = null;
                }
                else if (selectedIndex == addIndex)
                {
                    selectedIndex   = wasSelected; // don't change the index
                    showInputWindow = true;
                }
                else
                {
                    int actionIndex = selectedIndex - 1; // account for none option

                    actionPathProperty.stringValue = actions[actionIndex].GetPath();
                    //property.objectReferenceValue = actions[actionIndex];
                }

                property.serializedObject.ApplyModifiedProperties();
            }


            EditorGUI.EndProperty();

            if (showInputWindow)
            {
                SteamVR_Input_EditorWindow.ShowWindow(); //show the input window so they can add a new action
            }
        }
        // Draw the property inside the given rect
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (SteamVR_Input.actions == null || SteamVR_Input.actions.Length == 0)
            {
                EditorGUI.BeginProperty(position, label, property);
                EditorGUI.LabelField(position, "Please generate SteamVR Input actions");
                EditorGUI.EndProperty();
                return;
            }

            if (enumItems == null || enumItems.Length == 0)
            {
                Awake();
            }

            // Using BeginProperty / EndProperty on the parent property means that
            // prefab override logic works on the entire property.
            EditorGUI.BeginProperty(position, label, property);

            SerializedProperty actionPathProperty = property.FindPropertyRelative("actionSetPath");

            if (actionPathProperty != null)
            {
                string currentPath = actionPathProperty.stringValue;
                if (string.IsNullOrEmpty(currentPath) == false)
                {
                    for (int actionSetIndex = 0; actionSetIndex < actionSets.Length; actionSetIndex++)
                    {
                        if (actionSets[actionSetIndex].fullPath == currentPath)
                        {
                            selectedIndex = actionSetIndex + 1; // account for none option
                            break;
                        }
                    }
                }
            }

            if (selectedIndex == notInitializedIndex)
            {
                selectedIndex = 0;
            }


            Rect labelPosition = position;

            labelPosition.width = EditorGUIUtility.labelWidth;
            EditorGUI.LabelField(labelPosition, label);

            Rect fieldPosition = position;

            fieldPosition.x     = (labelPosition.x + labelPosition.width);
            fieldPosition.width = EditorGUIUtility.currentViewWidth - (labelPosition.x + labelPosition.width) - 5 - 16;

            Rect objectRect = position;

            objectRect.x     = fieldPosition.x + fieldPosition.width + 15;
            objectRect.width = 10;

            bool showInputWindow = false;

            int wasSelected = selectedIndex;

            selectedIndex = EditorGUI.Popup(fieldPosition, selectedIndex, enumItems);
            if (selectedIndex != wasSelected)
            {
                if (selectedIndex == noneIndex || selectedIndex == notInitializedIndex)
                {
                    selectedIndex = noneIndex;

                    actionPathProperty.stringValue = "";
                }
                else if (selectedIndex == addIndex)
                {
                    selectedIndex   = wasSelected; // don't change the index
                    showInputWindow = true;
                }
                else
                {
                    actionPathProperty.stringValue = actionSets[selectedIndex - 1].fullPath;

                    //property.objectReferenceValue = actionSets[selectedIndex - 1];
                }

                property.serializedObject.ApplyModifiedProperties();
            }

            EditorGUI.EndProperty();

            if (showInputWindow)
            {
                SteamVR_Input_EditorWindow.ShowWindow(); //show the input window so they can add a new actionset
            }
        }