Exemple #1
0
        /// <summary>
        /// Gets the tooltip text for the type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="attributes">The type attributes. Optional, if null type attributes will be used.</param>
        /// <returns>The documentation tooltip.</returns>
        public string GetTooltip(ScriptType type, object[] attributes = null)
        {
            // Try to use cache
            if (_typeCache.TryGetValue(type, out var text))
            {
                return(text);
            }

            // Try to use tooltip attribute
            if (attributes == null)
            {
                attributes = type.GetAttributes(false);
            }
            text = type.TypeName;
            var tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);

            if (tooltip != null)
            {
                text += '\n' + tooltip.Text;
            }
            else if (type.Type != null)
            {
                // Try to use xml docs for managed type
                var xml = GetXmlDocs(type.Type.Assembly);
                if (xml != null)
                {
                    var key = "T:" + GetXmlKey(type.Type.FullName);
                    if (xml.TryGetValue(key, out var xmlDoc))
                    {
                        text += '\n' + xmlDoc;
                    }
                }
            }

            _typeCache.Add(type, text);
            return(text);
        }
        internal static CustomEditor CreateEditor(ScriptType targetType, bool canUseRefPicker = true)
        {
            if (targetType.IsArray)
            {
                return(new ArrayEditor());
            }
            var targetTypeType = TypeUtils.GetType(targetType);

            if (canUseRefPicker)
            {
                if (typeof(Asset).IsAssignableFrom(targetTypeType))
                {
                    return(new AssetRefEditor());
                }
                if (typeof(FlaxEngine.Object).IsAssignableFrom(targetTypeType))
                {
                    return(new FlaxObjectRefEditor());
                }
            }

            // Use custom editor
            {
                var checkType = targetTypeType;
                do
                {
                    var type = Internal_GetCustomEditor(checkType);
                    if (type != null)
                    {
                        return((CustomEditor)Activator.CreateInstance(type));
                    }
                    checkType = checkType.BaseType;

                    // Skip if cannot use ref editors
                    if (!canUseRefPicker && checkType == typeof(FlaxEngine.Object))
                    {
                        break;
                    }
                } while (checkType != null);
            }

            // Use attribute editor
            var attributes            = targetType.GetAttributes(false);
            var customEditorAttribute = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute);

            if (customEditorAttribute != null)
            {
                return((CustomEditor)Activator.CreateInstance(customEditorAttribute.Type));
            }

            // Select default editor (based on type)
            if (targetType.IsEnum)
            {
                return(new EnumEditor());
            }
            if (targetType.IsGenericType)
            {
                if (DictionaryEditor.CanEditType(targetTypeType))
                {
                    return(new DictionaryEditor());
                }

                // Use custom editor
                var genericTypeDefinition = targetType.GetGenericTypeDefinition();
                var type = Internal_GetCustomEditor(genericTypeDefinition);
                if (type != null)
                {
                    return((CustomEditor)Activator.CreateInstance(type));
                }
            }

            // The most generic editor
            return(new GenericEditor());
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TypeItemView"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 public TypeItemView(ScriptType type)
     : this(type, type.GetAttributes(false))
 {
 }