Beispiel #1
0
        /// <inheritdoc />
        protected sealed override void Setup(MulticastDelegate setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
            if (setValue == null)
            {
                if (setMemberInfo != null)
                {
                    setValue = setMemberInfo.GetValue(0) as MulticastDelegate;
                }
                else if (setValueType == null)
                {
                                        #if DEV_MODE
                    Debug.LogError("Value and fieldInfo and setDelegateType were all null for DelegateDrawer!");
                                        #endif

                    return;
                }
            }

            UpdateInvocationList(setValue);

            delegateType = setValueType;
            var type = setValueType != null ? setValueType : setMemberInfo != null ? setMemberInfo.Type : setValue.GetType();

                        #if DEV_MODE
            Debug.Assert(typeof(Delegate).IsAssignableFrom(type), type.FullName);
            Debug.Assert(type != typeof(Delegate), type.FullName + " not supported by DelegateDrawer. Should use AnyDelegateDrawer instead.");
            Debug.Assert(type != typeof(MulticastDelegate), type.FullName + " not supported by DelegateDrawer. Should use AnyDelegateDrawer instead.");
                        #endif

            var invokeMethod = type.GetMethod("Invoke");
            if (invokeMethod == null)
            {
                                #if DEV_MODE
                Debug.LogError("DelegateDrawer - Could not find \"Invoke\" method in type " + type.Name + "! memberInfo.Type=" + (setMemberInfo == null ? "n/a" : setMemberInfo.Type.Name));
                                #endif

                parameterInfos = invokeMethod.GetParameters();
            }
            else
            {
                parameterInfos = invokeMethod.GetParameters();
            }

            if (setLabel == null)
            {
                setLabel = GUIContentPool.Create(setMemberInfo == null ? "()=>" : setMemberInfo.Name, GetTooltip(parameterInfos));
            }
            else
            {
                if (setLabel.tooltip.Length == 0)
                {
                    setLabel.tooltip = GetTooltip(parameterInfos);
                }
            }

            base.Setup(setValue, setValueType, setMemberInfo, setParent, setLabel, setReadOnly);
        }
Beispiel #2
0
 /// <inheritdoc />
 public override void SetupInterface(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
 {
     if (setValue == null)
     {
         if (setMemberInfo != null && setMemberInfo.CanRead)
         {
             Setup((bool)setMemberInfo.GetValue(0), setValueType, setMemberInfo, setParent, setLabel, setReadOnly);
         }
         else
         {
                                 #if DEV_MODE
             Debug.LogWarning(ToString(setLabel, setMemberInfo) + " SetupInterface called with null value and null or ReadOnly memberInfo: " + StringUtils.ToString(setMemberInfo));
                                 #endif
             Setup(false, setValueType, setMemberInfo, setParent, setLabel, setReadOnly);
         }
     }
     else
     {
         Setup((bool)setValue, setValueType, setMemberInfo, setParent, setLabel, setReadOnly);
     }
 }
Beispiel #3
0
        public static PropertyDrawer Create([NotNull] LinkedMemberInfo memberInfo, [CanBeNull] IParentDrawer parent, [CanBeNull] GUIContent label, bool readOnly)
        {
            PropertyDrawer result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new PropertyDrawer();
            }

            object useValue;

                        #if GET_VALUE_DURING_SETUP
            // call the getter of a property here, even though it could have side effects?
            // UPDATE: This results in errors if the property has index parameters!
            if (memberInfo.CanRead && (memberInfo.MemberInfo as PropertyInfo).GetIndexParameters().Length == 0)
            {
                try
                {
                    useValue = memberInfo.GetValue(0);
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                    useValue = memberInfo.DefaultValue();
                }
            }
            else
                        #endif
            {
                useValue = memberInfo.DefaultValue();
            }

            result.Setup(useValue, memberInfo.Type, memberInfo, parent, label, readOnly);
            result.LateSetup();
            return(result);
        }
 public IDrawer GetForField(LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label = null, bool readOnly = false)
 {
     return(GetForField(memberInfo.GetValue(0), memberInfo.Type, memberInfo, parent, label, readOnly));
 }