示例#1
0
        /// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary>
        /// <param name="array"> The starting cached value of the drawer. </param>
        /// <param name="memberInfo"> LinkedMemberInfo for the field, property or parameter that the drawer represents. Can be null. </param>
        /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param>
        /// <param name="label"> The prefix label. </param>
        /// <param name="readOnly"> True if control should be read only. </param>
        /// <returns> The instance, ready to be used. </returns>
        public static Array2DDrawer Create(Array array, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label, bool readOnly)
        {
            Array2DDrawer result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new Array2DDrawer();
            }
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(DrawerUtility.GetType(memberInfo, array).GetArrayRank() == 2);
                        #endif
            result.Setup(array, DrawerUtility.GetType(memberInfo, array), memberInfo, parent, label, readOnly);
            result.LateSetup();
            return(result);
        }
示例#2
0
        public static ICollectionDrawer Create(Array value, LinkedMemberInfo memberInfo, [CanBeNull] IParentDrawer parent, GUIContent label, bool readOnly)
        {
            if (value == null)
            {
                                #if DEV_MODE
                Debug.Assert(memberInfo != null, "Array.Create - both value and memberInfo null!");
                                #endif

                value = memberInfo.DefaultValue() as Array;
                if (value == null)
                {
                                        #if DEV_MODE
                    Debug.LogError("Array.Create(" + memberInfo + ") of type " + StringUtils.ToString(memberInfo.Type) + ": value was null and memberInfo.DefaultValue() returned null!");
                                        #endif
                    return(null);
                }

                if (memberInfo.CanWrite)
                {
                    memberInfo.SetValue(value);
                }
            }

            switch (value.Rank)
            {
            case 1:
                break;

            case 2:
                return(Array2DDrawer.Create(value, memberInfo, parent, label, readOnly));

            case 3:
                return(Array3DDrawer.Create(value, memberInfo, parent, label, readOnly));

            default:
                return(null);
            }

            ArrayDrawer result;
            if (!DrawerPool.TryGet(out result))
            {
                result = new ArrayDrawer();
            }
            result.Setup(value, DrawerUtility.GetType(memberInfo, value), memberInfo, parent, label, readOnly);
            result.LateSetup();
            return(result);
        }