Exemplo n.º 1
0
        public void AddNewController()
        {
            ControllerStruct controllerStruct = new ControllerStruct();

            controllerStruct.Name              = "Controller Device Name";
            controllerStruct.TotalButton       = 0;
            controllerStruct.TotalAxis1DButton = 0;
            controllerStruct.TotalAxis2DButton = 0;
            controllerStruct.hand              = XR_Enum.Hand.RIGHT;
            controllerStruct.id = CreateDeviceID();

            controllerList.Add(controllerStruct);
        }
Exemplo n.º 2
0
        void KeyBinding()
        {
            EditorGUILayout.Space();

            if (m_keyBindingData.controllerList.Count > 0)
            {
                if (m_keyBindingData.controllerList.Count > 0)
                {
                    EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(350));

                    if (GUILayout.Button("<==", GUILayout.Width(50)))
                    {
                        if (m_keyBindingData.currentControllerIndex > 0)
                        {
                            m_keyBindingData.currentControllerIndex--;
                        }
                        else
                        {
                            m_keyBindingData.currentControllerIndex = m_keyBindingData.controllerList.Count - 1;
                        }
                    }

                    GUILayout.FlexibleSpace();

                    List <string> deviceName  = new List <string>();
                    List <int>    deviceIndex = new List <int>();
                    for (int i = 0; i < m_keyBindingData.controllerList.Count; i++)
                    {
                        deviceName.Add(m_keyBindingData.controllerList[i].Name + " " + m_keyBindingData.controllerList[i].hand);
                        deviceIndex.Add(i);
                    }

                    if (deviceName.Count > 0)
                    {
                        m_keyBindingData.currentControllerIndex =
                            EditorGUILayout.IntPopup(m_keyBindingData.currentControllerIndex, deviceName.ToArray(), deviceIndex.ToArray(), GUILayout.MinWidth(10));
                    }
                    GUILayout.FlexibleSpace();

                    if (GUILayout.Button("==>", GUILayout.Width(50)))
                    {
                        if (m_keyBindingData.currentControllerIndex < m_keyBindingData.controllerList.Count - 1)
                        {
                            m_keyBindingData.currentControllerIndex++;
                        }
                        else
                        {
                            m_keyBindingData.currentControllerIndex = 0;
                        }
                    }

                    EditorGUILayout.EndHorizontal();

                    ControllerStruct controller = m_keyBindingData.GetControllerByIndex(m_keyBindingData.currentControllerIndex);

                    EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(350));
                    EditorGUILayout.LabelField("Name: " + controller.Name.ToString(), EditorStyles.boldLabel, GUILayout.Width(200));
                    EditorGUILayout.LabelField("Hand: " + controller.hand.ToString(), EditorStyles.boldLabel, GUILayout.Width(200));
                    EditorGUILayout.EndHorizontal();

                    if (controller.TotalButton > 0)
                    {
                        //EditorGUILayout.LabelField("Button Press/Touch", EditorStyles.boldLabel, GUILayout.Width(250));
                        EditorGUILayout.Space();
                        EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(350));
                        EditorGUILayout.LabelField("Button Name", EditorStyles.boldLabel, GUILayout.Width(150));
                        EditorGUILayout.LabelField("Key Mapping", EditorStyles.boldLabel, GUILayout.Width(150));
                        EditorGUILayout.EndHorizontal();

                        XR_Enum.InputType inputType  = XR_Enum.InputType.Bool;
                        string[]          enumNames  = XR_Utilities.GetDeviceControllerKeysName((XR_Enum.DefaultController)controller.deviceType, inputType);
                        int[]             enumValues = XR_Utilities.GetDeviceControllerKeysValues((XR_Enum.DefaultController)controller.deviceType, inputType);
                        if (enumValues != null)
                        {
                            for (int i = 1; i <= controller.TotalButton; i++)
                            {
                                KeyMap keyMap = controller.GetKeyMap(enumValues[i], inputType);
                                EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(350));
                                string featureUsageName = ((XR_Enum.FeatureUsageButton)enumValues[i]).ToString();
                                EditorGUILayout.LabelField(featureUsageName, GUILayout.Width(150));
                                //keyMap.enumType = EditorGUILayout.Popup(keyMap.enumType, GetButtonsEnum, GUILayout.Width(100));
                                keyMap.mapedInput = EditorGUILayout.IntPopup(keyMap.mapedInput, enumNames, enumValues, GUILayout.Width(100));
                                controller.UpdateKeyMap(keyMap);
                                EditorGUILayout.EndHorizontal();
                            }
                        }
                    }

                    if (controller.TotalAxis1DButton > 0)
                    {
                        EditorGUILayout.Space();
                        EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(350));
                        EditorGUILayout.LabelField("Axis1D Name", EditorStyles.boldLabel, GUILayout.Width(150));
                        EditorGUILayout.LabelField("Key Mapping", EditorStyles.boldLabel, GUILayout.Width(150));
                        EditorGUILayout.EndHorizontal();

                        XR_Enum.InputType inputType  = XR_Enum.InputType.Axis1D;
                        string[]          enumNames  = XR_Utilities.GetDeviceControllerKeysName((XR_Enum.DefaultController)controller.deviceType, inputType);
                        int[]             enumValues = XR_Utilities.GetDeviceControllerKeysValues((XR_Enum.DefaultController)controller.deviceType, inputType);
                        if (enumValues != null)
                        {
                            for (int i = 1; i <= controller.TotalAxis1DButton; i++)
                            {
                                KeyMap keyMap = controller.GetKeyMap(enumValues[i], inputType);
                                EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(350));
                                string featureUsageName = ((XR_Enum.FeatureUsageAxis)enumValues[i]).ToString();
                                EditorGUILayout.LabelField(featureUsageName, GUILayout.Width(150));
                                keyMap.mapedInput = EditorGUILayout.IntPopup(keyMap.mapedInput, enumNames, enumValues, GUILayout.Width(100));
                                controller.UpdateKeyMap(keyMap);
                                EditorGUILayout.EndHorizontal();
                            }
                        }
                    }

                    if (controller.TotalAxis2DButton > 0)
                    {
                        EditorGUILayout.Space();
                        EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(350));
                        EditorGUILayout.LabelField("Axis2D Name", EditorStyles.boldLabel, GUILayout.Width(150));
                        EditorGUILayout.LabelField("Key Mapping", EditorStyles.boldLabel, GUILayout.Width(150));
                        EditorGUILayout.EndHorizontal();

                        XR_Enum.InputType inputType  = XR_Enum.InputType.Axis2D;
                        string[]          enumNames  = XR_Utilities.GetDeviceControllerKeysName((XR_Enum.DefaultController)controller.deviceType, inputType);
                        int[]             enumValues = XR_Utilities.GetDeviceControllerKeysValues((XR_Enum.DefaultController)controller.deviceType, inputType);
                        if (enumValues != null)
                        {
                            for (int i = 1; i <= controller.TotalAxis2DButton; i++)
                            {
                                KeyMap keyMap = controller.GetKeyMap(enumValues[i], inputType);
                                EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(350));
                                string featureUsageName = ((XR_Enum.FeatureUsage2DAxis)enumValues[i]).ToString();
                                EditorGUILayout.LabelField(featureUsageName, GUILayout.Width(150));
                                keyMap.mapedInput = EditorGUILayout.IntPopup(keyMap.mapedInput, enumNames, enumValues, GUILayout.Width(100));
                                controller.UpdateKeyMap(keyMap);
                                EditorGUILayout.EndHorizontal();
                            }
                        }
                    }
                }
            }

            EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(350));
            EditorGUILayout.EndHorizontal();
        }
Exemplo n.º 3
0
        void XRController()
        {
            EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(250));
            if (GUILayout.Button("Add XR Default Controller", GUILayout.MaxWidth(150), GUILayout.MaxHeight(20)))
            {
                m_keyBindingData.AddNewController();
            }
            EditorGUILayout.EndHorizontal();

            if (m_keyBindingData.controllerList.Count > 0)
            {
                EditorGUILayout.Space();

                if (m_keyBindingData.foldControllerList == false)
                {
                    if (GUILayout.Button("Show", EditorStyles.miniButtonRight, GUILayout.Width(50)))
                    {
                        m_keyBindingData.foldControllerList = true;
                    }
                }

                if (m_keyBindingData.foldControllerList)
                {
                    if (GUILayout.Button("Hide", EditorStyles.miniButtonRight, GUILayout.Width(50)))
                    {
                        m_keyBindingData.foldControllerList = false;
                    }
                }

                EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(350));
                EditorGUILayout.LabelField(" ", GUILayout.Width(20));
                EditorGUILayout.LabelField("ID", GUILayout.Width(20));
                EditorGUILayout.LabelField("Controller", GUILayout.Width(150));
                EditorGUILayout.LabelField("Total Button", GUILayout.Width(80));
                EditorGUILayout.LabelField("Total Axis1D", GUILayout.Width(80));
                EditorGUILayout.LabelField("Total Axis2D", GUILayout.Width(80));
                EditorGUILayout.EndHorizontal();

                if (m_keyBindingData.foldControllerList)
                {
                    for (int i = 0; i < m_keyBindingData.controllerList.Count; i++)
                    {
                        ControllerStruct controller = m_keyBindingData.controllerList[i];

                        EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(280));
                        EditorGUILayout.LabelField((i + 1).ToString(), GUILayout.Width(20));
                        EditorGUILayout.LabelField(controller.id.ToString(), GUILayout.Width(20));

                        controller.deviceType = EditorGUILayout.Popup(controller.deviceType, XR_Utilities.GetDefaultDevice(), GUILayout.Width(150));

                        int maxButton = 0, maxAxis = 0, max2DAxis = 0;
                        if (controller.deviceType == 0)
                        {
                            controller.UpdateData("None");
                        }
                        else
                        {
                            if (XR_Utilities.GetDeviceControllerKeysName((XR_Enum.DefaultController)controller.deviceType, XR_Enum.InputType.Bool) != null)
                            {
                                maxButton = XR_Utilities.GetDeviceControllerKeysName((XR_Enum.DefaultController)controller.deviceType, XR_Enum.InputType.Bool).Length - 1;
                                if (controller.TotalButton == 0 || controller.TotalButton > maxButton)
                                {
                                    controller.TotalButton = maxButton;
                                }
                            }
                            if (XR_Utilities.GetDeviceControllerKeysName((XR_Enum.DefaultController)controller.deviceType, XR_Enum.InputType.Axis1D) != null)
                            {
                                maxAxis = XR_Utilities.GetDeviceControllerKeysName((XR_Enum.DefaultController)controller.deviceType, XR_Enum.InputType.Axis1D).Length - 1;
                                if (controller.TotalAxis1DButton == 0 || controller.TotalAxis1DButton > maxAxis)
                                {
                                    controller.TotalAxis1DButton = maxAxis;
                                }
                            }
                            if (XR_Utilities.GetDeviceControllerKeysName((XR_Enum.DefaultController)controller.deviceType, XR_Enum.InputType.Axis2D) != null)
                            {
                                max2DAxis = XR_Utilities.GetDeviceControllerKeysName((XR_Enum.DefaultController)controller.deviceType, XR_Enum.InputType.Axis2D).Length - 1;
                                if (controller.TotalAxis2DButton == 0 || controller.TotalAxis2DButton > max2DAxis)
                                {
                                    controller.TotalAxis2DButton = max2DAxis;
                                }
                            }

                            string deviceName = ((XR_Enum.DefaultController)controller.deviceType).ToString();
                            controller.UpdateData(deviceName, controller.TotalButton, controller.TotalAxis1DButton, controller.TotalAxis2DButton);
                        }


                        EditorGUILayout.LabelField(m_keyBindingData.controllerList[i].TotalButton.ToString(), EditorStyles.boldLabel, GUILayout.Width(30));
                        if (GUILayout.Button("+", EditorStyles.miniButtonLeft, GUILayout.Width(20)))
                        {
                            if (controller.TotalButton < maxButton)
                            {
                                controller.TotalButton++;
                            }
                        }
                        if (GUILayout.Button("-", EditorStyles.miniButtonRight, GUILayout.Width(20)))
                        {
                            if (controller.TotalButton > 0)
                            {
                                controller.TotalButton--;
                            }
                        }

                        EditorGUILayout.LabelField(m_keyBindingData.controllerList[i].TotalAxis1DButton.ToString(), EditorStyles.boldLabel, GUILayout.Width(30));
                        if (GUILayout.Button("+", EditorStyles.miniButtonLeft, GUILayout.Width(20)))
                        {
                            if (controller.TotalButton < maxAxis)
                            {
                                controller.TotalAxis1DButton++;
                            }
                        }
                        if (GUILayout.Button("-", EditorStyles.miniButtonRight, GUILayout.Width(20)))
                        {
                            if (controller.TotalAxis1DButton > 0)
                            {
                                controller.TotalAxis1DButton--;
                            }
                        }

                        EditorGUILayout.LabelField(m_keyBindingData.controllerList[i].TotalAxis2DButton.ToString(), EditorStyles.boldLabel, GUILayout.Width(30));
                        if (GUILayout.Button("+", EditorStyles.miniButtonLeft, GUILayout.Width(20)))
                        {
                            if (controller.TotalButton < max2DAxis)
                            {
                                controller.TotalAxis2DButton++;
                            }
                        }
                        if (GUILayout.Button("-", EditorStyles.miniButtonRight, GUILayout.Width(20)))
                        {
                            if (controller.TotalAxis2DButton > 0)
                            {
                                controller.TotalAxis2DButton--;
                            }
                        }

                        controller.hand = (XR_Enum.Hand)EditorGUILayout.EnumPopup(controller.hand, GUILayout.Width(50));


                        if (GUILayout.Button(" Delete ", EditorStyles.miniButtonMid, GUILayout.Width(40)))
                        {
                            m_keyBindingData.controllerList.RemoveAt(i);
                            break;
                        }

                        if (m_keyBindingData.controllerList.Count > 0)
                        {
                            m_keyBindingData.controllerList[i] = controller;
                        }

                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
        }