/// <summary>
        ///
        /// </summary>
        /// <param name="type">Initializes a new instance of the <see cref="SystemTypeAttribute"/> class.</param>
        /// <param name="grouping">Gets or sets grouping of selectable classes. Defaults to <see cref="TypeGrouping.ByNamespaceFlat"/> unless explicitly specified.</param>
        public SystemTypeAttribute(Type type, TypeGrouping grouping = TypeGrouping.ByNamespaceFlat)
        {
            bool isValid = type.IsClass || type.IsInterface || type.IsValueType && !type.IsEnum;

            Debug.Assert(isValid, $"Invalid Type {type} in attribute.");
            Grouping = grouping;
        }
Exemple #2
0
        private static string FormatGroupedTypeName(Type type, TypeGrouping grouping)
        {
            var name = type.FullName;

            switch (grouping)
            {
            default:
            case TypeGrouping.None:
                return(name);

            case TypeGrouping.ByNamespace:
                return(name.Replace('.', '/'));

            case TypeGrouping.ByNamespaceFlat:
                var lastPeriodIndex = name.LastIndexOf('.');
                if (lastPeriodIndex != -1)
                {
                    name = name.Substring(0, lastPeriodIndex) + "/" + name.Substring(lastPeriodIndex + 1);
                }

                return(name);

            case TypeGrouping.ByAddComponentMenu:
                var addComponentMenuAttributes = type.GetCustomAttributes(typeof(AddComponentMenu), false);
                if (addComponentMenuAttributes.Length == 1)
                {
                    return(((AddComponentMenu)addComponentMenuAttributes[0]).componentMenu);
                }

                return("Scripts/" + type.FullName.Replace('.', '/'));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="type">Initializes a new instance of the <see cref="SystemTypeAttribute"/> class.</param>
        /// <param name="grouping">Gets or sets grouping of selectable classes. Defaults to <see cref="Utilities.TypeGrouping.ByNamespaceFlat"/> unless explicitly specified.</param>
        public SystemTypeAttribute(Type type, TypeGrouping grouping = TypeGrouping.ByNamespaceFlat)
        {
#if WINDOWS_UWP && !ENABLE_IL2CPP
            bool isValid = type.IsClass() || type.IsInterface() || type.IsValueType() && !type.IsEnum();
#else
            bool isValid = type.IsClass || type.IsInterface || type.IsValueType && !type.IsEnum;
#endif // WINDOWS_UWP && !ENABLE_IL2CPP
            Debug.Assert(isValid, $"Invalid Type {type} in attribute.");
            Grouping = grouping;
        }
        public override int GetHashCode()
        {
            var hashCode = -8527728;

            hashCode = hashCode * -1521134295 + EqualityComparer <TypeConstraintContext> .Default.GetHashCode(Constraint);

            hashCode = hashCode * -1521134295 + TypeGrouping.GetHashCode();
            hashCode = hashCode * -1521134295 + AddEmptyValue.GetHashCode();
            return(hashCode);
        }
        private static string FormatGroupedTypeName(Type type, TypeGrouping grouping)
        {
            var name = type.FullName;

            switch (grouping)
            {
            case TypeGrouping.None:
                return(name);

            case TypeGrouping.NoneByNameNoNamespace:
                return(type.Name);

            case TypeGrouping.ByNamespace:
                return(string.IsNullOrEmpty(name) ? string.Empty : name.Replace('.', '/'));

            case TypeGrouping.ByNamespaceFlat:
                int lastPeriodIndex = string.IsNullOrEmpty(name) ? -1 : name.LastIndexOf('.');
                if (lastPeriodIndex != -1)
                {
                    name = string.IsNullOrEmpty(name)
                            ? string.Empty
                            : $"{name.Substring(0, lastPeriodIndex)}/{name.Substring(lastPeriodIndex + 1)}";
                }

                return(name);

            case TypeGrouping.ByAddComponentMenu:
                var addComponentMenuAttributes = type.GetCustomAttributes(typeof(AddComponentMenu), false);
                if (addComponentMenuAttributes.Length == 1)
                {
                    return(((AddComponentMenu)addComponentMenuAttributes[0]).componentMenu);
                }

                Debug.Assert(type.FullName != null);
                return($"Scripts/{type.FullName?.Replace('.', '/')}");

            default:
                throw new ArgumentOutOfRangeException(nameof(grouping), grouping, null);
            }
        }
Exemple #6
0
        private void CreateLabels(TypeGrouping grouping)
        {
            var count = Values.Count;
            var shift = 0;

            if (hasEmptyValue)
            {
                shift    += 1;
                count    += 1;
                labels    = new string[count];
                labels[0] = "<none>";
            }
            else
            {
                labels = new string[count];
            }

            for (var i = 0; i < count - shift; i++)
            {
                var type = Values[i];
                var name = FormatGroupedTypeName(type, grouping);
                labels[i + shift] = name;
            }
        }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImplementsAttribute"/> class.
 /// </summary>
 /// <param name="interfaceType">Type of interface that selectable classes must implement.</param>
 /// <param name="grouping">Gets or sets grouping of selectable classes. Defaults to <see cref="TypeGrouping.ByNamespaceFlat"/> unless explicitly specified.</param>
 public ImplementsAttribute(Type interfaceType, TypeGrouping grouping)
     : base(interfaceType, grouping)
 {
     InterfaceType = interfaceType;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExtendsAttribute"/> class.
 /// </summary>
 /// <param name="baseType">Type of class that selectable classes must derive from.</param>
 /// <param name="grouping">Gets or sets grouping of selectable classes. Defaults to <see cref="Utilities.TypeGrouping.ByNamespaceFlat"/> unless explicitly specified.</param>
 public ExtendsAttribute(Type baseType, TypeGrouping grouping) : base(baseType, grouping)
 {
     BaseType = baseType;
 }
        private static void DisplayDropDown(Rect position, List <Type> types, Type selectedType, TypeGrouping grouping)
        {
            var menu = new GenericMenu();

            menu.AddItem(new GUIContent("(None)"), selectedType == null, OnSelectedTypeName, null);
            menu.AddSeparator(string.Empty);

            for (int i = 0; i < types.Count; ++i)
            {
                string menuLabel = FormatGroupedTypeName(types[i], grouping);

                if (string.IsNullOrEmpty(menuLabel))
                {
                    continue;
                }

                var content = new GUIContent(menuLabel);
                menu.AddItem(content, types[i] == selectedType, OnSelectedTypeName, types[i]);
            }

            menu.DropDown(position);
        }
Exemple #10
0
        public static void DisplayDropDown(Rect position, IEnumerable <Type> types, Type selectedType, TypeGrouping grouping)
        {
            var menu = new GenericMenu();

            menu.AddItem(new GUIContent(None), selectedType == null, OnSelectedTypeName, null);
            menu.AddSeparator(string.Empty);

            foreach (var type in types)
            {
                var menuLabel = FormatGroupedTypeName(type, grouping);

                if (string.IsNullOrEmpty(menuLabel))
                {
                    continue;
                }

                var content = new GUIContent(menuLabel);
                menu.AddItem(content, type == selectedType, OnSelectedTypeName, type);
            }

            menu.DropDown(position);

            void OnSelectedTypeName(object typeRef)
            {
                SelectedType      = typeRef as Type;
                SelectedReference = SystemType.GetReference(SelectedType);
                EditorWindow.focusedWindow.SendEvent(EditorGUIUtility.CommandEvent(TypeReferenceUpdated));
            }
        }
        private void DrawResult()
        {
            EditorGUILayout.BeginVertical("Box");
            EditorGUILayout.LabelField("Below you can see which types are referenced by which AIs, and which are not referenced at all.", SharedStyles.BuiltIn.wrappedText);
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            if (GUILayout.Button("Expand All", EditorStyles.toolbarButton))
            {
                _referencedTypes.Apply(s => s.expanded  = true);
                _referencingAIs.Apply(ai => ai.expanded = true);
            }

            if (GUILayout.Button("Collapse All", EditorStyles.toolbarButton))
            {
                _referencedTypes.Apply(s => s.expanded  = false);
                _referencingAIs.Apply(ai => ai.expanded = false);
            }

            if (GUILayout.Button("Copy", EditorStyles.toolbarButton))
            {
                EditorGUIUtility.systemCopyBuffer = Export();
            }

            GUILayout.FlexibleSpace();

            EditorGUILayout.LabelField("Group by", GUILayout.Width(60f));
            _grouping = (TypeGrouping)GUILayout.SelectionGrid((int)_grouping, _groupingTabTitles, 3, EditorStyles.toolbarButton);
            EditorGUILayout.EndHorizontal();

            if (_grouping == TypeGrouping.ReferencedType)
            {
                _typesScrollPos = EditorGUILayout.BeginScrollView(_typesScrollPos, "Box");
                EditorGUILayout.LabelField("Referenced Types", SharedStyles.BuiltIn.centeredWrappedText);
                foreach (var t in _referencedTypes)
                {
                    DrawTypeListItem(t);
                }

                EditorGUILayout.EndScrollView();
            }
            else if (_grouping == TypeGrouping.UnreferencedType)
            {
                _typesScrollPos = EditorGUILayout.BeginScrollView(_typesScrollPos, "Box");
                EditorGUILayout.LabelField("Unreferenced Types", SharedStyles.BuiltIn.centeredWrappedText);
                foreach (var t in _unreferencedTypes)
                {
                    DrawTypeListItem(t);
                }

                EditorGUILayout.EndScrollView();
            }
            else
            {
                _aiScrollPos = EditorGUILayout.BeginScrollView(_aiScrollPos, "Box");
                EditorGUILayout.LabelField("AIs", SharedStyles.BuiltIn.centeredWrappedText);
                foreach (var ai in _referencingAIs)
                {
                    DrawAIListItem(ai);
                }

                EditorGUILayout.EndScrollView();
            }

            if (GUILayout.Button("Back"))
            {
                _aiScrollPos = _typesScrollPos = Vector2.zero;
                _step        = Step.Start;
            }
        }
Exemple #12
0
 public TypesEditorCollection(TypesCachedCollection cachedCollection, bool hasEmptyValue, TypeGrouping grouping)
     : base(cachedCollection)
 {
     this.hasEmptyValue = hasEmptyValue;
     CreateLabels(grouping);
 }
        /// <summary>
        /// Displays the type picker dropdown.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="types"></param>
        /// <param name="selectedType"></param>
        /// <param name="grouping"></param>
        /// <param name="newType"></param>
        public static void DisplayDropDown(Rect position, IEnumerable <Type> types, Type selectedType, TypeGrouping grouping, Type newType = null)
        {
            var menu = new GenericMenu();

            menu.AddItem(new GUIContent(NONE), selectedType == null, OnSelectedTypeName, null);
            menu.AddSeparator(string.Empty);

            foreach (var type in types)
            {
                var menuLabel = FormatGroupedTypeName(type, grouping);

                if (string.IsNullOrEmpty(menuLabel))
                {
                    continue;
                }

                var content = new GUIContent(menuLabel);
                menu.AddItem(content, type == selectedType, OnSelectedTypeName, type);
            }

            if (newType != null)
            {
                menu.AddSeparator(string.Empty);
                menu.AddItem(new GUIContent($"Create new {newType.Name}..."), false, data =>
                {
                    MixedRealityServiceWizard.ShowNewServiceWizard(newType);
                    CreateNewTypeOverride = null;
                }, null);
            }

            menu.DropDown(position);

            void OnSelectedTypeName(object typeRef)
            {
                SelectedType = typeRef as Type;
                EditorWindow.focusedWindow.SendEvent(EditorGUIUtility.CommandEvent(TypeReferenceUpdated));
            }
        }
 public TypeAppearanceContext(TypeConstraintContext constraint, TypeGrouping typeGrouping, bool addEmptyValue)
 {
     Constraint    = constraint;
     TypeGrouping  = typeGrouping;
     AddEmptyValue = addEmptyValue;
 }