Exemplo n.º 1
0
 public override void Initialize(MemberInfo member, Type memberValueType)
 {
     if (this.Attribute.ErrorMessage != null)
     {
         this.stringHelper = new StringMemberHelper(member.ReflectedType, false, this.Attribute.ErrorMessage);
     }
 }
        //private bool exists;

        /// <summary>
        /// Initializes the drawer.
        /// </summary>
        protected override void Initialize()
        {
//#pragma warning disable CS0618 // Type or member is obsolete
//            this.requireExistingPath = this.Attribute.RequireExistingPath || this.Attribute.RequireValidPath;
//#pragma warning restore CS0618 // Type or member is obsolete

            this.parentProperty = this.Property.FindParent(p => p.Info.HasSingleBackingMember, true);
            this.parentPath     = new StringMemberHelper(this.parentProperty, this.Attribute.ParentFolder);
            //this.exists = this.PathExists(this.ValueEntry.SmartValue, this.parentPath.GetString(this.Property));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        protected override void Initialize()
        {
            this.expanded             = false;
            this.buttonAttribute      = this.Property.GetAttribute <ButtonAttribute>();
            this.buttonHeight         = this.Property.Context.GetGlobal("ButtonHeight", 0).Value;
            this.style                = this.Property.Context.GetGlobal("ButtonStyle", (GUIStyle)null).Value;
            this.toggle               = this.GetPersistentValue <bool>("toggle", false);
            this.hasGUIColorAttribute = this.Property.GetAttribute <GUIColorAttribute>() != null;
            this.drawParameters       = this.Property.Children.Count > 0 && !DontDrawMethodParamaters;
            this.name  = this.Property.NiceName;
            this.label = new GUIContent(name);

            if (buttonAttribute != null)
            {
                this.btnStyle = this.buttonAttribute.Style;
                this.expanded = buttonAttribute.Expanded;

                if (!string.IsNullOrEmpty(this.buttonAttribute.Name))
                {
                    this.mh = new StringMemberHelper(this.Property, this.buttonAttribute.Name);
                }

                if (this.buttonHeight == 0 && buttonAttribute.ButtonHeight > 0)
                {
                    this.buttonHeight = buttonAttribute.ButtonHeight;
                }
            }

            if (this.style == null)
            {
                if (this.buttonHeight > 20)
                {
                    this.style = SirenixGUIStyles.Button;
                }
                else
                {
                    this.style = EditorStyles.miniButton;
                }
            }

            if (this.drawParameters && this.btnStyle == ButtonStyle.FoldoutButton && !this.expanded)
            {
                if (this.buttonHeight > 20)
                {
                    this.style          = SirenixGUIStyles.ButtonLeft;
                    this.toggleBtnStyle = SirenixGUIStyles.ButtonRight;
                }
                else
                {
                    this.style          = EditorStyles.miniButtonLeft;
                    this.toggleBtnStyle = EditorStyles.miniButtonRight;
                }
            }
        }
Exemplo n.º 4
0
        public override void Initialize(MemberInfo member, Type memberValueType)
        {
            if (this.Attribute.MemberName != null && this.Attribute.MemberName.Length > 0 && this.Attribute.MemberName[0] == '@')
            {
                var expression = this.Attribute.MemberName.Substring(1);

                var emitContext = new EmitContext()
                {
                    IsStatic       = member.IsStatic(),
                    ReturnType     = typeof(bool),
                    Type           = member.ReflectedType,
                    Parameters     = new Type[] { member.GetReturnType() },
                    ParameterNames = new string[] { "value" }
                };

                var del = ExpressionUtility.ParseExpression(expression, emitContext, out this.memberErrorMessage);

                if (emitContext.IsStatic)
                {
                    this.staticValidationExpression = (ExpressionFunc <T, bool>)del;
                }
                else
                {
                    this.instanceValidationExpression = del;
                }
            }
            else
            {
                LegacyFindMember(member);
            }

            this.defaultMessageString = this.Attribute.DefaultMessage ?? "Value is invalid for member '" + member.Name + "'";
            this.defaultResultType    = this.Attribute.MessageType.ToValidationResultType();

            if (this.Attribute.DefaultMessage != null)
            {
                this.validationMessageHelper = new StringMemberHelper(member.ReflectedType, false, this.Attribute.DefaultMessage);

                if (this.validationMessageHelper.ErrorMessage != null)
                {
                    if (this.memberErrorMessage != null)
                    {
                        this.memberErrorMessage += "\n\n" + this.validationMessageHelper.ErrorMessage;
                    }
                    else
                    {
                        this.memberErrorMessage = this.validationMessageHelper.ErrorMessage;
                    }

                    this.validationMessageHelper = null;
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes the drawer.
        /// </summary>
        protected override void Initialize()
        {
            this.PaletteIndex = 0;
            this.CurrentName  = this.Attribute.PaletteName;
            this.ShowAlpha    = this.Attribute.ShowAlpha;
            this.Names        = ColorPaletteManager.Instance.ColorPalettes.Select(x => x.Name).ToArray();

            if (this.Attribute.PaletteName == null)
            {
                this.PersistentName = this.ValueEntry.Context.GetPersistent <string>(this, "ColorPaletteName", null);
                var list = this.Names.ToList();
                this.CurrentName = this.PersistentName.Value;

                if (this.CurrentName != null && list.Contains(this.CurrentName))
                {
                    this.PaletteIndex = list.IndexOf(this.CurrentName);
                }
            }
            else
            {
                this.NameGetter = new StringMemberHelper(this.Property, this.Attribute.PaletteName);
            }
        }
 protected override void Initialize()
 {
     this.stringMemberHelper = new StringMemberHelper(this.Property, this.Attribute.Name);
 }
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        protected override void Initialize()
        {
            this.hideDetailedMessage = true;
            this.messageHelper       = new StringMemberHelper(this.Property, this.Attribute.Message);
            this.detailsHelper       = new StringMemberHelper(this.Property, this.Attribute.Details);
            this.errorMessage        = this.messageHelper.ErrorMessage ?? this.detailsHelper.ErrorMessage;

            if (this.Attribute.VisibleIf != null)
            {
                MemberInfo memberInfo;

                // Parameter functions
                if (this.Property.ValueEntry != null && this.Property.ParentType.FindMember()
                    .IsMethod()
                    .HasReturnType <bool>()
                    .HasParameters(this.Property.ValueEntry.BaseValueType)
                    .IsNamed(this.Attribute.VisibleIf)
                    .TryGetMember(out memberInfo, out this.errorMessage))
                {
                    if (this.errorMessage == null)
                    {
                        if (memberInfo is MethodInfo)
                        {
                            var method = memberInfo as MethodInfo;

                            if (memberInfo.IsStatic())
                            {
                                // TODO: Emit dis.
                                this.staticValidationParameterMethodCaller = p => (bool)method.Invoke(null, new object[] { p });
                            }
                            else
                            {
                                // TODO: Emit dis.
                                this.instanceValidationParameterMethodCaller = (i, p) => (bool)method.Invoke(i, new object[] { p });
                            }
                        }
                        else
                        {
                            this.errorMessage = "Invalid member type!";
                        }
                    }
                }

                // Fields, properties, and no-parameter functions.
                else if (this.Property.ParentType.FindMember()
                         .HasReturnType <bool>()
                         .HasNoParameters()
                         .IsNamed(this.Attribute.VisibleIf)
                         .TryGetMember(out memberInfo, out this.errorMessage))
                {
                    if (this.errorMessage == null)
                    {
                        if (memberInfo is FieldInfo)
                        {
                            if (memberInfo.IsStatic())
                            {
                                this.staticValidationCaller = EmitUtilities.CreateStaticFieldGetter <bool>(memberInfo as FieldInfo);
                            }
                            else
                            {
                                this.instanceValueGetter = EmitUtilities.CreateWeakInstanceFieldGetter(this.Property.ParentType, memberInfo as FieldInfo);
                            }
                        }
                        else if (memberInfo is PropertyInfo)
                        {
                            if (memberInfo.IsStatic())
                            {
                                this.staticValidationCaller = EmitUtilities.CreateStaticPropertyGetter <bool>(memberInfo as PropertyInfo);
                            }
                            else
                            {
                                this.instanceValueGetter = EmitUtilities.CreateWeakInstancePropertyGetter(this.Property.ParentType, memberInfo as PropertyInfo);
                            }
                        }
                        else if (memberInfo is MethodInfo)
                        {
                            if (memberInfo.IsStatic())
                            {
                                this.staticValidationCaller = (Func <bool>)Delegate.CreateDelegate(typeof(Func <bool>), memberInfo as MethodInfo);
                            }
                            else
                            {
                                this.instanceValidationMethodCaller = EmitUtilities.CreateWeakInstanceMethodCallerFunc <bool>(memberInfo as MethodInfo);
                            }
                        }
                        else
                        {
                            this.errorMessage = "Invalid member type!";
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 protected override void Initialize()
 {
     this.labelGetter = new StringMemberHelper(this.Property, this.Attribute.GroupName);
 }
 protected override void Initialize()
 {
     this.labelHelper = new StringMemberHelper(this.Property.FindParent(p => p.Info.HasSingleBackingMember, true), this.Attribute.Label);
 }
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 protected override void Initialize()
 {
     IsVisible        = this.GetPersistentValue("IsVisible", this.Attribute.HasDefinedExpanded ? this.Attribute.Expanded : SirenixEditorGUI.ExpandFoldoutByDefault);
     this.TitleHelper = new StringMemberHelper(this.Property, this.Attribute.GroupName);
     this.t           = this.IsVisible.Value ? 1 : 0;
 }