public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { this.Init(property, true); //var cache = SPGUI.DisableIfPlaying(); if (this.HideAllDetails) { var clipPos = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight); //this.DrawClip(EditorGUI.IndentedRect(clipPos), property, label, EditorGUIUtility.labelWidth, GUI.skin.label, _nameIsReadOnly); this.DrawClip(clipPos, property, label, EditorGUIUtility.labelWidth, GUI.skin.label, _nameIsReadOnly); } else { property.isExpanded = SPEditorGUI.PrefixFoldoutLabel(position, property.isExpanded, GUIContent.none); var clipPos = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight); //this.DrawClip(EditorGUI.IndentedRect(clipPos), property, label, EditorGUIUtility.labelWidth, GUI.skin.label, _nameIsReadOnly); this.DrawClip(clipPos, property, label, EditorGUIUtility.labelWidth, GUI.skin.label, _nameIsReadOnly); if (property.isExpanded) { var detailRect = new Rect(position.xMin + 5f, position.yMin + EditorGUIUtility.singleLineHeight, position.width - 5f, this.GetDetailHeight()); this.DrawDetails(detailRect, property); } } //cache.Reset(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { bool canShrink = this.attribute is DisplayFlatAttribute ? (this.attribute as DisplayFlatAttribute).CanShrinkAndExpand : false; bool cache = property.isExpanded; if (!canShrink) { property.isExpanded = true; } try { if (!property.hasChildren) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } if (canShrink) { cache = SPEditorGUI.PrefixFoldoutLabel(position, property.isExpanded, GUIContent.none); } if (property.isExpanded) { float h = SPEditorGUI.GetDefaultPropertyHeight(property, label, true) + BOTTOM_PAD + TOP_PAD - EditorGUIUtility.singleLineHeight; var area = new Rect(position.x, position.yMax - h, position.width, h); var drawArea = new Rect(area.x, area.y + TOP_PAD, area.width - MARGIN, area.height - TOP_PAD); GUI.BeginGroup(area, label, GUI.skin.box); GUI.EndGroup(); EditorGUI.indentLevel++; SPEditorGUI.FlatChildPropertyField(drawArea, property); EditorGUI.indentLevel--; } else { GUI.BeginGroup(position, label, GUI.skin.box); GUI.EndGroup(); } } catch (System.Exception ex) { throw ex; } finally { property.isExpanded = cache; } }
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(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (EditorHelper.AssertMultiObjectEditingNotSupported(position, property, label)) { return; } this.Init(property, label, true); _currentLabel = label; if (this.fieldInfo.DeclaringType == typeof(SPAnimationController)) { _currentLabel.text = "Animation States"; } property.isExpanded = SPEditorGUI.PrefixFoldoutLabel(position, property.isExpanded, GUIContent.none); if (!property.isExpanded) { //here we emulate the ReorderableList header //ReorderableListHelper.DrawRetractedHeader(EditorGUI.IndentedRect(position), label); ReorderableListHelper.DrawRetractedHeader(position, label); } else { //var cache = SPGUI.DisableIfPlaying(); _animList.displayAdd = !Application.isPlaying; _animList.displayRemove = !Application.isPlaying; _animList.draggable = !Application.isPlaying; EditorGUI.BeginChangeCheck(); //_animList.DoList(EditorGUI.IndentedRect(position)); _animList.DoList(position); if (EditorGUI.EndChangeCheck()) { property.serializedObject.ApplyModifiedProperties(); } if (!_hideDetailRegion && _animList.index >= 0) { try { var detailRect = new Rect(position.xMin, position.yMin + _animList.GetHeight(), position.width, this.GetDetailHeight()); var stateProp = _animList.serializedProperty.GetArrayElementAtIndex(_animList.index); var nameProp = stateProp.FindPropertyRelative("_name"); GUI.BeginGroup(detailRect, nameProp.stringValue, GUI.skin.box); GUI.EndGroup(); //draw basic details var buffer = EditorGUIUtility.singleLineHeight + 2f; detailRect = new Rect(detailRect.xMin, detailRect.yMin + buffer, detailRect.width, detailRect.height - buffer); _clipDrawer.DrawDetails(detailRect, stateProp); } catch { //failed to draw details because poorly selected nonsense } } //cache.Reset(); } }
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(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { //EditorGUI.BeginProperty(position, label, property); //if(property.isExpanded) //{ // var r1 = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight); // var r2 = new Rect(position.xMin, r1.yMax, position.width, EditorGUIUtility.singleLineHeight); // var r3 = new Rect(position.xMin, r2.yMax, position.width, EditorGUIUtility.singleLineHeight); // property.isExpanded = EditorGUI.Foldout(r1, property.isExpanded, GUIContent.none); // SPEditorGUI.DefaultPropertyField(r1, property.FindPropertyRelative(PROP_WEIGHT), label); // EditorGUI.indentLevel++; // SPEditorGUI.DefaultPropertyField(r2, property.FindPropertyRelative(PROP_DIMINISHRATE), EditorHelper.TempContent("Diminish Rate")); // SPEditorGUI.DefaultPropertyField(r3, property.FindPropertyRelative(PROP_DIMINISHPERIOD), EditorHelper.TempContent("Diminish Period Duration")); // EditorGUI.indentLevel--; //} //else //{ // property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, GUIContent.none); // SPEditorGUI.DefaultPropertyField(position, property.FindPropertyRelative(PROP_WEIGHT), label); //} //EditorGUI.EndProperty(); if (!this.DrawFoldout || property.isExpanded) { const float LINE2_MARGIN = 20f; var r1 = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight); var r2 = new Rect(position.xMin + LINE2_MARGIN, r1.yMax, Mathf.Max(position.width - LINE2_MARGIN, 0f), EditorGUIUtility.singleLineHeight); if (this.DrawFoldout) { property.isExpanded = SPEditorGUI.PrefixFoldoutLabel(r1, property.isExpanded, GUIContent.none); } var weightProp = property.FindPropertyRelative(PROP_WEIGHT); _line1[0] = weightProp.floatValue; EditorGUI.BeginChangeCheck(); SPEditorGUI.MultiFloatField(r1, label, _line1Labels, _line1, 50f); if (EditorGUI.EndChangeCheck()) { weightProp.floatValue = _line1[0]; } var maxCountProp = property.FindPropertyRelative(PROP_MAXCOUNT); var rateProp = property.FindPropertyRelative(PROP_DIMINISHRATE); var periodProp = property.FindPropertyRelative(PROP_DIMINISHPERIOD); _line2[0] = maxCountProp.floatValue; _line2[1] = rateProp.floatValue; _line2[2] = periodProp.floatValue; EditorGUI.BeginChangeCheck(); SPEditorGUI.DelayedMultiFloatField(r2, _line2Labels, _line2, 80f); if (EditorGUI.EndChangeCheck()) { maxCountProp.floatValue = DiscreteFloatPropertyDrawer.NormalizeValue(maxCountProp.floatValue, _line2[0]); rateProp.floatValue = _line2[1]; periodProp.floatValue = _line2[2]; } } else { if (this.DrawFoldout) { property.isExpanded = SPEditorGUI.PrefixFoldoutLabel(position, property.isExpanded, GUIContent.none); } var weightProp = property.FindPropertyRelative(PROP_WEIGHT); _line1[0] = weightProp.floatValue; SPEditorGUI.MultiFloatField(position, label, _line1Labels, _line1, 50f); } }