//#######################
        // GetHandler

        public static IPropertyHandler GetHandler(SerializedProperty property)
        {
            if (property == null)
            {
                throw new System.ArgumentNullException("property");
            }

            IPropertyHandler result = _handlerCache.GetHandler(property);

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

            //TEST FOR SPECIAL CASE HANDLER
            var fieldInfo = ScriptAttributeUtility.GetFieldInfoFromProperty(property);

            if (fieldInfo != null && System.Attribute.IsDefined(fieldInfo, typeof(PropertyAttribute)))
            {
                var attribs = fieldInfo.GetCustomAttributes(typeof(PropertyAttribute), false) as PropertyAttribute[];
                //if (attribs.Length > 1)
                //{
                //    if (attribs.Any((a) => a is SPPropertyAttribute))
                //    {
                //        result = new MultiPropertyAttributePropertyHandler(fieldInfo, attribs);
                //        _handlerCache.SetHandler(property, result);
                //        return result;
                //    }
                //}
                //else if (attribs[0] is SPPropertyAttribute)
                //{
                //    result = new SPPropertyAttributePropertyHandler(fieldInfo, attribs[0] as SPPropertyAttribute);
                //    _handlerCache.SetHandler(property, result);
                //    return result;
                //}

                if (attribs.Any((a) => a is SPPropertyAttribute))
                {
                    result = new MultiPropertyAttributePropertyHandler(fieldInfo, attribs);
                    _handlerCache.SetHandler(property, result);
                    return(result);
                }
            }

            //USE STANDARD HANDLER if none was found
            var handler = StandardPropertyHandler.Instance;

            _handlerCache.SetHandler(property, handler);
            return(handler);
        }
Exemplo n.º 2
0
        private PropertyDrawer GetDrawer(SerializedProperty property)
        {
            if (property.propertyType == SerializedPropertyType.Generic || property.propertyType == SerializedPropertyType.ObjectReference)
            {
                var fieldInfo = ScriptAttributeUtility.GetFieldInfoFromProperty(property);
                if (fieldInfo == null)
                {
                    return(null);
                }

                var tp = fieldInfo.FieldType;
                if (tp.IsListType())
                {
                    tp = tp.GetElementTypeOfListType();
                }

                PropertyDrawer drawer = null;
                if (_fieldTypeToDrawer.TryGetValue(tp, out drawer))
                {
                    if (drawer != null)
                    {
                        PropertyDrawerActivator.InitializePropertyDrawer(drawer, null, fieldInfo);
                    }
                    return(drawer);
                }

                var drawerType = ScriptAttributeUtility.GetDrawerTypeForType(tp);
                if (drawerType == null)
                {
                    _fieldTypeToDrawer[tp] = null;
                    return(null);
                }

                drawer = PropertyDrawerActivator.Create(drawerType, null, fieldInfo);
                _fieldTypeToDrawer[tp] = drawer;
                return(drawer);
            }

            return(null);
        }
        private PropertyDrawer GetDrawer(SerializedProperty property)
        {
            if (property.propertyType == SerializedPropertyType.Generic || property.propertyType == SerializedPropertyType.ObjectReference)
            {
                var fieldInfo = ScriptAttributeUtility.GetFieldInfoFromProperty(property);
                if (fieldInfo == null)
                {
                    return(null);
                }

                var tp = fieldInfo.FieldType;
                if (tp.IsListType())
                {
                    tp = tp.GetElementTypeOfListType();
                }
                if (_fieldTypeToDrawer.ContainsKey(tp))
                {
                    var result = _fieldTypeToDrawer[tp];
                    if (result != null)
                    {
                        PropertyDrawerActivator.InitializePropertyDrawer(result, null, fieldInfo);
                    }
                    return(result);
                }

                var drawerType = ScriptAttributeUtility.GetDrawerTypeForType(tp);
                if (drawerType == null)
                {
                    _fieldTypeToDrawer.Add(tp, null);
                    return(null);
                }

                var drawer = PropertyDrawerActivator.Create(drawerType, null, fieldInfo);
                _fieldTypeToDrawer.Add(tp, drawer);
                return(drawer);
            }

            return(null);
        }