示例#1
0
        // *undocumented*
        private static string GetObjectTypeName(Object o)
        {
            if (o == null)
            {
                return("Nothing Selected");
            }

            if (o is GameObject)
            {
                return(o.name);
            }

            // Show "Tags & Layers" instead of "TagManager"
            if (o is TagManager)
            {
                return("Tags & Layers");
            }

            if (o is Component)
            {
                var behaviour = o as MonoBehaviour;
                if (behaviour)
                {
                    var scriptClassName = behaviour.GetScriptClassName();
                    if (scriptClassName == "InvalidStateMachineBehaviour")
                    {
                        return(behaviour.name + L10n.Tr(" (Script)"));
                    }
                    return(scriptClassName + L10n.Tr(" (Script)"));
                }

                var meshfilter = o as MeshFilter;
                if (meshfilter)
                {
                    var mesh = meshfilter.sharedMesh;
                    return((mesh ? mesh.name : "[none]") + " (MeshFilter)");
                }

                return(o.GetType().Name);
            }

            // Importers don't have names. Just show the type without parenthesis (like we do for components).
            if (o is AssetImporter)
            {
                var monoImporter = o as MonoImporter;
                if (monoImporter)
                {
                    var script = monoImporter.GetScript();
                    return("Default References (" + (script ? script.name : string.Empty) + ")");
                }

                if (NativeClassExtensionUtilities.ExtendsANativeType(o))
                {
                    var script = MonoScript.FromScriptedObject(o);
                    if (script != null)
                    {
                        return(script.GetClass().Name + L10n.Tr(" (Script)"));
                    }
                }

                return(o.GetType().Name);
            }

            return(o.name + " (" + o.GetType().Name + ")");
        }
        internal static PropertyHandler GetHandler(SerializedProperty property)
        {
            if (property == null)
            {
                return(s_SharedNullHandler);
            }

            // Don't use custom drawers in debug mode
            if (property.serializedObject.inspectorMode != InspectorMode.Normal)
            {
                return(s_SharedNullHandler);
            }

            // If the drawer is cached, use the cached drawer
            PropertyHandler handler = propertyHandlerCache.GetHandler(property);

            if (handler != null)
            {
                return(handler);
            }

            Type propertyType = null;
            List <PropertyAttribute> attributes = null;
            FieldInfo field = null;

            // Determine if SerializedObject target is a script or a builtin type
            UnityEngine.Object target = property.serializedObject.targetObject;
            if (NativeClassExtensionUtilities.ExtendsANativeType(target))
            {
                // For scripts, use reflection to get FieldInfo for the member the property represents
                field = GetFieldInfoFromProperty(property, out propertyType);

                // Use reflection to see if this member has an attribute
                attributes = GetFieldAttributes(field);
            }
            else
            {
                // For builtin types, look if we hardcoded an attribute for this property
                // First initialize the hardcoded properties if not already done
                if (s_BuiltinAttributes == null)
                {
                    PopulateBuiltinAttributes();
                }

                if (attributes == null)
                {
                    attributes = GetBuiltinAttributes(property);
                }
            }

            handler = s_NextHandler;

            if (attributes != null)
            {
                for (int i = attributes.Count - 1; i >= 0; i--)
                {
                    handler.HandleAttribute(property, attributes[i], field, propertyType);
                }
            }

            // Field has no CustomPropertyDrawer attribute with matching drawer so look for default drawer for field type
            if (!handler.hasPropertyDrawer && propertyType != null)
            {
                handler.HandleDrawnType(property, propertyType, propertyType, field, null);
            }

            if (handler.empty)
            {
                propertyHandlerCache.SetHandler(property, s_SharedNullHandler);
                handler = s_SharedNullHandler;
            }
            else
            {
                propertyHandlerCache.SetHandler(property, handler);
                s_NextHandler = new PropertyHandler();
            }

            return(handler);
        }