Esempio n. 1
0
        public bool CanCacheInspectorGUI(SerializedProperty property)
        {
            if (m_DecoratorDrawers != null &&
                !isCurrentlyNested &&
                m_DecoratorDrawers.Any(decorator => !decorator.CanCacheInspectorGUI()))
            {
                return(false);
            }

            if (propertyDrawer != null)
            {
                return(propertyDrawer.CanCacheInspectorGUISafe(property.Copy()));
            }

            property = property.Copy();

            bool childrenAreExpanded = property.isExpanded && EditorGUI.HasVisibleChildFields(property);

            // Loop through all child properties
            if (childrenAreExpanded)
            {
                PropertyHandler    handler     = null;
                SerializedProperty endProperty = property.GetEndProperty();
                while (property.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(property, endProperty))
                {
                    if (handler == null)
                    {
                        handler = ScriptAttributeUtility.GetHandler(property);
                    }
                    if (!handler.CanCacheInspectorGUI(property))
                    {
                        return(false);
                    }
                    childrenAreExpanded = false;
                }
            }

            return(true);
        }
        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(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(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);
        }
 internal static PropertyHandler GetHandler(SerializedProperty property)
 {
   if (property == null || property.serializedObject.inspectorMode != InspectorMode.Normal)
     return ScriptAttributeUtility.s_SharedNullHandler;
   PropertyHandler handler1 = ScriptAttributeUtility.propertyHandlerCache.GetHandler(property);
   if (handler1 != null)
     return handler1;
   System.Type type = (System.Type) null;
   List<PropertyAttribute> propertyAttributeList = (List<PropertyAttribute>) null;
   System.Reflection.FieldInfo field = (System.Reflection.FieldInfo) null;
   UnityEngine.Object targetObject = property.serializedObject.targetObject;
   if (targetObject is MonoBehaviour || targetObject is ScriptableObject)
   {
     field = ScriptAttributeUtility.GetFieldInfoFromProperty(property, out type);
     propertyAttributeList = ScriptAttributeUtility.GetFieldAttributes(field);
   }
   else
   {
     if (ScriptAttributeUtility.s_BuiltinAttributes == null)
       ScriptAttributeUtility.PopulateBuiltinAttributes();
     if (propertyAttributeList == null)
       propertyAttributeList = ScriptAttributeUtility.GetBuiltinAttributes(property);
   }
   PropertyHandler handler2 = ScriptAttributeUtility.s_NextHandler;
   if (propertyAttributeList != null)
   {
     for (int index = propertyAttributeList.Count - 1; index >= 0; --index)
       handler2.HandleAttribute(propertyAttributeList[index], field, type);
   }
   if (!handler2.hasPropertyDrawer && type != null)
     handler2.HandleDrawnType(type, type, field, (PropertyAttribute) null);
   if (handler2.empty)
   {
     ScriptAttributeUtility.propertyHandlerCache.SetHandler(property, ScriptAttributeUtility.s_SharedNullHandler);
     handler2 = ScriptAttributeUtility.s_SharedNullHandler;
   }
   else
   {
     ScriptAttributeUtility.propertyHandlerCache.SetHandler(property, handler2);
     ScriptAttributeUtility.s_NextHandler = new PropertyHandler();
   }
   return handler2;
 }
Esempio n. 4
0
        internal void SetHandler(SerializedProperty property, PropertyHandler handler)
        {
            int key = GetPropertyHash(property);

            m_PropertyHandlers[key] = handler;
        }
Esempio n. 5
0
        internal static PropertyHandler GetHandler(SerializedProperty property)
        {
            PropertyHandler result;

            if (property == null)
            {
                result = ScriptAttributeUtility.s_SharedNullHandler;
            }
            else if (property.serializedObject.inspectorMode != InspectorMode.Normal)
            {
                result = ScriptAttributeUtility.s_SharedNullHandler;
            }
            else
            {
                PropertyHandler handler = ScriptAttributeUtility.propertyHandlerCache.GetHandler(property);
                if (handler != null)
                {
                    result = handler;
                }
                else
                {
                    Type type = null;
                    List <PropertyAttribute> list   = null;
                    FieldInfo          field        = null;
                    UnityEngine.Object targetObject = property.serializedObject.targetObject;
                    if (targetObject is MonoBehaviour || targetObject is ScriptableObject)
                    {
                        field = ScriptAttributeUtility.GetFieldInfoFromProperty(property, out type);
                        list  = ScriptAttributeUtility.GetFieldAttributes(field);
                    }
                    else
                    {
                        if (ScriptAttributeUtility.s_BuiltinAttributes == null)
                        {
                            ScriptAttributeUtility.PopulateBuiltinAttributes();
                        }
                        if (list == null)
                        {
                            list = ScriptAttributeUtility.GetBuiltinAttributes(property);
                        }
                    }
                    handler = ScriptAttributeUtility.s_NextHandler;
                    if (list != null)
                    {
                        for (int i = list.Count - 1; i >= 0; i--)
                        {
                            handler.HandleAttribute(list[i], field, type);
                        }
                    }
                    if (!handler.hasPropertyDrawer && type != null)
                    {
                        handler.HandleDrawnType(type, type, field, null);
                    }
                    if (handler.empty)
                    {
                        ScriptAttributeUtility.propertyHandlerCache.SetHandler(property, ScriptAttributeUtility.s_SharedNullHandler);
                        handler = ScriptAttributeUtility.s_SharedNullHandler;
                    }
                    else
                    {
                        ScriptAttributeUtility.propertyHandlerCache.SetHandler(property, handler);
                        ScriptAttributeUtility.s_NextHandler = new PropertyHandler();
                    }
                    result = handler;
                }
            }
            return(result);
        }
Esempio n. 6
0
        internal void SetHandler(SerializedProperty property, PropertyHandler handler)
        {
            int propertyHash = GetPropertyHash(property);

            this.m_PropertyHandlers[propertyHash] = handler;
        }
 internal void SetHandler(SerializedProperty property, PropertyHandler handler)
 {
     int propertyHash = GetPropertyHash(property);
     this.m_PropertyHandlers[propertyHash] = handler;
 }
 internal void SetHandler(SerializedProperty property, PropertyHandler handler)
 {
   this.m_PropertyHandlers[PropertyHandlerCache.GetPropertyHash(property)] = handler;
 }
Esempio n. 9
0
        internal override bool GetOptimizedGUIBlock(bool isDirty, bool isVisible, out float height)
        {
            height = -1;

            // Don't use optimizedGUI for audio filters
            var behaviour = target as MonoBehaviour;

            if (behaviour != null && AudioUtil.HasAudioCallback(behaviour) && AudioUtil.GetCustomFilterChannelCount(behaviour) > 0)
            {
                return(false);
            }

            if (ObjectIsMonoBehaviourOrScriptableObjectWithoutScript(target))
            {
                return(false);
            }

            var scriptableObject = target as ScriptableObject;

            if ((behaviour != null || scriptableObject != null) && SerializationUtility.HasManagedReferencesWithMissingTypes(target))
            {
                return(false);
            }

            if (isDirty)
            {
                ResetOptimizedBlock();
            }

            if (!isVisible)
            {
                height = 0;
                return(true);
            }

            // Return cached result if any.
            if (m_OptimizedBlockState != OptimizedBlockState.CheckOptimizedBlock)
            {
                if (m_OptimizedBlockState == OptimizedBlockState.NoOptimizedBlock)
                {
                    return(false);
                }
                height = m_LastHeight;
                return(true);
            }

            // Update serialized object representation
            if (m_SerializedObject == null)
            {
                m_SerializedObject = new SerializedObject(targets, m_Context)
                {
                    inspectorMode = inspectorMode
                }
            }
            ;
            else
            {
                m_SerializedObject.Update();
                m_SerializedObject.inspectorMode = inspectorMode;
            }

            height = 0;
            SerializedProperty property = m_SerializedObject.GetIterator();
            bool childrenAreExpanded    = true;

            while (property.NextVisible(childrenAreExpanded))
            {
                var handler           = ScriptAttributeUtility.GetHandler(property);
                var hasPropertyDrawer = handler.propertyDrawer != null;
                var propertyHeight    = handler.GetHeight(property, null, hasPropertyDrawer || PropertyHandler.UseReorderabelListControl(property));
                if (propertyHeight > 0)
                {
                    height += propertyHeight + EditorGUI.kControlVerticalSpacing;
                }
                childrenAreExpanded = !hasPropertyDrawer && property.isExpanded && EditorGUI.HasVisibleChildFields(property);
            }

            m_LastHeight          = height;
            m_OptimizedBlockState = OptimizedBlockState.HasOptimizedBlock;

            return(true);
        }
Esempio n. 10
0
        internal override bool OnOptimizedInspectorGUI(Rect contentRect)
        {
            m_SerializedObject.UpdateIfRequiredOrScript();

            bool childrenAreExpanded = true;
            bool wasEnabled          = GUI.enabled;
            var  visibleRect         = GUIClip.visibleRect;
            var  contentOffset       = contentRect.y;

            // In some specific cases (e.g. when the inspector field has a dropdown behavior - case 1335344) we need to
            // apply the padding values so it behaves properly. By checking that xMin is zero when we do the assignments,
            // we avoid applying the padding more than once (because this is called more than once in some cases and
            // can lead to wrong indentation - case 1114055).
            if (contentRect.xMin == 0)
            {
                contentRect.xMin  = EditorStyles.kInspectorPaddingLeft;
                contentRect.xMax -= EditorStyles.kInspectorPaddingRight;
            }

            if (Event.current.type != EventType.Repaint)
            {
                visibleRect = m_LastVisibleRect;
            }

            // Release keyboard focus before scrolling so that the virtual scrolling focus wrong control.
            if (Event.current.type == EventType.ScrollWheel)
            {
                GUIUtility.keyboardControl = 0;
            }

            var  behaviour             = target as MonoBehaviour;
            var  property              = m_SerializedObject.GetIterator();
            bool isInspectorModeNormal = inspectorMode == InspectorMode.Normal;
            bool isInPrefabInstance    = PrefabUtility.GetPrefabInstanceHandle(behaviour) != null;
            bool isMultiSelection      = m_SerializedObject.targetObjectsCount > 1;

            using (new LocalizationGroup(behaviour))
            {
                while (property.NextVisible(childrenAreExpanded))
                {
                    var handler           = ScriptAttributeUtility.GetHandler(property);
                    var hasPropertyDrawer = handler.propertyDrawer != null;
                    childrenAreExpanded = !hasPropertyDrawer && property.isExpanded && EditorGUI.HasVisibleChildFields(property);
                    contentRect.height  = handler.GetHeight(property, null, hasPropertyDrawer || PropertyHandler.UseReorderabelListControl(property));

                    if (contentRect.Overlaps(visibleRect))
                    {
                        EditorGUI.indentLevel = property.depth;
                        using (new EditorGUI.DisabledScope((isInspectorModeNormal || isInPrefabInstance || isMultiSelection) && string.Equals("m_Script", property.propertyPath, System.StringComparison.Ordinal)))
                            childrenAreExpanded &= handler.OnGUI(contentRect, property, GetPropertyLabel(property), PropertyHandler.UseReorderabelListControl(property), visibleRect);
                    }

                    if (contentRect.height > 0)
                    {
                        contentRect.y += contentRect.height + EditorGUI.kControlVerticalSpacing;
                    }
                }
            }

            // Fix new height
            if (Event.current.type == EventType.Repaint)
            {
                m_LastVisibleRect = visibleRect;
                var newHeight = contentRect.y - contentOffset;
                if (newHeight != m_LastHeight)
                {
                    m_LastHeight = contentRect.y - contentOffset;
                    Repaint();
                }
            }

            GUI.enabled = wasEnabled;
            return(m_SerializedObject.ApplyModifiedProperties());
        }
		internal static PropertyHandler GetHandler(SerializedProperty property)
		{
			if (property == null)
			{
				return ScriptAttributeUtility.s_SharedNullHandler;
			}
			if (property.serializedObject.inspectorMode != InspectorMode.Normal)
			{
				return ScriptAttributeUtility.s_SharedNullHandler;
			}
			PropertyHandler handler = ScriptAttributeUtility.propertyHandlerCache.GetHandler(property);
			if (handler != null)
			{
				return handler;
			}
			Type type = null;
			List<PropertyAttribute> list = null;
			FieldInfo field = null;
			UnityEngine.Object targetObject = property.serializedObject.targetObject;
			if (targetObject is MonoBehaviour || targetObject is ScriptableObject)
			{
				field = ScriptAttributeUtility.GetFieldInfoFromProperty(property, out type);
				list = ScriptAttributeUtility.GetFieldAttributes(field);
			}
			else
			{
				if (ScriptAttributeUtility.s_BuiltinAttributes == null)
				{
					ScriptAttributeUtility.PopulateBuiltinAttributes();
				}
				if (list == null)
				{
					list = ScriptAttributeUtility.GetBuiltinAttributes(property);
				}
			}
			handler = ScriptAttributeUtility.s_NextHandler;
			if (list != null)
			{
				for (int i = list.Count - 1; i >= 0; i--)
				{
					handler.HandleAttribute(list[i], field, type);
				}
			}
			if (!handler.hasPropertyDrawer && type != null)
			{
				handler.HandleDrawnType(type, type, field, null);
			}
			if (handler.empty)
			{
				ScriptAttributeUtility.propertyHandlerCache.SetHandler(property, ScriptAttributeUtility.s_SharedNullHandler);
				handler = ScriptAttributeUtility.s_SharedNullHandler;
			}
			else
			{
				ScriptAttributeUtility.propertyHandlerCache.SetHandler(property, handler);
				ScriptAttributeUtility.s_NextHandler = new PropertyHandler();
			}
			return handler;
		}
Esempio n. 12
0
 internal void SetHandler(SerializedProperty property, PropertyHandler handler)
 {
     this.m_PropertyHandlers[PropertyHandlerCache.GetPropertyHash(property)] = handler;
 }