Ejemplo n.º 1
0
    public override void OnGUI(Rect p_position, SerializedProperty p_property, GUIContent p_Label)
    {
        string _path    = p_property.propertyPath;
        bool   _isFirst = _path.EndsWith(".data[0]");

        if (_isFirst)
        {
            Rect _butRect = new Rect(p_position);
            int  _indent  = EditorGUI.indentLevel * 15;
            _butRect.height = 16;
            _butRect.x     += _indent;
            _butRect.width -= _indent + 160;
            GUI.Label(_butRect, "        CopyPaste-Array");

            _butRect.x    += _butRect.width;
            _butRect.width = 160;
            SerializedProperty _parentProperty = SerializedPropertyValue.GetParent(p_property);
            SerializedPropertyValue.DrawCopyPasteArray(_butRect, _parentProperty);
            p_position.y += 18;
        }

        CopyPasteAttribute _copyPaste = attribute as CopyPasteAttribute;

        Rect _copyPasteRect = new Rect(p_position);

        _copyPasteRect.x     += p_position.width - 120;
        _copyPasteRect.width  = 120;
        _copyPasteRect.height = 18;
        SerializedPropertyValue.DrawCopyPaste(_copyPasteRect, p_property);


        if ((p_property.propertyType == SerializedPropertyType.Generic) || (p_property.isArray && (p_property.propertyType != SerializedPropertyType.String)))
        {
            EditorGUI.PropertyField(p_position, p_property, true);
        }
        else
        {
            p_position.width -= 120;
            EditorGUI.PropertyField(p_position, p_property);
        }
    }
Ejemplo n.º 2
0
    public static object GetValue(SerializedProperty p_property)
    {
//		Debug.Log("Get : " + p_Property.propertyType.ToString() + " isArray:" + p_Property.isArray.ToString());
        if (p_property.isArray)
        {
            if (p_property.propertyType == SerializedPropertyType.String)
            {
                return(p_property.stringValue);
            }
            else
            {
                return(GetArray <object>(p_property));
            }
        }
        else
        {
            switch (p_property.propertyType)
            {
            case SerializedPropertyType.Integer:
                return(p_property.intValue);

            case SerializedPropertyType.Boolean:
                return(p_property.boolValue);

            case SerializedPropertyType.Float:
                return(p_property.floatValue);

            case SerializedPropertyType.String:
                return(p_property.stringValue);

            case SerializedPropertyType.Color:
                return(p_property.colorValue);

            case SerializedPropertyType.Gradient:
                return(GetValue <Gradient>(p_property, "gradientValue"));

            case SerializedPropertyType.ObjectReference:
                return(p_property.objectReferenceValue);

            case SerializedPropertyType.LayerMask:
                return(p_property.intValue);

            case SerializedPropertyType.Enum:
                return(p_property.enumValueIndex);

            case SerializedPropertyType.Vector2:
                return(p_property.vector2Value);

            case SerializedPropertyType.Vector3:
                return(p_property.vector3Value);

            case SerializedPropertyType.Rect:
                return(p_property.rectValue);

            case SerializedPropertyType.ArraySize:
                SerializedProperty _parent = SerializedPropertyValue.GetParent(p_property);
                return(_parent.arraySize);

            case SerializedPropertyType.Character:
                return((char)p_property.intValue);

            case SerializedPropertyType.AnimationCurve:
                return(p_property.animationCurveValue);

            case SerializedPropertyType.Bounds:
                return(p_property.boundsValue);

            case SerializedPropertyType.Quaternion:
                return(p_property.quaternionValue);

            case SerializedPropertyType.Generic:
                return(p_property.Copy());

            default:
                Debug.LogError("Not support this type : " + p_property.propertyType.ToString());
                return(null);
            }
        }
    }
Ejemplo n.º 3
0
    public static void SetValue(SerializedProperty p_targetProperty, object p_sourceObj)
    {
        if (p_targetProperty.isArray)
        {
            if (p_targetProperty.propertyType == SerializedPropertyType.String)
            {
                p_targetProperty.stringValue = (string)p_sourceObj;
            }
            else
            {
                object[] _targetArr = ObjToArray(p_sourceObj);
                if (_targetArr != null)
                {
                    int f;
                    int len = _targetArr.Length;
                    p_targetProperty.ClearArray();
                    for (f = 0; f < len; f++)
                    {
                        p_targetProperty.InsertArrayElementAtIndex(f);
                        SerializedProperty _targetProperty = p_targetProperty.GetArrayElementAtIndex(f);
                        SetValue(_targetProperty, _targetArr[f]);
                    }
                }
                else
                {
                    Debug.LogError("SetValue Type Wrong");
                }
            }
        }
        else
        {
            try{
                switch (p_targetProperty.propertyType)
                {
                case SerializedPropertyType.Integer:
                    p_targetProperty.intValue = (int)p_sourceObj;
                    break;

                case SerializedPropertyType.String:
                    p_targetProperty.stringValue = (string)p_sourceObj;
                    break;

                case SerializedPropertyType.Boolean:
                    p_targetProperty.boolValue = (bool)p_sourceObj;
                    break;

                case SerializedPropertyType.Float:
                    p_targetProperty.floatValue = (float)p_sourceObj;
                    break;

                case SerializedPropertyType.Enum:
                    p_targetProperty.enumValueIndex = (int)p_sourceObj;
                    break;

                case SerializedPropertyType.LayerMask:
                    p_targetProperty.intValue = (int)p_sourceObj;
                    break;

                case SerializedPropertyType.ObjectReference:
                    p_targetProperty.objectReferenceValue = (Object)p_sourceObj;
                    break;

                case SerializedPropertyType.Color:
                    p_targetProperty.colorValue = (Color)p_sourceObj;
                    break;

                case SerializedPropertyType.Gradient:
                    SetValue <Gradient>(p_targetProperty, "gradientValue", (Gradient)p_sourceObj);
                    break;

                case SerializedPropertyType.AnimationCurve:
                    p_targetProperty.animationCurveValue = (AnimationCurve)p_sourceObj;
                    break;

                case SerializedPropertyType.Rect:
                    p_targetProperty.rectValue = (Rect)p_sourceObj;
                    break;

                case SerializedPropertyType.Bounds:
                    p_targetProperty.boundsValue = (Bounds)p_sourceObj;
                    break;

                case SerializedPropertyType.Vector2:
                    p_targetProperty.vector2Value = (Vector2)p_sourceObj;
                    break;

                case SerializedPropertyType.Vector3:
                    p_targetProperty.vector3Value = (Vector3)p_sourceObj;
                    break;

                case SerializedPropertyType.Vector4:
                    p_targetProperty.vector4Value = (Vector4)p_sourceObj;
                    break;

                case SerializedPropertyType.ArraySize:
                    SerializedProperty _parent = SerializedPropertyValue.GetParent(p_targetProperty);
                    _parent.arraySize = (int)p_sourceObj;
                    break;

                case SerializedPropertyType.Generic:
                    SerializedProperty _sourceProperty = (SerializedProperty)p_sourceObj;
                    SetValueByProperty(p_targetProperty, _sourceProperty.Copy());
                    break;

                default:
                    Debug.LogError("SetValue Not support this type : " + p_targetProperty.propertyType.ToString());
                    break;
                }
            }catch (System.Exception e) {
                Debug.LogErrorFormat(
                    "SerializedProperty SetValue Error, sourceObj is {0}, targetProperty [{1}] is {2}\n{3}",
                    p_sourceObj.GetType().Name,
                    p_targetProperty.name,
                    p_targetProperty.propertyType,
                    e.Message
                    );
            }
        }
    }
Ejemplo n.º 4
0
    public override void OnGUI(Rect p_position, SerializedProperty p_property, GUIContent p_label)
    {
        string _path = p_property.propertyPath;

        if (!_path.EndsWith("]"))
        {
            EditorGUI.LabelField(p_position, p_label.text, "[ReorderableList] Only for Array Or Collection");
            return;
        }

        ReorderableListAttribute _reorderableList = attribute as ReorderableListAttribute;
        bool _isFirst = _path.EndsWith(".data[0]");

        if (_reorderableList.list != null)
        {
            if (_isFirst)
            {
                Rect _butRect = new Rect(p_position);
                int  _indent  = EditorGUI.indentLevel * 15;
                _butRect.height = 16;
                if (useOrder)
                {
                    _butRect.x     += _indent + 70;
                    _butRect.width -= _indent + 70 + 160;
                    if (GUI.Button(_butRect, "Finish Reorder"))
                    {
                        useOrder = false;
                    }
                }
                else
                {
                    _butRect.x     += _indent;
                    _butRect.width -= _indent + 160;
                    if (GUI.Button(_butRect, "Start Reorder"))
                    {
                        useOrder = true;
                    }
                }

                _butRect.x    += _butRect.width;
                _butRect.width = 160;
                SerializedProperty _parentProperty = SerializedPropertyValue.GetParent(p_property);
                SerializedPropertyValue.DrawCopyPasteArray(_butRect, _parentProperty);
            }
        }

        SerializedObject _serializedObject = p_property.serializedObject;

        if (_isFirst)
        {
            if (_reorderableList.list == null)
            {
                SerializedProperty _parentProperty = SerializedPropertyValue.GetParent(p_property);
                _reorderableList.list = ReorderableListUtility.CreateAutoLayout(_parentProperty, 4, SerializedPropertyValue.DrawCopyPasteBehind);
            }
        }

        if (useOrder)
        {
            if (_isFirst)
            {
                p_position.width -= 120;
                ReorderableListUtility.DoListWithFoldout(_reorderableList.list, p_position);
            }
        }
        else
        {
            p_position.y += 16;

            Rect _copyPasteRect = new Rect(p_position);
            _copyPasteRect.x     += p_position.width - 120;
            _copyPasteRect.width  = 120;
            _copyPasteRect.height = 18;
            string _click = SerializedPropertyValue.DrawCopyPasteButton(_copyPasteRect, p_property);
            if (_click != "")
            {
            }
            else if ((p_property.propertyType == SerializedPropertyType.Generic) || (p_property.isArray && (p_property.propertyType != SerializedPropertyType.String)))
            {
                EditorGUI.PropertyField(p_position, p_property, p_label, true);
            }
            else
            {
                p_position.width -= 120;
                p_position.height = SerializedPropertyValue.GetPropertyHeight(p_property, p_label);
                EditorGUI.PropertyField(p_position, p_property);
            }
        }
    }