/// <summary> /// Draw all properties from begin to end, and return the rect taken up. /// </summary> private Rect DrawPropertyNestedRange(Rect position, int indentOffset, SerializedProperty begin, SerializedProperty end) { // Track the top so we know how tall the whole drawn area was float top = position.yMin; SerializedProperty cur = begin.Copy(); while (!SerializedProperty.EqualContents(cur, end)) { EditorGUI.indentLevel = cur.depth + indentOffset; position.y += PROPERTY_MARGIN; StratusSerializedPropertyHandler curHandler = StratusScriptAttributeUtility.GetHandler(cur); position.height = curHandler.GetHeight(cur, StratusEditorUtility.TempContent(cur.displayName), cur.isExpanded); EditorGUI.BeginChangeCheck(); curHandler.OnGUI(position, cur, null, true); position.y += position.height; if (EditorGUI.EndChangeCheck()) { break; } cur.NextVisible(false); } position.yMin = top; return(position); }
private void DrawHierarchy(Rect rect) { //if (behaviorTree != null) GUILayout.BeginArea(rect); GUILayout.Label("Hierarchy", StratusGUIStyles.header); GUILayout.EndArea(); rect = StratusEditorUtility.PadVertical(rect, lineHeight); //rect.y += lineHeight * 2f; treeInspector?.TreeViewGUI(rect); }
private void DrawHierarchy(Rect rect) { //if (behaviorTree != null) //GUI.BeginGroup(rect); GUILayout.BeginArea(rect); GUILayout.Label("Hierarchy", StratusGUIStyles.header); //rect.y += lineHeight * 2f; GUILayout.EndArea(); //GUI.EndGroup(); float offset = lineHeight * 3f; rect = StratusEditorUtility.RaiseVertical(rect, offset); this.treeInspector?.TreeViewGUI(rect); //rect = StratusEditorUtility.PadVertical(rect, lineHeight); }
/// <summary> /// Calculate the height taken up by all properties from begin to end. /// </summary> private float GetHeightNestedRange(SerializedProperty begin, SerializedProperty end) { float height = 0f; SerializedProperty cur = begin.Copy(); while (!SerializedProperty.EqualContents(cur, end)) { StratusSerializedPropertyHandler curHandler = StratusScriptAttributeUtility.GetHandler(cur); float curHeight = curHandler.GetHeight(cur, StratusEditorUtility.TempContent(cur.displayName), cur.isExpanded); height += curHeight + PROPERTY_MARGIN; cur.NextVisible(false); } return(height); }
private void ModifyAction(Rect rect) { EditorGUILayout.LabelField("Action", EditorStyles.boldLabel); // Set the action EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(this.Type); if (GUILayout.Button("Set", EditorStyles.miniButtonRight)) { this.target.task = (StratusAITask)StratusEditorUtility.Instantiate(this.target.type.Type); } EditorGUILayout.EndHorizontal(); // If an action has been set, show it //if (target.action != null) // ActionEditor = UnityEditor.Editor.CreateEditor(StatefulAction.action); //ActionEditor.DrawDefaultInspector(); }
void ShowBookmarkedScenes() { GUILayout.Label("Bookmarks", EditorStyles.centeredGreyMiniLabel); foreach (var scene in BookmarkedScenes) { // If it was deleted from the outside, we need to remove this reference if (scene == null) { RemoveBookmarkedScene(scene); return; } EditorGUILayout.BeginHorizontal(); // Open scene if (GUILayout.Button(scene.name, EditorStyles.toolbarButton)) { StratusEditorUtility.OnMouseClick( () => { var scenePath = AssetDatabase.GetAssetPath(scene); if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { EditorSceneManager.OpenScene(scenePath); } }, () => { var menu = new GenericMenu(); menu.AddItem(new GUIContent("Remove"), false, () => { RemoveBookmarkedScene(scene); } ); menu.ShowAsContext(); }, null, true); } EditorGUILayout.EndHorizontal(); } }
private void SelectExtension(Rect rect) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Extensions", EditorStyles.whiteLargeLabel); bool changed = StratusEditorUtility.CheckControlChange(() => { extensionIndex = EditorGUILayout.Popup(extensionIndex, extensionsNames); if (GUILayout.Button("Remove", EditorStyles.miniButtonRight)) { RemoveExtension(selectedExtension); } }); if (changed || extensionEditor == null) { CreateExtensionEditor(); } } EditorGUILayout.EndHorizontal(); }
/// <summary> /// Handle the Drawing of a given property without the need of a position Rect. /// </summary> public bool OnGUILayout(SerializedProperty property, GUIContent label, bool includeChildren, params GUILayoutOption[] options) { bool haveDecorators = (decoratorDrawers != null && decoratorDrawers.Count != 0); bool needCustomRect = (property.propertyType != SerializedPropertyType.Boolean || PropertyDrawer != null || haveDecorators); Rect curRect; if (needCustomRect) { bool hasLabel = StratusEditorUtility.LabelHasContent(label); float height = GetHeight(property, label, includeChildren); curRect = EditorGUILayout.GetControlRect(hasLabel, height, options); } else { curRect = StratusEditorUtility.GetToggleRect(true, options); } StratusEditorUtility.lastEditorGUILayoutRect = curRect; return(OnGUI(curRect, property, label, includeChildren)); }
//----------------------------------------------------------------------/ // Procedures //----------------------------------------------------------------------/ private void DrawEditor() { //EditProperty(nameof(this.behaviorTree)); if (this.InspectObjectFieldWithHeader(ref this.behaviorTree, "Behavior Tree")) { this.OnTreeSet(); } if (!this.isTreeSet) { return; } //if (StratusEditorUtility.currentEvent.type != EventType.Repaint) // return; Rect rect = this.currentPosition; // this.currentPosition; rect = StratusEditorUtility.Pad(rect); rect = StratusEditorUtility.PadVertical(rect, lineHeight * 5f); // Hierarchy: LEFT rect.width *= 0.5f; this.DrawHierarchy(rect); // Inspector: TOP-RIGHT rect.x += rect.width; rect.width -= StratusEditorGUI.standardPadding; rect.height *= 0.5f; rect.height -= padding * 2f; this.DrawInspector(rect); // Blackboard: BOTTOM-RIGHT rect.y += rect.height; rect.y += padding; this.DrawBlackboard(rect); }
protected override void OnGUILayout(Rect position) { if (instance.scenePool == null) { GUILayout.Label("No ScenePool asset has been set!"); return; } GUILayout.BeginHorizontal(); GUILayout.Label("Scenes:"); if (GUILayout.Button("Open All")) { SceneLinker.OpenAll(); } if (GUILayout.Button("Close All")) { SceneLinker.CloseAll(); } GUILayout.EndHorizontal(); GUILayout.Space(2.5f); displayScrollPosition = GUILayout.BeginScrollView(displayScrollPosition, false, false); foreach (var scene in instance.scenes) { GUILayout.BeginHorizontal(); GUILayout.Label($"- " + scene.name); if (scene.isOpened) { if (GUILayout.Button("Close", EditorStyles.miniButtonRight, GUILayout.Width(displayOpenButtonWidth))) { scene.Close(); } } else { if (GUILayout.Button("Open", EditorStyles.miniButtonRight, GUILayout.Width(displayOpenButtonWidth))) { scene.Add(); } } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.BeginHorizontal(); { GUILayout.Label($"Links ({sceneLinks.Length})"); StratusEditorUtility.Toggle(instance, "displayLinks", "Show"); //instance.displayLinks = GUILayout.Toggle(instance.displayLinks, "Show"); if (GUILayout.Button("Select")) { foreach (var link in sceneLinks) { EditorGUIUtility.PingObject(link); } } } GUILayout.EndHorizontal(); StratusEditorUtility.Toggle(instance, "displayBoundaries", "Show scene boundaries"); StratusEditorUtility.Toggle(instance, "loadInitial", "Load initial scene on play"); }
private void SelectScenes(Rect rect) { StratusEditorUtility.SelectSubset(triggerable.scenePool.scenes, triggerable.selectedScenes, GetName); }
private void Show(StratusEpisode episode) { GUILayout.Label(episode.label, EditorStyles.whiteLargeLabel); //StratusEditorUtility.OnLastControlMouseClick(null, null, () => { Selection.activeGameObject = episode.gameObject; }); EditorGUILayout.BeginHorizontal(); StratusEditorUtility.ModifyProperty(episode, "mode", GUIContent.none); if (GUILayout.Button("Validate", EditorStyles.miniButtonRight)) { ValidatorWindow.Open("Episode Validation", ObjectValidation.Aggregate(episode)); } EditorGUILayout.EndHorizontal(); foreach (var segment in episode.segments) { if (segment == null || !segmentExpanded.ContainsKey(segment)) { continue; } // Show the segment GUILayout.BeginHorizontal(EditorStyles.toolbar); //episode.initialSegment == episode ? $"{episode.label} *" : episode.label, EditorStyles.whiteLabel GUIStyle segmentStyle = EditorStyles.label; // segment == (episode.initialSegment) ? EditorStyles.centeredGreyMiniLabel: GUI.skin.label; string label = episode.initialSegment == segment ? $"{segment.label} (Initial)" : segment.label; segmentExpanded[segment] = EditorGUILayout.Foldout(segmentExpanded[segment], label, false, EditorStyles.foldout); //if (EditorGUI.Rect) System.Action onRightClick = () => { var menu = new GenericMenu(); menu.AddItem(new GUIContent("Select"), false, () => { Selection.activeGameObject = segment.gameObject; }); if (!Application.isPlaying) { menu.AddItem(new GUIContent("Set Initial"), false, () => { episode.SetInitialSegment(segment); }); } else { menu.AddItem(new GUIContent("Enter"), false, () => { episode.Enter(segment, true, 0); }); } menu.ShowAsContext(); }; System.Action onDoubleClick = () => { StratusDebug.Log("Boop"); Selection.activeGameObject = segment.gameObject; }; StratusEditorUtility.OnLastControlMouseClick(null, onRightClick, onDoubleClick); //var button = new GUIObject(); //button.label = segment.label; //button.onRightClickDown = onRightClick; //button.onLeftClickUp = onLeftClick; //button.Draw(segmentStyle); GUILayout.EndHorizontal(); ShowSegment(episode, segment); } }
/// <summary> /// Handle the height calculation for the current property /// </summary> public float GetHeight(SerializedProperty inputProperty, GUIContent label, bool includeChildren) { float heightSoFar = 0f; // Handle decorator drawer heights if (decoratorDrawers != null && !IsCurrentlyNested) { // add up the heigh of all attached decorators foreach (DecoratorDrawer decoratorDrawer in decoratorDrawers) { heightSoFar += decoratorDrawer.GetHeight(); } } // Copy the property to ensure we don't break caller's position SerializedProperty property = inputProperty.Copy(); // If this is drawn by a Property drawer, use its height if (PropertyDrawer != null) { GUIContent curLabel = label ?? StratusEditorUtility.TempContent(property.displayName); return(PropertyDrawer.GetPropertyHeightSafe(property, curLabel) + heightSoFar); } // If this is an array header, special case it //if (Redacted.PaginatedArrayUtilities.IsArraySizeProperty(property)) //{ // return Redacted.PaginatedArrayUtilities.GetArrayHeaderSize(property) + heightSoFar; //} // Start with the default drawer heightSoFar += StratusEditorUtility.GetSinglePropertyHeight(property, label); // Has children that need to be drawn if (includeChildren && property.isExpanded) { SerializedProperty begin = null; SerializedProperty end = null; // Special case for paginated arrays if (property.isArray) { SerializedProperty sizeProperty = property.Copy(); sizeProperty.NextVisible(true); //heightSoFar += StratusEditorUtility.GetSinglePropertyHeight(sizeProperty, ) //heightSoFar += Redacted.PaginatedArrayUtilities.GetArrayHeaderSize(sizeProperty); //Redacted.PaginatedArrayUtilities.GetPagePropertyRange(property, ref begin, ref end); } else { begin = property.Copy(); begin.NextVisible(true); end = property.GetEndProperty(); } if (begin != null && end != null) { heightSoFar += GetHeightNestedRange(begin, end); } } return(heightSoFar); }
/// <summary> /// Handle the Drawing of a given property, within a given position rect. /// </summary> public bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren) { // Keep track of the height we have available to draw this property after decorator drawers float heighRemaining = position.height; position.height = 0f; // Handle Decorator Drawers for non-nested properties if (decoratorDrawers != null && !IsCurrentlyNested) { foreach (DecoratorDrawer decoratorDrawer in decoratorDrawers) { position.height = decoratorDrawer.GetHeight(); float labelWidth = EditorGUIUtility.labelWidth; float fieldWidth = EditorGUIUtility.fieldWidth; // Draw the decorator with its default OnGUI decoratorDrawer.OnGUI(position); EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.fieldWidth = fieldWidth; position.y += position.height; heighRemaining -= position.height; } } position.height = heighRemaining; // Handle Property drawers if (PropertyDrawer != null) { float labelWidth = EditorGUIUtility.labelWidth; float fieldWidth = EditorGUIUtility.fieldWidth; GUIContent curLabel = label ?? StratusEditorUtility.TempContent(property.displayName); PropertyDrawer.OnGUISafe(position, property.Copy(), curLabel); EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.fieldWidth = fieldWidth; return(false); } position.height = StratusEditorUtility.GetSinglePropertyHeight(property, label); bool isVisible = StratusEditorUtility.DefaultPropertyField(position, property, label); position.y += position.height; // No children - we're done if (!includeChildren) { return(isVisible); } // Handle Children if (isVisible && StratusEditorUtility.HasVisibleChildFields(property)) { Vector2 localIconSize = EditorGUIUtility.GetIconSize(); bool localEnabled = GUI.enabled; int localIndentLevel = EditorGUI.indentLevel; SerializedProperty begin = null; SerializedProperty end = null; // Array/List: Get paginated begin/end, draw header, and update position to where paginated elements should be drawn if (property.isArray) { //Redacted.PaginatedArrayUtilities.GetPagePropertyRange(property, ref begin, ref end); //SerializedProperty sizeProperty = property.Copy(); //sizeProperty.NextVisible(true); //EditorGUI.BeginChangeCheck(); //Rect headerRect = Redacted.PaginatedArrayUtilities.HandleArrayHeader(position, sizeProperty); //if (EditorGUI.EndChangeCheck()) // return false; // //position.y += headerRect.height; //position.height -= headerRect.height; } // Default: Just get first and last child else { begin = property.Copy(); begin.NextVisible(true); end = property.GetEndProperty(); } // Draw all nested properties from begin to end if (begin != null && end != null) { position = DrawPropertyNestedRange(position, EditorGUI.indentLevel - property.depth, begin, end); } EditorGUIUtility.SetIconSize(localIconSize); GUI.enabled = localEnabled; EditorGUI.indentLevel = localIndentLevel; } return(false); }