public override string ToString()
        {
            if (type.value == null)
            {
                return(k_InvalidSlotString);
            }

            if (tagIndex == -1)
            {
                return(type.name);
            }

            List <string> tags = InputDeviceUtility.GetDeviceTags(type);

            return(string.Format("{0}.{1}", type.name, tags[tagIndex]));
        }
        public void OnGUI(Rect rect, GUIContent label, Type baseType = null, SerializedProperty prop = null)
        {
            if (prop != null)
            {
                label = EditorGUI.BeginProperty(rect, label, prop);
            }

            if (baseType == null)
            {
                baseType = typeof(InputDevice);
            }

            List <string> tagNames   = null;
            Vector2       tagMaxSize = Vector2.zero;

            if (type.value != null)
            {
                tagNames = InputDeviceUtility.GetDeviceTags(type.value);
                if (tagNames != null)
                {
                    GUIContent content = new GUIContent();
                    for (var j = 0; j < tagNames.Count; j++)
                    {
                        content.text = tagNames[j];
                        Vector2 size = EditorStyles.popup.CalcSize(content);
                        tagMaxSize = Vector2.Max(size, tagMaxSize);
                    }
                }
            }

            rect.width -= tagMaxSize.x; // Adjust width to leave room for tag
            EditorGUI.BeginChangeCheck();
            Type t = TypeGUI.TypeField(rect, label, baseType, type);

            if (EditorGUI.EndChangeCheck())
            {
                if (prop != null)
                {
                    Undo.RecordObjects(prop.serializedObject.targetObjects, "Input Device");
                }

                type = t;

                if (prop != null)
                {
                    // Flushing seems necessaary to have prefab property override status change without lag.
                    Undo.FlushUndoRecordObjects();
                    prop.serializedObject.SetIsDifferentCacheDirty();
                }
            }
            if (tagNames != null)
            {
                int oldIndent = EditorGUI.indentLevel;
                EditorGUI.indentLevel = 0;

                EditorGUI.BeginChangeCheck();
                // We want to have the ability to unset a tag after specifying one, so add an "Any" option
                var popupTags = new string[tagNames.Count + 1];
                popupTags[0] = "Any";
                tagNames.CopyTo(popupTags, 1);
                int newTagIndex = tagIndex + 1;
                rect.x     += rect.width;
                rect.width  = tagMaxSize.x;
                newTagIndex = EditorGUI.Popup(
                    rect,
                    newTagIndex,
                    popupTags);
                if (EditorGUI.EndChangeCheck())
                {
                    if (prop != null)
                    {
                        Undo.RecordObjects(prop.serializedObject.targetObjects, "Control");
                    }

                    tagIndex = newTagIndex - 1;

                    if (prop != null)
                    {
                        // Flushing seems necessaary to have prefab property override status change without lag.
                        Undo.FlushUndoRecordObjects();
                        prop.serializedObject.SetIsDifferentCacheDirty();
                    }
                }

                EditorGUI.indentLevel = oldIndent;
            }
            else
            {
                // if we're no longer showing tags, reset the tag field so that we can still search on the current
                // tag selection of the device slot.
                tagIndex = -1;
            }

            if (prop != null)
            {
                EditorGUI.EndProperty();
            }
        }
Exemple #3
0
        public List <DomainEntry> GetControlEntriesOfType(int domainId, Type controlType)
        {
            DeviceSlot slot = GetDeviceSlot(domainId);

            return(InputDeviceUtility.GetDeviceControlEntriesOfType(slot == null ? null : slot.type, controlType));
        }