Exemplo n.º 1
0
    public void InitIfNot(SerializedProperty property)
    {
        if (_container == null)
        {
            _container = fieldInfo.GetValue(property.serializedObject.targetObject) as TrexSerializableObject;

            _reorderList = new ReorderableList(_container.Values, typeof(TrexSerializableItem), true, true, true, true);

            _reorderList.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "ContainerTable");
            };

            _reorderList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                try
                {
                    _targetObject = _reorderList.list[index] as TrexSerializableItem;
                }
                catch (Exception)
                {
                    return;
                }

                Rect _origin = new Rect(rect);

                rect.height -= EMPTY_PADDING_HEIGHT;
                rect.y      += EMPTY_MARGIN_HEIGHT;

                // type
                EditorGUI.LabelField(rect, _targetObject.type.ToString());
                rect.x += LABEL_WIDTH_TYPE;

                // key
                EditorGUI.LabelField(rect, _targetObject.Key);
                rect.x     += LABEL_WIDTH_KEY;
                rect.width -= LABEL_WIDTH_TYPE + LABEL_WIDTH_KEY + LABEL_WIDTH_BUTTON;

                // value
                TrexSerializableObjectFieldDrawer.AdaptTable[_targetObject.type](_targetObject, rect);
                rect.x       = _origin.width + 12;
                rect.height -= BUTTON_MARGIN_HEIGHT;
                rect.width   = LABEL_WIDTH_BUTTON;

                // apply
                _container[_targetObject.Key] = _targetObject;

                // button
                if (GUI.Button(rect, "x", EditorStyles.miniButtonMid))
                {
                    if (_container.DataTable.ContainsKey(_targetObject.Key))
                    {
                        _container.DataTable.Remove(_targetObject.Key);
                    }
                }
            };

            _reorderList.drawFooterCallback = (Rect rect) =>
            {
                // key
                rect.height = EditorGUIUtility.singleLineHeight + 2.0f;
                rect.width  = rect.width / 3 - 3.8f;
                _addingKey  = EditorGUI.TextField(rect, _addingKey);

                // type
                rect.x     += rect.width + 4.0f;
                _addingType = (TrexObjectType)EditorGUI.EnumPopup(rect, _addingType, EditorStyles.toolbarPopup);

                // button
                rect.x += rect.width + 4.0f;
                if (GUI.Button(rect, "ADD", EditorStyles.toolbarButton))
                {
                    if (string.IsNullOrEmpty(_addingKey) || _container.DataTable.ContainsKey(_addingKey))
                    {
                        return;
                    }

                    TrexSerializableItem _item = new TrexSerializableItem();
                    _item.InitItem(_addingType, _addingKey);

                    _container.DataTable.Add(_addingKey, _item);
                    _reorderList.list.Add(_item);
                }
            };
            _isDraw = true;
        }
    }
Exemplo n.º 2
0
 public static void ColorDrawer(TrexSerializableItem _value, Rect _rect)
 {
     _value.ColorValue = EditorGUI.ColorField(_rect, _value.ColorValue);
 }
Exemplo n.º 3
0
 public static void LayerMaskDrawer(TrexSerializableItem _value, Rect _rect)
 {
     _value.LayerValue = EditorGUI.LayerField(_rect, _value.LayerValue);
 }
Exemplo n.º 4
0
 public static void Vector4Drawer(TrexSerializableItem _value, Rect _rect)
 {
     _value.Vector4Value = EditorGUI.Vector4Field(_rect, "", _value.Vector4Value);
 }
Exemplo n.º 5
0
 public static void TransformDrawer(TrexSerializableItem _value, Rect _rect)
 {
     _value.TransformValue = EditorGUI.ObjectField(_rect, _value.TransformValue, typeof(Transform), true) as Transform;
 }
Exemplo n.º 6
0
 public static void ObjectDrawer(TrexSerializableItem _value, Rect _rect)
 {
     _value.ObjectValue = EditorGUI.ObjectField(_rect, _value.ObjectValue, typeof(UnityEngine.Object), true);
 }
Exemplo n.º 7
0
 public static void BoolDrawer(TrexSerializableItem _value, Rect _rect)
 {
     _value.BoolValue = EditorGUI.Toggle(_rect, _value.BoolValue);
 }
Exemplo n.º 8
0
 public static void FloatDrawer(TrexSerializableItem _value, Rect _rect)
 {
     _value.FloatValue = EditorGUI.FloatField(_rect, _value.FloatValue);
 }