Exemplo n.º 1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var r0 = new Rect(position.xMin, position.yMin, position.width / 2f, position.height);
            var r1 = new Rect(r0.xMax, position.yMin, position.width - r0.width, position.height);

            var propName  = property.FindPropertyRelative(PROP_NAME);
            var propValue = property.FindPropertyRelative(PROP_VALUE);
            var propRef   = property.FindPropertyRelative(PROP_REF);

            int index = System.Array.IndexOf(_knownPlayerSettingPropNames, propName.stringValue);

            EditorGUI.BeginChangeCheck();
            index = EditorGUI.Popup(r0, GUIContent.none, index, _knownPlayerSettingPropNamesPretty);
            if (EditorGUI.EndChangeCheck())
            {
                if (index >= 0 && index < _knownPlayerSettingPropNames.Length)
                {
                    propName.stringValue = _knownPlayerSettingPropNames[index];
                }
                else
                {
                    propName.stringValue = string.Empty;
                }

                propValue.stringValue        = string.Empty;
                propRef.objectReferenceValue = null;
            }

            if (index < 0 || index >= _knownPlayerSettings.Length)
            {
                return;
            }

            var info = _knownPlayerSettings[index];

            if (info.PropertyType.IsEnum)
            {
                int ei = ConvertUtil.ToInt(propValue.stringValue);
                propValue.stringValue        = ConvertUtil.ToInt(EditorGUI.EnumPopup(r1, ConvertUtil.ToEnumOfType(info.PropertyType, ei))).ToString();
                propRef.objectReferenceValue = null;
            }
            else
            {
                var etp = VariantReference.GetVariantType(info.PropertyType);
                switch (etp)
                {
                case VariantType.Null:
                    propValue.stringValue        = string.Empty;
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.String:
                    propValue.stringValue        = EditorGUI.TextField(r1, propValue.stringValue);
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Boolean:
                    propValue.stringValue        = EditorGUI.Toggle(r1, GUIContent.none, ConvertUtil.ToBool(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Integer:
                    propValue.stringValue        = EditorGUI.IntField(r1, GUIContent.none, ConvertUtil.ToInt(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Float:
                    propValue.stringValue        = EditorGUI.FloatField(r1, GUIContent.none, ConvertUtil.ToSingle(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Double:
                    propValue.stringValue        = EditorGUI.DoubleField(r1, GUIContent.none, ConvertUtil.ToDouble(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Vector2:
                    propValue.stringValue        = VectorUtil.Stringify(EditorGUI.Vector2Field(r1, GUIContent.none, ConvertUtil.ToVector2(propValue.stringValue)));
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Vector3:
                    propValue.stringValue        = VectorUtil.Stringify(EditorGUI.Vector3Field(r1, GUIContent.none, ConvertUtil.ToVector3(propValue.stringValue)));
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Vector4:
                    propValue.stringValue        = VectorUtil.Stringify(EditorGUI.Vector4Field(r1, (string)null, ConvertUtil.ToVector4(propValue.stringValue)));
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Quaternion:
                    propValue.stringValue        = QuaternionUtil.Stringify(SPEditorGUI.QuaternionField(r1, GUIContent.none, ConvertUtil.ToQuaternion(propValue.stringValue)));
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Color:
                    propValue.stringValue        = ConvertUtil.ToInt(EditorGUI.ColorField(r1, ConvertUtil.ToColor(propValue.stringValue))).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.DateTime:
                    //TODO - should never actually occur
                    propValue.stringValue        = string.Empty;
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.GameObject:
                case VariantType.Component:
                case VariantType.Object:
                    propValue.stringValue        = string.Empty;
                    propRef.objectReferenceValue = EditorGUI.ObjectField(r1, GUIContent.none, propValue.objectReferenceValue, info.PropertyType, false);
                    break;

                case VariantType.LayerMask:
                    propValue.stringValue        = SPEditorGUI.LayerMaskField(r1, GUIContent.none, ConvertUtil.ToInt(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Rect:
                    //TODO - should never actually occur
                    propValue.stringValue        = string.Empty;
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Numeric:

                    break;
                }
            }
        }