private void DrawValueFieldInPropertyMode(Rect position, SerializedProperty property, VariantReference.EditorHelper helper) { _selectComponentDrawer.AllowNonComponents = true; _selectComponentDrawer.RestrictionType = null; _selectComponentDrawer.ShowXButton = false; var targProp = property.FindPropertyRelative(PROP_UNITYOBJREF); var memberProp = property.FindPropertyRelative(PROP_STRING); if (targProp.objectReferenceValue == null) { _selectComponentDrawer.OnGUI(position, targProp); } else { var r1 = new Rect(position.xMin, position.yMin, position.width * 0.4f, position.height); var r2 = new Rect(r1.xMax, position.yMin, position.width - r1.width, position.height); _selectComponentDrawer.OnGUI(r1, targProp); memberProp.stringValue = SPEditorGUI.ReflectedPropertyField(r2, targProp.objectReferenceValue, memberProp.stringValue, com.spacepuppy.Dynamic.DynamicMemberAccess.Read); } }
private Rect DrawRefModeSelectionDropDown(Rect position, SerializedProperty property, VariantReference.EditorHelper helper) { var r0 = new Rect(position.xMin, position.yMin, Mathf.Min(REF_SELECT_WIDTH, position.width), position.height); EditorGUI.BeginChangeCheck(); var mode = (VariantReference.RefMode)EditorGUI.EnumPopup(r0, GUIContent.none, _helper._mode); if (EditorGUI.EndChangeCheck()) { _helper.PrepareForRefModeChange(mode); CopyValuesFromHelper(property, helper); } return(new Rect(r0.xMax, r0.yMin, position.width - r0.width, r0.height)); }
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 = ComponentUtil.IsAcceptableComponentType(_forcedObjectType) ? _forcedObjectType : typeof(Component); _selectComponentDrawer.ShowXButton = true; var targProp = property.FindPropertyRelative(PROP_UNITYOBJREF); 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(PROP_UNITYOBJREF); 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; } } }
private void DrawValueFieldInEvalMode(Rect position, SerializedProperty property, VariantReference.EditorHelper helper) { _selectComponentDrawer.AllowNonComponents = true; _selectComponentDrawer.RestrictionType = null; _selectComponentDrawer.ShowXButton = false; var targProp = property.FindPropertyRelative("_unityObjectReference"); var evalProp = property.FindPropertyRelative("_string"); var r1 = new Rect(position.xMin, position.yMin, position.width * 0.4f, position.height); var r2 = new Rect(r1.xMax, position.yMin, position.width - r1.width, position.height); _selectComponentDrawer.OnGUI(r1, targProp); evalProp.stringValue = EditorGUI.TextField(r2, evalProp.stringValue); }