public void Editor_CanIconsForLayouts()
    {
        const string kIconPath = "Packages/com.unity.inputsystem/InputSystem/Editor/Icons/";

        Assert.That(EditorInputControlLayoutCache.GetIconForLayout("Button"),
                    Is.SameAs(AssetDatabase.LoadAssetAtPath <Texture2D>(kIconPath + "Button.png")));
        Assert.That(EditorInputControlLayoutCache.GetIconForLayout("Axis"),
                    Is.SameAs(AssetDatabase.LoadAssetAtPath <Texture2D>(kIconPath + "Axis.png")));
        Assert.That(EditorInputControlLayoutCache.GetIconForLayout("Key"),
                    Is.SameAs(AssetDatabase.LoadAssetAtPath <Texture2D>(kIconPath + "Button.png")));
        Assert.That(EditorInputControlLayoutCache.GetIconForLayout("DualShockGamepad"),
                    Is.SameAs(AssetDatabase.LoadAssetAtPath <Texture2D>(kIconPath + "Gamepad.png")));
        Assert.That(EditorInputControlLayoutCache.GetIconForLayout("Pen"),
                    Is.SameAs(AssetDatabase.LoadAssetAtPath <Texture2D>(kIconPath + "Pen.png")));
    }
Beispiel #2
0
        public static string GetSteamControllerInputType(InputAction action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            // Make sure we have an expected control layout.
            var expectedControlLayout = action.expectedControlLayout;

            if (string.IsNullOrEmpty(expectedControlLayout))
            {
                throw new Exception(string.Format(
                                        "Cannot determine Steam input type for action '{0}' that has no associated expected control layout",
                                        action));
            }

            // Try to fetch the layout.
            var layout = EditorInputControlLayoutCache.TryGetLayout(expectedControlLayout);

            if (layout == null)
            {
                throw new Exception(string.Format(
                                        "Cannot determine Steam input type for action '{0}'; cannot find layout '{1}'", action,
                                        expectedControlLayout));
            }

            // Map our supported control types.
            var controlType = layout.type;

            if (typeof(ButtonControl).IsAssignableFrom(controlType))
            {
                return("Button");
            }
            if (typeof(InputControl <float>).IsAssignableFrom(controlType))
            {
                return("AnalogTrigger");
            }
            if (typeof(Vector2Control).IsAssignableFrom(controlType))
            {
                return("StickPadGyro");
            }

            // Everything else throws.
            throw new Exception(string.Format(
                                    "Cannot determine Steam input type for action '{0}'; layout '{1}' with control type '{2}' has no known representation in the Steam controller API",
                                    action, expectedControlLayout, controlType.Name));
        }
        protected NameAndParameterListView(SerializedProperty property, Action applyAction, string expectedControlLayout)
        {
            m_DeleteButton = EditorGUIUtility.TrIconContent("Toolbar Minus", $"Delete {itemName}");
            m_UpButton     = EditorGUIUtility.TrIconContent(GUIHelpers.LoadIcon("ChevronUp"), $"Move {itemName} up");
            m_DownButton   = EditorGUIUtility.TrIconContent(GUIHelpers.LoadIcon("ChevronDown"), $"Move {itemName} down");

            m_Property    = property;
            m_Apply       = applyAction;
            m_ListOptions = GetOptions();

            m_ExpectedControlLayout = expectedControlLayout;
            if (!string.IsNullOrEmpty(m_ExpectedControlLayout))
            {
                m_ExpectedValueType = EditorInputControlLayoutCache.GetValueType(m_ExpectedControlLayout);
            }

            m_ParametersForEachListItem         = NameAndParameters.ParseMultiple(m_Property.stringValue).ToArray();
            m_EditableParametersForEachListItem = new ParameterListView[m_ParametersForEachListItem.Length];

            for (var i = 0; i < m_ParametersForEachListItem.Length; i++)
            {
                m_EditableParametersForEachListItem[i] = new ParameterListView {
                    onChange = OnParametersChanged
                };
                var typeName = m_ParametersForEachListItem[i].name;
                var rowType  = m_ListOptions.LookupTypeRegistration(typeName);
                m_EditableParametersForEachListItem[i].Initialize(rowType, m_ParametersForEachListItem[i].parameters);

                var name = ObjectNames.NicifyVariableName(typeName);

                ////REVIEW: finding this kind of stuff should probably have better support globally on the asset; e.g. some
                ////        notification that pops up and allows fixing all occurrences in one click
                // Find out if we still support this option and indicate it in the list, if we don't.
                if (rowType == null)
                {
                    name += " (Obsolete)";
                }
                else if (m_ExpectedValueType != null)
                {
                    var valueType = GetValueType(rowType);
                    if (!m_ExpectedValueType.IsAssignableFrom(valueType))
                    {
                        name += " (Ignored)";
                    }
                }
                m_EditableParametersForEachListItem[i].name = name;
            }
        }
        private static void ConvertInputActionToVDF(InputAction action, StringBuilder builder, Dictionary <string, string> localizationStrings)
        {
            builder.Append("\t\t\t\t\"");
            builder.Append(action.name);

            var mapIdentifier    = CSharpCodeHelpers.MakeIdentifier(action.actionMap.name);
            var actionIdentifier = CSharpCodeHelpers.MakeIdentifier(action.name);
            var titleId          = "Action_" + mapIdentifier + "_" + actionIdentifier;

            localizationStrings[titleId] = action.name;

            // StickPadGyros are objects. Everything else is just strings.
            var inputType = GetSteamControllerInputType(action);

            if (inputType == "StickPadGyro")
            {
                builder.Append("\"\n");
                builder.Append("\t\t\t\t{\n");

                // Title.
                builder.Append("\t\t\t\t\t\"title\"\t\"#");
                builder.Append(titleId);
                builder.Append("\"\n");

                // Decide on "input_mode". Assume "absolute_mouse" by default and take
                // anything built on StickControl as "joystick_move".
                var inputMode   = "absolute_mouse";
                var controlType = EditorInputControlLayoutCache.TryGetLayout(action.expectedControlType).type;
                if (typeof(StickControl).IsAssignableFrom(controlType))
                {
                    inputMode = "joystick_move";
                }
                builder.Append("\t\t\t\t\t\"input_mode\"\t\"");
                builder.Append(inputMode);
                builder.Append("\"\n");

                builder.Append("\t\t\t\t}\n");
            }
            else
            {
                builder.Append("\"\t\"");
                builder.Append(titleId);
                builder.Append("\"\n");
            }
        }
Beispiel #5
0
    public void Editor_CanListDeviceMatchersForLayout()
    {
        const string json = @"
            {
                ""name"" : ""TestLayout""
            }
        ";

        InputSystem.RegisterLayout(json);

        InputSystem.RegisterLayoutMatcher("TestLayout", new InputDeviceMatcher().WithProduct("A"));
        InputSystem.RegisterLayoutMatcher("TestLayout", new InputDeviceMatcher().WithProduct("B"));

        var matchers = EditorInputControlLayoutCache.GetDeviceMatchers("TestLayout").ToList();

        Assert.That(matchers, Has.Count.EqualTo(2));
        Assert.That(matchers[0], Is.EqualTo(new InputDeviceMatcher().WithProduct("A")));
        Assert.That(matchers[1], Is.EqualTo(new InputDeviceMatcher().WithProduct("B")));
    }
Beispiel #6
0
        protected PropertiesReorderableList(SerializedProperty property, Action applyAction, string expectedControlLayout)
        {
            m_Property    = property;
            m_Apply       = applyAction;
            m_ListItems   = new List <string>();
            m_ListOptions = GetOptions();
            m_EditableParametersForSelectedItem = new ParameterListView {
                onChange = OnParametersChanged
            };
            m_ParametersForEachListItem = InputControlLayout.ParseNameAndParameterList(m_Property.stringValue)
                                          ?? new InputControlLayout.NameAndParameters[0];
            m_ExpectedControlLayout = expectedControlLayout;

            foreach (var nameAndParams in m_ParametersForEachListItem)
            {
                var name = ObjectNames.NicifyVariableName(nameAndParams.name);

                ////REVIEW: finding this kind of stuff should probably have better support globally on the asset; e.g. some
                ////        notification that pops up and allows fixing all occurrences in one click
                // Find out if we still support this option and indicate it in the list, if we don't.
                if (m_ListOptions.LookupTypeRegistration(new InternedString(nameAndParams.name)) == null)
                {
                    name += " (Obsolete)";
                }

                m_ListItems.Add(name);
            }

            m_ListView = new ReorderableList(m_ListItems, typeof(string))
            {
                headerHeight          = 3,
                onAddDropdownCallback = (rect, list) =>
                {
                    Type expectedValueType = null;
                    if (!string.IsNullOrEmpty(m_ExpectedControlLayout))
                    {
                        expectedValueType = EditorInputControlLayoutCache.GetValueType(m_ExpectedControlLayout);
                    }

                    // Add only original names to the menu and not aliases.
                    var menu = new GenericMenu();
                    foreach (var name in m_ListOptions.internedNames.Where(x => !m_ListOptions.aliases.Contains(x)).OrderBy(x => x.ToString()))
                    {
                        // Skip if not compatible with value type.
                        if (expectedValueType != null)
                        {
                            var type      = m_ListOptions.LookupTypeRegistration(name);
                            var valueType = GetValueType(type);
                            if (valueType != null && !expectedValueType.IsAssignableFrom(valueType))
                            {
                                continue;
                            }
                        }

                        var niceName = ObjectNames.NicifyVariableName(name);
                        menu.AddItem(new GUIContent(niceName), false, OnAddElement, name.ToString());
                    }
                    menu.ShowAsContext();
                },
                onRemoveCallback = list =>
                {
                    var index = list.index;
                    list.list.RemoveAt(index);
                    ArrayHelpers.EraseAt(ref m_ParametersForEachListItem, index);
                    m_EditableParametersForSelectedItem.Clear();
                    m_Apply();
                    list.index = -1;
                },
                onReorderCallbackWithDetails = (list, oldIndex, newIndex) =>
                {
                    MemoryHelpers.Swap(ref m_ParametersForEachListItem[oldIndex],
                                       ref m_ParametersForEachListItem[newIndex]);
                    OnSelection(list);
                    m_Apply();
                },
                onSelectCallback = OnSelection
            };
        }
 public void Editor_CanGetValueTypeOfLayout()
 {
     Assert.That(EditorInputControlLayoutCache.GetValueType("Axis"), Is.SameAs(typeof(float)));
     Assert.That(EditorInputControlLayoutCache.GetValueType("Button"), Is.SameAs(typeof(float)));
     Assert.That(EditorInputControlLayoutCache.GetValueType("Stick"), Is.SameAs(typeof(Vector2)));
 }