public void DrawClip(Rect area, SerializedProperty property, GUIContent label, float labelWidth, GUIStyle labelStyle, bool nameIsReadonly) { //Draw Name var nameProp = property.FindPropertyRelative(PROP_NAME); var labelRect = new Rect(area.xMin, area.yMin, labelWidth, EditorGUIUtility.singleLineHeight); var textRect = new Rect(labelRect.xMax, area.yMin, (area.width - labelWidth) * 0.4f, EditorGUIUtility.singleLineHeight); EditorGUI.BeginProperty(area, label, nameProp); //EditorGUI.LabelField(labelRect, label, labelStyle); GUI.Label(labelRect, label, labelStyle); if (nameIsReadonly || _nameIsReadOnly || Application.isPlaying) { //EditorGUI.LabelField(textRect, nameProp.stringValue, GUI.skin.textField); GUI.Label(textRect, nameProp.stringValue, GUI.skin.textField); } else { //nameProp.stringValue = EditorGUI.TextField(textRect, nameProp.stringValue); nameProp.stringValue = GUI.TextField(textRect, nameProp.stringValue); } //EditorGUI.EndProperty(); var cache = SPGUI.DisableIfPlaying(); //Draw Animation Clip Reference var clipProp = property.FindPropertyRelative(PROP_CLIP); var xmin = textRect.xMax + 2f; var clipRect = new Rect(xmin, area.yMin, area.xMax - xmin, EditorGUIUtility.singleLineHeight); var clipLabel = GUIContent.none; //EditorGUI.BeginProperty(clipRect, clipLabel, clipProp); //clipProp.objectReferenceValue = EditorGUI.ObjectField(clipRect, clipProp.objectReferenceValue, typeof(AnimationClip), false); var obj = clipProp.objectReferenceValue; if (GameObjectUtil.IsGameObjectSource(obj)) { if (_selectComponentDrawer == null) { _selectComponentDrawer = new SelectableComponentPropertyDrawer(); _selectComponentDrawer.RestrictionType = typeof(IScriptableAnimationClip); _selectComponentDrawer.ShowXButton = true; } _selectComponentDrawer.OnGUI(clipRect, clipProp, GUIContent.none); } else { obj = EditorGUI.ObjectField(clipRect, obj, typeof(UnityEngine.Object), true); if (obj == null || obj is AnimationClip || obj is IScriptableAnimationClip) { clipProp.objectReferenceValue = obj; } else if (GameObjectUtil.IsGameObjectSource(obj)) { clipProp.objectReferenceValue = ObjUtil.GetAsFromSource <IScriptableAnimationClip>(obj) as UnityEngine.Object; } } EditorGUI.EndProperty(); cache.Reset(); if (Application.isPlaying && !property.hasMultipleDifferentValues && property.serializedObject.targetObject is SPLegacyAnimController) { if (GUI.Button(new Rect(area.xMin, area.yMin, 20f, EditorGUIUtility.singleLineHeight), ">")) { var targ = property.serializedObject.targetObject as SPLegacyAnimController; targ.Play(nameProp.stringValue); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { this.Init(property); EditorGUI.BeginProperty(position, label, property); //################################ //FIRST LINE var rect = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight); var configProp = property.FindPropertyRelative(PROP_CONFIGURED); var targetProp = property.FindPropertyRelative(PROP_TARGET); var findProp = property.FindPropertyRelative(PROP_FIND); //var r0 = new Rect(rect.xMin, rect.yMin, EditorGUIUtility.labelWidth, rect.height); //rect = new Rect(r0.xMax, rect.yMin, rect.width - r0.width, rect.height); //property.isExpanded = EditorGUI.Foldout(r0, property.isExpanded, label); if (!this.AlwaysExpanded) { property.isExpanded = SPEditorGUI.PrefixFoldoutLabel(ref rect, property.isExpanded, label); } else { rect = EditorGUI.PrefixLabel(rect, label); } var r0 = new Rect(rect.xMin, rect.yMin, Mathf.Min(rect.width * 0.25f, 50f), rect.height); var e = (configProp.boolValue) ? TargetSource.Config : TargetSource.Arg; EditorGUI.BeginChangeCheck(); e = (TargetSource)EditorGUI.EnumPopup(r0, e); if (EditorGUI.EndChangeCheck()) { UpdateTargetFromSource(targetProp, e); configProp.boolValue = (e != TargetSource.Arg); if (e != TargetSource.Arg) { findProp.SetEnumValue(TriggerableTargetObject.FindCommand.Direct); } } else if (e == TargetSource.Config && !_defaultSet && targetProp.objectReferenceValue == null) { UpdateTargetFromSource(targetProp, e); _defaultSet = true; } else { _defaultSet = true; } var r1 = new Rect(rect.xMin + r0.width, rect.yMin, rect.width - r0.width, rect.height); if (!configProp.boolValue) { var e0 = findProp.GetEnumValue <TriggerableTargetObject.FindCommand>(); switch (e0) { case TriggerableTargetObject.FindCommand.Direct: EditorGUI.LabelField(r1, "Target determined by activating trigger."); break; case TriggerableTargetObject.FindCommand.FindParent: case TriggerableTargetObject.FindCommand.FindInChildren: case TriggerableTargetObject.FindCommand.FindInEntity: EditorGUI.LabelField(r1, e0.ToString() + " of activating trigger arg."); break; case TriggerableTargetObject.FindCommand.FindInScene: case TriggerableTargetObject.FindCommand.FindEntityInScene: default: configProp.boolValue = false; targetProp.objectReferenceValue = null; EditorGUI.LabelField(r1, e0.ToString()); break; } targetProp.objectReferenceValue = null; } else { _objectDrawer.OnGUI(r1, targetProp, GUIContent.none); } //################################ //SECOND LINE if (this.AlwaysExpanded || property.isExpanded) { var indent = EditorGUIUtility.labelWidth * 0.5f; rect = new Rect(position.xMin + indent, position.yMin + EditorGUIUtility.singleLineHeight, Mathf.Max(0f, position.width - indent), EditorGUIUtility.singleLineHeight); var w0 = Mathf.Min(rect.width * 0.3f, 120f); var w1 = Mathf.Min(rect.width * 0.3f, 80f); var w2 = rect.width - w0 - w1; r0 = new Rect(rect.xMin, rect.yMin, w0, rect.height); r1 = new Rect(r0.xMax, rect.yMin, w1, rect.height); var r2 = new Rect(r1.xMax, rect.yMin, w2, rect.height); var resolveProp = property.FindPropertyRelative(PROP_RESOLVEBY); var queryProp = property.FindPropertyRelative(PROP_QUERY); var e0 = findProp.GetEnumValue <TriggerableTargetObject.FindCommand>(); EditorGUI.BeginChangeCheck(); e0 = (TriggerableTargetObject.FindCommand)EditorGUI.EnumPopup(r0, e0); if (EditorGUI.EndChangeCheck()) { findProp.SetEnumValue(e0); } switch (e0) { case TriggerableTargetObject.FindCommand.FindInScene: case TriggerableTargetObject.FindCommand.FindEntityInScene: configProp.boolValue = false; targetProp.objectReferenceValue = null; break; } var e1 = resolveProp.GetEnumValue <TriggerableTargetObject.ResolveByCommand>(); EditorGUI.BeginChangeCheck(); e1 = (TriggerableTargetObject.ResolveByCommand)EditorGUI.EnumPopup(r1, e1); if (EditorGUI.EndChangeCheck()) { resolveProp.SetEnumValue(e1); } switch (e1) { case TriggerableTargetObject.ResolveByCommand.Nothing: { var cache = SPGUI.Disable(); EditorGUI.TextField(r2, string.Empty); queryProp.stringValue = string.Empty; cache.Reset(); } break; case TriggerableTargetObject.ResolveByCommand.WithTag: { queryProp.stringValue = EditorGUI.TagField(r2, queryProp.stringValue); } break; case TriggerableTargetObject.ResolveByCommand.WithName: { queryProp.stringValue = EditorGUI.TextField(r2, queryProp.stringValue); } break; case TriggerableTargetObject.ResolveByCommand.WithType: { var tp = TypeUtil.FindType(queryProp.stringValue); if (!TypeUtil.IsType(tp, typeof(UnityEngine.Object))) { tp = null; } tp = SPEditorGUI.TypeDropDown(r2, GUIContent.none, typeof(UnityEngine.Object), tp); queryProp.stringValue = (tp != null) ? tp.FullName : null; } break; } } EditorGUI.EndProperty(); }
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) { this.Init(property); EditorGUI.BeginProperty(position, label, property); //################################ //FIRST LINE var rect = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight); rect = EditorGUI.PrefixLabel(rect, label); var targetProp = property.FindPropertyRelative(PROP_TARGET); var w0 = Mathf.Min(rect.width * 0.3f, 80f); var w1 = rect.width - w0; var r0 = new Rect(rect.xMin, rect.yMin, w0, EditorGUIUtility.singleLineHeight); var r1 = new Rect(r0.xMax, rect.yMin, w1, EditorGUIUtility.singleLineHeight); var searchProp = property.FindPropertyRelative(PROP_SEARCHBY); var queryProp = property.FindPropertyRelative(PROP_QUERY); var eSearchBy = (SearchByAlt)searchProp.GetEnumValue <SearchBy>(); EditorGUI.BeginChangeCheck(); eSearchBy = (SearchByAlt)EditorGUI.EnumPopup(r0, eSearchBy); if (EditorGUI.EndChangeCheck()) { searchProp.SetEnumValue((SearchBy)eSearchBy); } switch (eSearchBy) { case SearchByAlt.Direct: { //SPEditorGUI.PropertyField(r1, targetProp, GUIContent.none); if (_selectableDrawer == null) { _selectableDrawer = new SelectableComponentPropertyDrawer(); } _selectableDrawer.AllowSceneObjects = true; _selectableDrawer.RestrictionType = _inheritsFromType; _selectableDrawer.AllowProxy = _allowProxy; _selectableDrawer.OnGUI(r1, targetProp, GUIContent.none); } break; case SearchByAlt.Tag: { queryProp.stringValue = EditorGUI.TagField(r1, queryProp.stringValue); targetProp.objectReferenceValue = null; } break; case SearchByAlt.Name: { queryProp.stringValue = EditorGUI.TextField(r1, queryProp.stringValue); targetProp.objectReferenceValue = null; } break; case SearchByAlt.Type: { var tp = TypeUtil.FindType(queryProp.stringValue); if (!TypeUtil.IsType(tp, typeof(UnityEngine.Object))) { tp = null; } tp = SPEditorGUI.TypeDropDown(r1, GUIContent.none, typeof(UnityEngine.Object), tp); queryProp.stringValue = (tp != null) ? tp.FullName : null; targetProp.objectReferenceValue = null; } break; } EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { this.Init(property); EditorGUI.BeginProperty(position, label, property); //################################ //FIRST LINE var rect = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight); var configProp = property.FindPropertyRelative(PROP_CONFIGURED); var targetProp = property.FindPropertyRelative(PROP_TARGET); //var r0 = new Rect(rect.xMin, rect.yMin, EditorGUIUtility.labelWidth, rect.height); //rect = new Rect(r0.xMax, rect.yMin, rect.width - r0.width, rect.height); //property.isExpanded = EditorGUI.Foldout(r0, property.isExpanded, label); property.isExpanded = SPEditorGUI.PrefixFoldoutLabel(ref rect, property.isExpanded, label); var r0 = new Rect(rect.xMin, rect.yMin, Mathf.Min(rect.width * 0.25f, 50f), rect.height); var e = (configProp.boolValue) ? TargetSource.Config : TargetSource.Arg; EditorGUI.BeginChangeCheck(); e = (TargetSource)EditorGUI.EnumPopup(r0, e); if (EditorGUI.EndChangeCheck()) { UpdateTargetFromSource(targetProp, e, (_configAttrib != null) ? _configAttrib.TargetType : null); configProp.boolValue = (e != TargetSource.Arg); } else if (e == TargetSource.Config && !_defaultSet && targetProp.objectReferenceValue == null) { UpdateTargetFromSource(targetProp, e, (_configAttrib != null) ? _configAttrib.TargetType : null); _defaultSet = true; } else { _defaultSet = true; } var r1 = new Rect(rect.xMin + r0.width, rect.yMin, rect.width - r0.width, rect.height); if (!configProp.boolValue) { EditorGUI.LabelField(r1, "Target determined by activating trigger."); targetProp.objectReferenceValue = null; } else { _objectDrawer.RestrictionType = (_configAttrib != null) ? _configAttrib.TargetType : null; _objectDrawer.OnGUI(r1, targetProp, GUIContent.none); } //################################ //SECOND LINE if (property.isExpanded) { var indent = EditorGUIUtility.labelWidth * 0.5f; rect = new Rect(position.xMin + indent, position.yMin + EditorGUIUtility.singleLineHeight, Mathf.Max(0f, position.width - indent), EditorGUIUtility.singleLineHeight); var w0 = Mathf.Min(rect.width * 0.3f, 120f); var w1 = Mathf.Min(rect.width * 0.3f, 80f); var w2 = rect.width - w0 - w1; r0 = new Rect(rect.xMin, rect.yMin, w0, rect.height); r1 = new Rect(r0.xMax, rect.yMin, w1, rect.height); var r2 = new Rect(r1.xMax, rect.yMin, w2, rect.height); var findProp = property.FindPropertyRelative(PROP_FIND); var resolveProp = property.FindPropertyRelative(PROP_RESOLVEBY); var queryProp = property.FindPropertyRelative(PROP_QUERY); var e0 = findProp.GetEnumValue <TriggerableTargetObject.FindCommand>(); EditorGUI.BeginChangeCheck(); e0 = (TriggerableTargetObject.FindCommand)EditorGUI.EnumPopup(r0, e0); if (EditorGUI.EndChangeCheck()) { findProp.SetEnumValue(e0); } var e1 = resolveProp.GetEnumValue <TriggerableTargetObject.ResolveByCommand>(); EditorGUI.BeginChangeCheck(); e1 = (TriggerableTargetObject.ResolveByCommand)EditorGUI.EnumPopup(r1, e1); if (EditorGUI.EndChangeCheck()) { resolveProp.SetEnumValue(e1); } switch (e1) { case TriggerableTargetObject.ResolveByCommand.Nothing: { GUI.enabled = false; EditorGUI.TextField(r2, string.Empty); queryProp.stringValue = string.Empty; GUI.enabled = true; } break; case TriggerableTargetObject.ResolveByCommand.WithTag: { queryProp.stringValue = EditorGUI.TagField(r2, queryProp.stringValue); } break; case TriggerableTargetObject.ResolveByCommand.WithName: { queryProp.stringValue = EditorGUI.TextField(r2, queryProp.stringValue); } break; } } EditorGUI.EndProperty(); }