Esempio n. 1
0
    protected Rect Initialize(Rect position, GUIContent label)
    {
        noFieldLabel  = ((CustomAttributeBase)attribute).NoFieldLabel;
        noPrefixLabel = ((CustomAttributeBase)attribute).NoPrefixLabel;
        noIndex       = ((CustomAttributeBase)attribute).NoIndex;
        prefixLabel   = ((CustomAttributeBase)attribute).PrefixLabel;

        if (fieldInfo.FieldType.IsArray)
        {
            index = AttributeUtility.GetIndexFromLabel(label);
            if (!noIndex && !string.IsNullOrEmpty(prefixLabel))
            {
                prefixLabel += " " + index;
            }
            else if (noIndex && string.IsNullOrEmpty(prefixLabel))
            {
                prefixLabel = "Element";
            }
        }

        if (!noPrefixLabel)
        {
            if (!string.IsNullOrEmpty(prefixLabel))
            {
                position = EditorGUI.PrefixLabel(position, new GUIContent(prefixLabel));
            }
            else
            {
                position = EditorGUI.PrefixLabel(position, label);
            }
            EditorGUI.indentLevel = 0;
        }
        return(position);
    }
    protected Rect Begin(Rect position, SerializedProperty property, GUIContent label)
    {
        noFieldLabel       = ((CustomAttributeBase)attribute).NoFieldLabel;
        noPrefixLabel      = ((CustomAttributeBase)attribute).NoPrefixLabel;
        noIndex            = ((CustomAttributeBase)attribute).NoIndex;
        prefixLabel        = ((CustomAttributeBase)attribute).PrefixLabel;
        scrollbarThreshold = Screen.width - position.width > 19 ? 298 : 313;
        indentLevel        = EditorGUI.indentLevel;

        EditorGUI.BeginChangeCheck();

        if (fieldInfo.FieldType.IsArray)
        {
            index         = AttributeUtility.GetIndexFromLabel(label);
            arrayProperty = property.serializedObject.FindProperty(fieldInfo.Name);

            if (noIndex)
            {
                if (string.IsNullOrEmpty(prefixLabel))
                {
                    label.text = label.text.Substring(0, label.text.Length - 2);
                }
            }
            else if (!string.IsNullOrEmpty(prefixLabel))
            {
                prefixLabel += " " + index;
            }
        }


        if (drawPrefixLabel)
        {
            if (!noPrefixLabel)
            {
                if (!string.IsNullOrEmpty(prefixLabel))
                {
                    label.text = prefixLabel;
                }
                position = EditorGUI.PrefixLabel(position, label);
            }
        }
        else
        {
            if (noPrefixLabel)
            {
                label.text = "";
            }
            else if
            (!string.IsNullOrEmpty(prefixLabel))
            {
                label.text = prefixLabel;
            }
        }
        currentPosition = position;
        currentLabel    = label;
        return(position);
    }
        public override void Begin(Rect position, SerializedProperty property, GUIContent label)
        {
            base.Begin(position, property, label);

            noFieldLabel  = ((CustomAttributeBase)attribute).NoFieldLabel;
            noPrefixLabel = ((CustomAttributeBase)attribute).NoPrefixLabel;
            noIndex       = ((CustomAttributeBase)attribute).NoIndex;
            prefixLabel   = ((CustomAttributeBase)attribute).PrefixLabel;
            disableOnPlay = ((CustomAttributeBase)attribute).DisableOnPlay;
            disableOnStop = ((CustomAttributeBase)attribute).DisableOnStop;
            disableBool   = ((CustomAttributeBase)attribute).DisableBool;
            indent        = ((CustomAttributeBase)attribute).Indent;

            scrollbarThreshold = Screen.width - position.width > 19 ? 298 : 313;
            currentEvent       = Event.current;

            bool inverseBool  = !string.IsNullOrEmpty(disableBool) && disableBool.StartsWith("!");
            bool boolDisabled = !string.IsNullOrEmpty(disableBool) && property.serializedObject.targetObject.GetValueFromMemberAtPath <bool>(inverseBool ? disableBool.Substring(1) : disableBool);

            boolDisabled = inverseBool ? !boolDisabled : boolDisabled;

            EditorGUI.BeginDisabledGroup((Application.isPlaying && disableOnPlay) || (!Application.isPlaying && disableOnStop) || boolDisabled);
            EditorGUI.indentLevel += indent;

            if (typeof(IList).IsAssignableFrom(fieldInfo.FieldType))
            {
                index         = AttributeUtility.GetIndexFromLabel(label);
                arrayProperty = property.GetParent();

                if (noIndex)
                {
                    if (string.IsNullOrEmpty(prefixLabel))
                    {
                        label.text = label.text.Substring(0, label.text.Length - 2);
                    }
                }
                else if (!string.IsNullOrEmpty(prefixLabel))
                {
                    prefixLabel += " " + index;
                }
            }


            if (drawPrefixLabel)
            {
                if (!noPrefixLabel)
                {
                    if (!string.IsNullOrEmpty(prefixLabel))
                    {
                        label.text = prefixLabel;
                    }

                    position = EditorGUI.PrefixLabel(position, label);
                }
            }
            else
            {
                if (noPrefixLabel)
                {
                    label.text = "";
                }
                else if (!string.IsNullOrEmpty(prefixLabel))
                {
                    label.text = prefixLabel;
                }
            }

            currentPosition = position;
            currentLabel    = label;
        }
        public override void Begin(Rect position, SerializedProperty property, GUIContent label)
        {
            base.Begin(position, property, label);

            noFieldLabel       = ((CustomAttributeBase)attribute).NoFieldLabel;
            noPrefixLabel      = ((CustomAttributeBase)attribute).NoPrefixLabel;
            noIndex            = ((CustomAttributeBase)attribute).NoIndex;
            prefixLabel        = ((CustomAttributeBase)attribute).PrefixLabel;
            disableOnPlay      = ((CustomAttributeBase)attribute).DisableOnPlay;
            disableOnStop      = ((CustomAttributeBase)attribute).DisableOnStop;
            scrollbarThreshold = Screen.width - position.width > 19 ? 298 : 313;
            indentLevel        = EditorGUI.indentLevel;
            currentEvent       = Event.current;

            EditorGUI.BeginDisabledGroup((Application.isPlaying && disableOnPlay) || (!Application.isPlaying && disableOnStop));

            if (fieldInfo.FieldType.IsArray)
            {
                index         = AttributeUtility.GetIndexFromLabel(label);
                arrayProperty = property.GetParent();

                if (noIndex)
                {
                    if (string.IsNullOrEmpty(prefixLabel))
                    {
                        label.text = label.text.Substring(0, label.text.Length - 2);
                    }
                }
                else if (!string.IsNullOrEmpty(prefixLabel))
                {
                    prefixLabel += " " + index;
                }
            }


            if (drawPrefixLabel)
            {
                if (!noPrefixLabel)
                {
                    if (!string.IsNullOrEmpty(prefixLabel))
                    {
                        label.text = prefixLabel;
                    }
                    position = EditorGUI.PrefixLabel(position, label);
                }
            }
            else
            {
                if (noPrefixLabel)
                {
                    label.text = "";
                }
                else if (!string.IsNullOrEmpty(prefixLabel))
                {
                    label.text = prefixLabel;
                }
            }

            currentPosition = position;
            currentLabel    = label;
        }