public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginChangeCheck(); EditorGUI.BeginProperty(position, label, property); var attr = this.attribute as EulerRotationInspectorAttribute; switch (property.propertyType) { case SerializedPropertyType.Quaternion: property.quaternionValue = SPEditorGUI.QuaternionField(position, label, property.quaternionValue, attr.UseRadians); break; case SerializedPropertyType.Vector3: //3d rotation var v = property.vector3Value; v.x = MathUtil.NormalizeAngle(v.x, attr.UseRadians); v.y = MathUtil.NormalizeAngle(v.y, attr.UseRadians); v.z = MathUtil.NormalizeAngle(v.z, attr.UseRadians); v = EditorGUI.Vector3Field(position, label, v); v.x = MathUtil.NormalizeAngle(v.x, attr.UseRadians); v.y = MathUtil.NormalizeAngle(v.y, attr.UseRadians); v.z = MathUtil.NormalizeAngle(v.z, attr.UseRadians); property.vector3Value = v; break; case SerializedPropertyType.Float: //2d rotation float a = MathUtil.NormalizeAngle(property.floatValue, attr.UseRadians); a = EditorGUI.FloatField(position, label, a); a = MathUtil.NormalizeAngle(a, attr.UseRadians); property.floatValue = a; //property.floatValue = FloatAngle(new Rect(0, 0, 30, 30), property.floatValue); break; } EditorGUI.EndProperty(); if (EditorGUI.EndChangeCheck()) { property.serializedObject.ApplyModifiedProperties(); } }
private void DrawValueFieldInValueMode(Rect position, SerializedProperty property, VariantReference.EditorHelper helper) { if (helper.Target == null) { return; } var variant = helper.Target; if (this.RestrictVariantType && helper._type != this.VariantTypeRestrictedTo) { helper.PrepareForValueTypeChange(this.VariantTypeRestrictedTo); GUI.changed = true; //force change } var r0 = new Rect(position.xMin, position.yMin, 90.0f, EditorGUIUtility.singleLineHeight); var r1 = new Rect(r0.xMax, position.yMin, position.xMax - r0.xMax, EditorGUIUtility.singleLineHeight); var cache = SPGUI.DisableIf(this.RestrictVariantType); EditorGUI.BeginChangeCheck(); var valueType = (VariantType)EditorGUI.EnumPopup(r0, GUIContent.none, variant.ValueType); if (EditorGUI.EndChangeCheck()) { helper.PrepareForValueTypeChange(valueType); } cache.Reset(); if (_typeRestrictedTo.IsEnum) { variant.IntValue = ConvertUtil.ToInt(EditorGUI.EnumPopup(r1, ConvertUtil.ToEnumOfType(_typeRestrictedTo, variant.IntValue))); } else { switch (valueType) { case VariantType.Null: cache = SPGUI.Disable(); EditorGUI.TextField(r1, "Null"); cache.Reset(); break; case VariantType.String: variant.StringValue = EditorGUI.TextField(r1, variant.StringValue); break; case VariantType.Boolean: variant.BoolValue = EditorGUI.Toggle(r1, variant.BoolValue); break; case VariantType.Integer: variant.IntValue = EditorGUI.IntField(r1, variant.IntValue); break; case VariantType.Float: variant.FloatValue = EditorGUI.FloatField(r1, variant.FloatValue); break; case VariantType.Double: variant.DoubleValue = ConvertUtil.ToDouble(EditorGUI.TextField(r1, variant.DoubleValue.ToString())); break; case VariantType.Vector2: variant.Vector2Value = EditorGUI.Vector2Field(r1, GUIContent.none, variant.Vector2Value); break; case VariantType.Vector3: variant.Vector3Value = EditorGUI.Vector3Field(r1, GUIContent.none, variant.Vector3Value); break; case VariantType.Vector4: variant.Vector4Value = EditorGUI.Vector4Field(r1, (string)null, variant.Vector4Value); break; case VariantType.Quaternion: variant.QuaternionValue = SPEditorGUI.QuaternionField(r1, GUIContent.none, variant.QuaternionValue); break; case VariantType.Color: variant.ColorValue = EditorGUI.ColorField(r1, variant.ColorValue); break; case VariantType.DateTime: variant.DateValue = ConvertUtil.ToDate(EditorGUI.TextField(r1, variant.DateValue.ToString())); break; case VariantType.GameObject: variant.GameObjectValue = EditorGUI.ObjectField(r1, variant.GameObjectValue, typeof(GameObject), true) as GameObject; break; case VariantType.Component: { _selectComponentDrawer.AllowNonComponents = false; _selectComponentDrawer.RestrictionType = _forcedObjectType; _selectComponentDrawer.ShowXButton = true; var targProp = property.FindPropertyRelative("_unityObjectReference"); EditorGUI.BeginChangeCheck(); _selectComponentDrawer.OnGUI(r1, targProp); if (EditorGUI.EndChangeCheck()) { variant.ComponentValue = targProp.objectReferenceValue as Component; } } break; case VariantType.Object: { var obj = variant.ObjectValue; if (ComponentUtil.IsAcceptableComponentType(_forcedObjectType)) { if (obj is GameObject || obj is Component) { _selectComponentDrawer.AllowNonComponents = false; _selectComponentDrawer.RestrictionType = _forcedObjectType; _selectComponentDrawer.ShowXButton = true; var targProp = property.FindPropertyRelative("_unityObjectReference"); EditorGUI.BeginChangeCheck(); _selectComponentDrawer.OnGUI(r1, targProp); if (EditorGUI.EndChangeCheck()) { variant.ObjectValue = targProp.objectReferenceValue as Component; } } else { EditorGUI.BeginChangeCheck(); obj = EditorGUI.ObjectField(r1, obj, typeof(UnityEngine.Object), true); if (EditorGUI.EndChangeCheck()) { if (obj == null) { variant.ObjectValue = null; } else if (TypeUtil.IsType(obj.GetType(), _forcedObjectType)) { variant.ObjectValue = obj; } else { var go = GameObjectUtil.GetGameObjectFromSource(obj); if (go != null) { variant.ObjectValue = go.GetComponent(_forcedObjectType); } else { variant.ObjectValue = null; } } } } } else { variant.ObjectValue = EditorGUI.ObjectField(r1, obj, _forcedObjectType, true); } } break; case VariantType.LayerMask: { variant.LayerMaskValue = SPEditorGUI.LayerMaskField(r1, GUIContent.none, (int)variant.LayerMaskValue); } break; case VariantType.Rect: { variant.RectValue = EditorGUI.RectField(r1, variant.RectValue); } break; } } }
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; } } }