void OnGUI() { XGUI.ResetToStyle(null); XGUI.BeginVertical(); if (editor == null || editor.Equals(null)) { editor = GraphEditor.Instance; } // Check if the graph editor exists if (editor == null || editor.Equals(null) || editor.Graph == null || editor.Graph.Equals(null)) { XGUI.ResetToStyle(GUI.skin.label); XGUI.Padding = new RectOffset(0, 0, 10, 0); XGUI.Alignment = TextAnchor.MiddleCenter; XGUI.FontStyle = FontStyle.Italic; XGUI.Label("No open graph"); XGUI.FlexibleSpace(); } else { InitList(); list.DoLayoutList(); } XGUI.EndVertical(); }
internal void OnGUI() { var offset = GraphEditor.Skin.tooltipPadding; var popupRect = new Rect(); popupRect.xMin = Event.current.mousePosition.x + 10; popupRect.yMin = Event.current.mousePosition.y + 10; popupRect.size = GUI.skin.label.CalcSize(new GUIContent(Text)); popupRect.size += new Vector2(offset.horizontal, offset.vertical); XGUI.ResetToStyle(null); XGUI.Color = GraphEditor.Skin.tooltipColor; XGUI.Border = GraphEditor.Skin.tooltipTextureOffset; XGUI.Normal.background = GraphEditor.Skin.tooltipBackground; XGUI.Box(popupRect, XGUI.None); popupRect.xMin += offset.left; popupRect.yMin += offset.right; XGUI.ResetToStyle(null); XGUI.RichText = true; XGUI.Alignment = TextAnchor.UpperLeft; XGUI.Normal.textColor = GraphEditor.Skin.tooltipTextColor; XGUI.Label(popupRect, Text); }
private void DrawElement (Rect rect, int index, bool isActive, bool isFocused) { var item = (Variable)list.list[index]; var width = rect.width; var height = rect.height; rect.y += EditorGUIUtility.standardVerticalSpacing; rect.height = EditorGUIUtility.singleLineHeight; XGUI.ResetToStyle(GUI.skin.label); XGUI.RichText = true; var str = item.Value == null ? null : item.Value.TypeString; XGUI.Label(rect, string.Format("<b>{0}</b> <i>{1}</i>", item.Name, str)); rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing; rect.height = height - EditorGUIUtility.singleLineHeight - EditorGUIUtility.standardVerticalSpacing * 4; EditorGUI.BeginChangeCheck(); var type = item.Value == null ? null : Type.GetType(item.Value.TypeString); if (type != null) { if (typeof(UnityEngine.Object).IsAssignableFrom(type)) { item.Value.Value = EditorGUI.ObjectField(rect, (UnityEngine.Object)item.Value.Value, type, true); } else { var oldValue = item.Value.Value; var newValue = GUIExtension.DrawField(rect, oldValue, type, XGUI.None, true); item.Value.Value = newValue; } } else { XGUI.ResetToStyle(GUI.skin.label); XGUI.Enabled = false; XGUI.TextField(rect, "Unknown Type"); } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(editor.Graph); } }
public static void DrawNode(GraphEditor editor, Node node) { GUI.enabled = !editor.search.IsOpen; EditorGUI.BeginChangeCheck(); if (Util.IsNull(node)) { return; } var serializedObject = new SerializedObject(node); var inputs = node.GetInputSockets(); var outputs = node.GetOutputSockets(); var inputWidth = GetContentWidth(node, true, inputs); var inputHeight = GetPropertyHeights(serializedObject, node, inputs, editor); var outputWidth = GetContentWidth(node, false, outputs); var outputHeight = GetPropertyHeights(serializedObject, node, outputs, editor); var height = Mathf.Max(inputHeight, outputHeight) + LINE_PADDING + EditorGUIUtility.singleLineHeight; // Draw box var rect = new Rect(); rect.width = inputWidth + outputWidth + BOX_PADDING * 2 + SOCKET_RADIUS * 4 + SOCKET_PADDING * 2 + MIDDLE_PADDING; if (inputWidth == 0 || outputWidth == 0) { rect.width -= MIDDLE_PADDING + SOCKET_RADIUS * 2 + SOCKET_PADDING; } rect.height = height + BOX_PADDING * 2; rect.center = new Vector2(node.XPos, -node.YPos) + editor.Offset; var fullRect = new Rect(rect); XGUI.ResetToStyle(null); XGUI.Color = GraphEditor.Skin.nodeColor; if (editor.Target == null || !editor.Target.Equals(node)) { XGUI.Color = GraphEditor.Skin.TintColor (XGUI.Color, GraphEditor.Skin.offNodeTint); } XGUI.Border = GraphEditor.Skin.nodeTextureOffset; XGUI.Normal.background = GraphEditor.Skin.nodeBackgroundTexture; XGUI.Box(rect); if (editor.Target != null && editor.Target.Equals(node)) { XGUI.ResetToStyle(null); XGUI.Color = GraphEditor.Skin.nodeFrameColor; XGUI.Border = GraphEditor.Skin.nodeTextureOffset; XGUI.Normal.background = GraphEditor.Skin.nodeFrameTexture; XGUI.Box(rect); } var labelRect = new Rect(rect); labelRect.x += BOX_PADDING; labelRect.y += BOX_PADDING; labelRect.height = EditorGUIUtility.singleLineHeight; XGUI.ResetToStyle(null); XGUI.FontStyle = FontStyle.Bold; XGUI.Normal.textColor = GraphEditor.Skin.nodeTextHeaderColor; if (editor.search.IsOpen) { XGUI.Normal.textColor = GraphEditor.Skin.TintColor( XGUI.Normal.textColor, GraphEditor.Skin.disabledNodeTextTint); } XGUI.Label(labelRect, node.DisplayName); rect.x += BOX_PADDING; if (inputWidth != 0) { rect.x += SOCKET_RADIUS * 2 + SOCKET_PADDING; } rect.y = labelRect.y + labelRect.height + LINE_PADDING; rect.width = inputWidth; var leftRect = new Rect(rect); if (inputWidth != 0) { rect.x += inputWidth + MIDDLE_PADDING; } rect.width = outputWidth; var rightRect = new Rect(rect); DrawMembers(true, editor, node, leftRect, serializedObject, inputs); DrawMembers(false, editor, node, rightRect, serializedObject, outputs); rect = fullRect; if (!editor.search.IsOpen) { switch (Event.current.type) { case EventType.MouseDown: if (rect.Contains(Event.current.mousePosition)) { editor.Target = node; Event.current.Use(); } break; case EventType.MouseDrag: if (ReferenceEquals(editor.Target, node)) { Undo.RecordObject(node, "Move " + node.GetType().Name); if (editor.Snap <= 0) { node.XPos += (int)Event.current.delta.x; node.YPos -= (int)Event.current.delta.y; } else { var graphPos = editor.GraphPosition; node.XPos = Mathf.RoundToInt(graphPos.x / editor.Snap) * editor.Snap; node.YPos = Mathf.RoundToInt(graphPos.y / editor.Snap) * editor.Snap; } Event.current.Use(); } break; case EventType.MouseUp: if (ReferenceEquals(editor.Target, node)) { Event.current.Use(); } break; case EventType.KeyDown: switch (Event.current.keyCode) { #if UNITY_EDITOR_OSX case KeyCode.Backspace: var masked = Event.current.modifiers & EventModifiers.Command; if (masked == EventModifiers.Command) { Delete(editor, node); } break; #endif case KeyCode.Delete: Delete(editor, node); break; } break; } } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } GUI.enabled = true; }
private static void DrawMember (bool isInput, GraphEditor editor, Node node, ref Rect rect, SerializedObject serializedObject, Socket socket) { string name = node.GetSocketDisplayName(socket); bool editable = node.GetSocketFlags(socket).IsEditable(); bool linked = editor.Graph.Links.IsSocketLinkedTo(socket); rect.height = EditorGUIUtility.singleLineHeight; XGUI.ResetToStyle(null); XGUI.Normal.textColor = GraphEditor.Skin.nodeTextColor; if (editor.search.IsOpen) { XGUI.Normal.textColor = GraphEditor.Skin.TintColor( XGUI.Normal.textColor, GraphEditor.Skin.disabledNodeTextTint); } var clipboardHasValue = false; var hovering = rect.Contains(Event.current.mousePosition) && !editor.search.IsOpen; if (editable && !linked) { var type = node.GetSocketType(socket); var value = node.GetSocketValue(socket); clipboardHasValue = editor.Clipboard.ContainsKey(type); // Check for clipboard operations if (hovering) { switch (Event.current.type) { case EventType.MouseDown: if (Event.current.shift) { if (Event.current.button == 0) { usedClipboard = true; if (clipboardHasValue) { value = editor.Clipboard[type]; node.SetSocketValue(socket, value); } } else if (Event.current.button == 1) { usedClipboard = true; editor.Clipboard[type] = value; } Event.current.Use(); } break; case EventType.MouseUp: if (usedClipboard) { usedClipboard = false; Event.current.Use(); } break; } } XGUI.Enabled = !editor.search.IsOpen; var prop = serializedObject.FindProperty(socket.FieldName); if (type == typeof(bool)) { value = XGUI.ToggleLeft(rect, name, (bool)value); node.SetSocketValue(socket, value); } else if (prop != null) { EditorGUI.PropertyField(rect, prop, GUIContent.none, true); } else if (type == null) { XGUI.Enabled = false; XGUI.TextField(rect, "Unknown Type"); } else { value = GUIExtension.DrawField (rect, value, type, GUIContent.none, true); node.SetSocketValue(socket, value); } } else { XGUI.Label(rect, name); } // Prepare a tooltip if (hovering && editor.Tooltip == null) { var text = string.Format( "<color=#4aa><i>{0}</i></color> <b>{1}</b>\n{2}{3}{4}", node.GetSocketType(socket).Name, node.GetSocketDisplayName(socket), string.IsNullOrEmpty(node.GetSocketDescription(socket)) ? "<color=#aaa><i>No documentation</i></color>" : node.GetSocketDescription(socket), (editable && !linked ? "\n<color=#777><i>Shift + Right click to copy</i></color>" : ""), (clipboardHasValue ? "\n<color=#777><i>Shift + Left click to paste</i></color>" : "") ); editor.Tooltip = new Tooltip(text); } }
void OnGUI() { if (list == null || list.Equals(null)) { Close(); return; } XGUI.ResetToStyle(null); XGUI.BeginVertical(); XGUI.ResetToStyle(GUI.skin.textField); XGUI.LabelWidth = 40; varName = XGUI.TextField("Name", varName); typeStr = XGUI.TextField("Type", typeStr); XGUI.ResetToStyle(null); XGUI.BeginHorizontal(); XGUI.ResetToStyle(GUI.skin.button); if (XGUI.Button("Cancel")) { Close(); return; } XGUI.Enabled = IsValid(); if (XGUI.Button("Create")) { var value = new DynamicValue(); value.TypeString = typeStr; list.list.Add(new Variable(varName, value)); editor.SaveList(); Close(); return; } XGUI.EndHorizontal(); if (!IsNameValid()) { EditorGUILayout.HelpBox( "Variable name is empty!", MessageType.Warning); } else if (!IsNameUnique()) { EditorGUILayout.HelpBox( "Variable name is the same as an existing variable!", MessageType.Warning); } else if (!IsTypeValid()) { EditorGUILayout.HelpBox( "Variable type does not exist!", MessageType.Warning); } XGUI.EndVertical(); }
void OnGUI() { Tooltip = null; // Make the box texture opaque if (boxTexture == null) { if (EditorGUIUtility.isProSkin) { // Make a copy of the old texture var oldTex = GUI.skin.box.normal.background; var tmp = RenderTexture.GetTemporary(oldTex.width, oldTex.height); Graphics.Blit(oldTex, tmp); RenderTexture previous = RenderTexture.active; RenderTexture.active = tmp; boxTexture = new Texture2D(oldTex.width, oldTex.height); boxTexture.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0); RenderTexture.active = previous; RenderTexture.ReleaseTemporary(tmp); // Remove alpha var colors = boxTexture.GetPixels(); for (int i = 0; i < colors.Length; ++i) { // Pro background color is RGB(64, 64, 64) colors[i].r = 0.2196f + (colors[i].r * colors[i].a); colors[i].g = 0.2196f + (colors[i].g * colors[i].a); colors[i].b = 0.2196f + (colors[i].b * colors[i].a); colors[i].a = 1; } boxTexture.SetPixels(colors); boxTexture.Apply(); } else { boxTexture = GUI.skin.box.normal.background; } } if (flatTexture == null) { flatTexture = new Texture2D(1, 1); flatTexture.filterMode = FilterMode.Point; flatTexture.SetPixels(new Color[1] { Color.white }); flatTexture.Apply(); } rectCache = rectCache ?? new Dictionary <Socket, Rect>(); rectCache.Clear(); autoRepaintOnSceneChange = true; wantsMouseMove = true; Offset = new Vector2( Mathf.RoundToInt(Offset.x), Mathf.RoundToInt(Offset.y) ); var graphRect = GetGraphRect(); var mousePos = Event.current.mousePosition; GraphPosition = new Vector2( mousePos.x - graphRect.xMin - Offset.x, -mousePos.y + graphRect.yMin + Offset.y ); // Top Toolbar var toolbarHeight = Vector2.up * TOOLBAR_HEIGHT; var topToolbarRect = new Rect(position); topToolbarRect.position = Vector2.zero; topToolbarRect.size -= new Vector2(10, 0); topToolbarRect.height = toolbarHeight.y; XGUI.ResetToStyle(null); XGUI.BeginArea(new Rect(0, 0, position.width - 10, TOOLBAR_HEIGHT)); XGUI.BeginHorizontal(); var oldGraph = Graph; XGUI.ResetToStyle(null); XGUI.BeginVertical(); XGUI.FlexibleSpace(); Graph = XGUI.ObjectField(Graph, false); if (Graph != oldGraph) { CenterView(); } XGUI.FlexibleSpace(); XGUI.EndVertical(); XGUI.FlexibleSpace(); XGUI.ResetToStyle(GUI.skin.button); if (XGUI.Button("Variables")) { VariablesEditor.Launch(this); } XGUI.EndHorizontal(); XGUI.EndArea(); // Bottom Toolbar XGUI.ResetToStyle(null); XGUI.BeginArea(new Rect(0, position.size.y - TOOLBAR_HEIGHT, position.width - 10, TOOLBAR_HEIGHT)); XGUI.BeginHorizontal(); XGUI.ResetToStyle(GUI.skin.button); XGUI.Enabled = Graph != null; snap = XGUI.ToggleButton(snap, "Snap"); XGUI.ResetToStyle(GUI.skin.button); XGUI.Enabled = Graph != null; if (XGUI.Button("Center View")) { CenterView(); } XGUI.FlexibleSpace(); if (graphRect.Contains(mousePos)) { XGUI.ResetToStyle(GUI.skin.label); XGUI.Alignment = TextAnchor.MiddleRight; XGUI.Label( string.Format("{0}, {1}", GraphPosition.x, GraphPosition.y), XGUI.ExpandHeight(true)); } XGUI.EndHorizontal(); XGUI.EndArea(); // Draw the graph { XGUI.ResetToStyle(null); XGUI.BackgroundColor = Skin.canvasColor; XGUI.Normal.background = flatTexture; XGUI.Box(graphRect); // Make the clipping window for the graph graphRect.position += Vector2.one * GRAPH_PADDING; graphRect.size -= Vector2.one * GRAPH_PADDING * 2; XGUI.ResetToStyle(null); XGUI.BeginClip(graphRect); // Draw the graph var gridRect = new Rect(Vector2.zero, graphRect.size); DrawGrid(gridRect); if (Graph != null && Graph.Nodes != null) { // Make a copy since nodes may reorder the list when drawn var nodes = new List <Node>(Graph.Nodes); // Draw nodes foreach (var node in nodes) { NodeEditor.DrawNode(this, node); } // Draw links if (Target is Socket) { var socket = (Socket)Target; if (rectCache.ContainsKey(socket)) { DrawConnection(rectCache[socket].center, Event.current.mousePosition, socket.IsInput(Graph), true, Skin.tempLinkColor); } } foreach (var link in Graph.Links) { if (!rectCache.ContainsKey(link.FromSocket) || !rectCache.ContainsKey(link.ToSocket)) { continue; } var from = rectCache[link.FromSocket].center; var to = rectCache[link.ToSocket].center; var socketType = link.FromSocket.GetSocketType(Graph); var color = Skin.objectSocketColor; if (socketType == typeof(ExecType)) { color = Skin.execSocketColor; } if (socketType.IsPrimitive) { color = Skin.primitiveSocketColor; } if (search.IsOpen) { color = Skin.TintColor(color, Skin.disabledSocketTint); } DrawConnection(from, to, false, false, color); } } // Draw Tooltip if (Tooltip != null) { Tooltip.OnGUI(); } // Search box search.OnGUI(this); GUI.EndClip(); } if (Graph == null) { CenterViewOn(Vector2.zero); var menuRect = new Rect(); menuRect.size = new Vector2(300, 200); menuRect.center = graphRect.center; GUI.Box(menuRect, GUIContent.none); GUILayout.BeginArea(menuRect); GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(GUILayout.Height(150)); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(GUILayout.Width(250)); GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); var size = GUI.skin.label.fontSize; var alignment = GUI.skin.label.alignment; GUI.skin.label.fontSize = 20; GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label("Leylines"); GUI.skin.label.fontSize = size; GUI.skin.label.alignment = alignment; GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(GUILayout.Height(130)); var rich = GUI.skin.label.richText; GUI.skin.label.richText = true; GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label("<b>No Graph Loaded</b>"); GUI.skin.label.richText = rich; GUI.skin.label.alignment = alignment; GUILayout.EndVertical(); GUILayout.EndVertical(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.EndArea(); } switch (Event.current.type) { case EventType.MouseDown: Target = this; GUI.FocusControl(null); Event.current.Use(); break; case EventType.MouseDrag: if (Graph == null) { break; } if (ReferenceEquals(Target, this)) { Offset += Event.current.delta; Event.current.Use(); } break; case EventType.MouseUp: if (ReferenceEquals(Target, this)) { Target = null; GUI.FocusControl(null); } if (Target != null && Target.GetType() == typeof(Socket)) { var clipPos = Event.current.mousePosition; clipPos.y -= topToolbarRect.size.y + GRAPH_PADDING; var socket = (Socket)Target; if (socket.IsInput(Graph)) { search.SetWantedOutputContext(this, socket); } else { search.SetWantedInputContext(this, socket); } search.Open(clipPos, GraphPosition, Graph.Policy, true); Target = search; GUI.FocusControl("search_field"); Event.current.Use(); } if (Event.current.button == 1 && Graph != null) { if (graphRect.Contains(Event.current.mousePosition)) { var clipPos = Event.current.mousePosition; clipPos.y -= topToolbarRect.size.y + GRAPH_PADDING; search.UnsetContext(); search.Open(clipPos, GraphPosition, Graph.Policy); Target = search; GUI.FocusControl("search_field"); Event.current.Use(); } } break; case EventType.DragUpdated: if (DragAndDrop.objectReferences.Length == 1) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; } else { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; } Event.current.Use(); break; case EventType.DragPerform: if (DragAndDrop.objectReferences.Length == 1) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; DragAndDrop.AcceptDrag(); var obj = DragAndDrop.objectReferences[0]; var type = obj.GetType(); var node = CreateInstance <DynamicNode>(); var socket = new DynamicSocket(type.Name, type, type.Name, SocketFlags.AllowMultipleLinks | SocketFlags.Editable); socket.SocketValue = obj; node.DisplayName = obj.GetType().Name; node.AddOutputSocket(socket); AddNode(node, GraphPosition); } else { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; } Event.current.Use(); break; } Repaint(); if (GUI.changed && Graph != null && !Graph.Equals(null)) { EditorUtility.SetDirty(Graph); } }
private bool DrawNodeResults (GraphEditor editor, string newSearchStr, bool keysUsed) { if (searchStr != newSearchStr || justOpened) { justOpened = false; if (searchJob != null) { searchJob.IsRunning = false; } // Define variables for capture var contextType = this.contextWantsType; var contextIsInput = this.contextWantsInput; var newResults = new SyncList <SearchResult>(); results = newResults; // Perform search searchJob = new Job((job) => { var scores = new List <int>(); int timeout = 0; int n = 0; while (job.IsRunning) { // Check if the search items have changed (and restart // the search if so) if (n > policy.SearchItems.Count) { scores.Clear(); newResults.Clear(); n = 0; } // Get the next item, if available if (n == policy.SearchItems.Count) { if (timeout > 0) { break; } timeout++; Thread.Sleep(1000); continue; } timeout = 0; var item = policy.SearchItems[n++]; if (contextType != null) { if (!item.MatchesContext(contextIsInput, contextType)) { continue; } } // Score the item and insert it var score = FuzzySearch(newSearchStr, item.Label); if (score == int.MinValue) { continue; } int i = 0; for (; i < scores.Count; ++i) { if (score > scores[i] || (score == scores[i] && item.Label.Length < newResults[i].Label.Length) ) { scores.Insert(i, score); newResults.Insert(i, item); break; } } if (i == scores.Count) { scores.Add(score); newResults.Add(item); } } }).Start(); } searchStr = newSearchStr; // Update the count if (Event.current.type != EventType.Repaint && Event.current.type != EventType.ExecuteCommand) { resultCount = results == null ? 0 : results.Count; } selected = Mathf.Clamp(selected, 0, resultCount - 1); if (keysUsed) { if (selected > Mathf.FloorToInt(scrollPos) + 11) { scrollPos = selected - 11; } else if (selected < scrollPos) { scrollPos = selected; } } scrollPos = Mathf.Clamp(scrollPos, 0, Mathf.Max(0, resultCount - 12)); XGUI.ResetToStyle(null); XGUI.BeginHorizontal(); XGUI.BeginVertical(); // Show results int index = Mathf.Clamp((int)scrollPos, 0, resultCount); bool hoveringOnResult = false; for (int i = index; i < Mathf.Min(index + 12, resultCount); ++i) { var result = results[i]; XGUI.ResetToStyle(GUI.skin.label); if (i == selected) { XGUI.Normal.background = GetHighlightTex(); } XGUI.BeginHorizontal(); XGUI.ResetToStyle(GUI.skin.label); if (i == selected) { XGUI.Normal.textColor = Color.white; } XGUI.RichText = true; XGUI.Alignment = TextAnchor.MiddleLeft; var score = "" + FuzzySearch(searchStr, result.Label); var highlight = FuzzyHighlight(searchStr, result.Label); XGUI.Label(score, XGUI.Width(30)); XGUI.Label(highlight, XGUI.ExpandWidth(true)); XGUI.EndHorizontal(); var lastRect = GUILayoutUtility.GetLastRect(); if (lastRect.Contains(Event.current.mousePosition)) { if (Event.current.type == EventType.MouseMove) { selected = i; Event.current.Use(); } hoveringOnResult = selected == i; } } // No results if (resultCount == 0) { XGUI.ResetToStyle(GUI.skin.label); XGUI.Alignment = TextAnchor.LowerCenter; XGUI.Enabled = false; XGUI.FontStyle = FontStyle.Italic; XGUI.Label("No results", XGUI.MaxHeight(30)); } XGUI.EndVertical(); scrollPos = GUILayout.VerticalScrollbar (scrollPos, Mathf.Min(resultCount, 12), 0, Mathf.Max(resultCount, 12), GUILayout.ExpandHeight(true)); XGUI.EndHorizontal(); switch (Event.current.type) { case EventType.ScrollWheel: scrollPos += Event.current.delta.y; Event.current.Use(); break; // Detect key events in the search field case EventType.Used: switch (Event.current.keyCode) { case KeyCode.KeypadEnter: case KeyCode.Return: SelectResult(editor, selected); Close(); break; } break; } return(hoveringOnResult); }
private void DrawVariableResults(GraphEditor editor) { var variables = editor.Graph.Variables; if (variables.AsList().Count == 0) { XGUI.ResetToStyle(GUI.skin.label); XGUI.Alignment = TextAnchor.LowerCenter; XGUI.Enabled = false; XGUI.FontStyle = FontStyle.Italic; XGUI.Label("No variables", XGUI.MaxHeight(30)); } else { varScrollPos = GUILayout.BeginScrollView(varScrollPos); foreach (var variable in variables) { XGUI.ResetToStyle(null); XGUI.BeginHorizontal(); XGUI.ResetToStyle(GUI.skin.button); if (XGUI.Button("Get", XGUI.Width(40))) { var node = ScriptableObject.CreateInstance <DynamicNode>(); node.name = "Get"; node.AddOutputSocket(new DynamicSocket( variable.Name, variable.Value.Type, variable.Name)); node.AddEvalInvoke(new EvalInvoke( variable.Name, variable.Name, variable.Name, InvokeType.GetVar)); editor.AddNode(node, spawnPosition); } if (XGUI.Button("Set", XGUI.Width(40))) { var node = ScriptableObject.CreateInstance <DynamicNode>(); node.name = "Set"; node.SetInputWidth(60); node.AddInputSocket(new DynamicSocket( "Exec", typeof(ExecType), "execIn")); node.AddInputSocket(new DynamicSocket( "Value", variable.Value.Type, "value", SocketFlags.Editable)); node.AddOutputSocket(new DynamicSocket( "Exec", typeof(ExecType), "execOut")); node.AddOutputSocket(new DynamicSocket( variable.Name, variable.Value.Type, variable.Name)); node.AddExecInvoke(new ExecInvoke( "execIn", "execOut", "newValue", variable.Name, variable.Name, InvokeType.SetVar)); editor.AddNode(node, spawnPosition); } XGUI.ResetToStyle(GUI.skin.label); XGUI.Label(variable.Name); XGUI.EndHorizontal(); } GUILayout.EndScrollView(); } }
public void OnGUI(GraphEditor editor) { if (editor.Target != this) { Close(); return; } if (!isOpen) { return; } GUI.enabled = true; var rect = new Rect(); rect.size = size; rect.center = position + new Vector2(0, rect.size.y / 2); XGUI.ResetToStyle(GUI.skin.box); XGUI.Normal.background = GraphEditor.boxTexture; XGUI.Box(rect); rect.position += Vector2.one * SEARCH_PADDING; rect.size -= Vector2.one * SEARCH_PADDING * 2; XGUI.ResetToStyle(null); XGUI.BeginArea(rect); XGUI.BeginVertical(); if (XEvent.IsKeyDown(KeyCode.Escape)) { Close(); XEvent.Use(); } // Search bar XGUI.BeginHorizontal(); XGUI.ResetToStyle(GUI.skin.button); var buttonString = searchNodes ? "Nodes" : "Variables"; if (XGUI.Button(buttonString, XGUI.Width(70))) { searchNodes = !searchNodes; } bool keysUsed = false; var newSearchStr = searchStr; if (searchNodes) { // Detect key events before the text field switch (Event.current.type) { case EventType.KeyDown: switch (Event.current.keyCode) { case KeyCode.UpArrow: selected--; Event.current.Use(); break; case KeyCode.DownArrow: selected++; Event.current.Use(); break; case KeyCode.Home: selected = 0; Event.current.Use(); break; case KeyCode.End: selected = int.MaxValue; Event.current.Use(); break; case KeyCode.PageUp: selected -= 11; Event.current.Use(); break; case KeyCode.PageDown: selected += 11; Event.current.Use(); break; } keysUsed = Event.current.type == EventType.Used; break; } XGUI.ResetToStyle(GUI.skin.textField); GUI.SetNextControlName("search_field"); newSearchStr = XGUI.TextField(searchStr); GUI.FocusControl("search_field"); var countStr = "" + resultCount; if (searchJob != null && searchJob.IsRunning) { countStr += "..."; } GUILayout.Label(countStr, GUILayout.ExpandWidth(false)); } GUILayout.EndHorizontal(); var hoveringOnResult = false; if (searchNodes) { hoveringOnResult = DrawNodeResults(editor, newSearchStr, keysUsed); } else { DrawVariableResults(editor); } GUILayout.EndVertical(); GUILayout.EndArea(); switch (Event.current.type) { case EventType.MouseDown: if (hoveringOnResult) { SelectResult(editor, selected); Close(); } else if (rect.Contains(Event.current.mousePosition)) { editor.Target = this; Event.current.Use(); } break; case EventType.MouseUp: if (rect.Contains(Event.current.mousePosition)) { editor.Target = this; Event.current.Use(); } break; } }
public static void DrawSocket (GraphEditor editor, Node node, Socket socket, Rect rect) { editor.rectCache[socket] = rect; var socketType = socket.GetSocketType(editor.Graph); var color = GraphEditor.Skin.objectSocketColor; var style = GraphEditor.Skin.paramSocketStyle; if (socketType == typeof(ExecType)) { color = GraphEditor.Skin.execSocketColor; style = GraphEditor.Skin.execSocketStyle; } else if (socketType.IsPrimitive) { color = GraphEditor.Skin.primitiveSocketColor; } var on = editor.Graph.Links.IsSocketLinkedTo(socket) || editor.Graph.Links.IsSocketLinkedFrom(socket); XGUI.ResetToStyle(null); XGUI.Normal.background = on ? style.onSocketTexture : style.offSocketTexture; XGUI.Color = on ? color : GraphEditor.Skin.TintColor(color, GraphEditor.Skin.offSocketTint); XGUI.Color = !editor.search.IsOpen ? XGUI.Color : GraphEditor.Skin.TintColor(XGUI.Color, GraphEditor.Skin.disabledSocketTint); XGUI.Box(rect); if (!GUI.enabled) { return; } switch (Event.current.type) { case EventType.MouseDown: if (rect.Contains(Event.current.mousePosition)) { if (Event.current.control) { editor.Graph.Links.RemoveAllWith(socket); } else { editor.Target = socket; } Event.current.Use(); } break; case EventType.MouseUp: if (!(editor.Target is Socket)) { break; } if (!rect.Contains(Event.current.mousePosition)) { break; } var otherSocket = (Socket)editor.Target; if (socket.Equals(otherSocket)) { editor.Target = null; break; } if (socket.NodeID == otherSocket.NodeID) { editor.Target = null; break; } var graph = editor.Graph; if (socket.IsInput(graph) == otherSocket.IsInput(graph)) { editor.Target = null; break; } if (socket.GetSocketType(graph) != otherSocket.GetSocketType(graph)) { if (!socket.GetSocketType(graph) .IsAssignableFrom(otherSocket.GetSocketType(graph))) { editor.Target = null; break; } } // Record to graph Undo.RegisterCompleteObjectUndo(graph, string.Format("Link {0} and {1}", socket, otherSocket ) ); if (!socket.GetFlags(graph).AllowMultipleLinks()) { graph.Links.RemoveAllWith(socket); } if (!otherSocket.GetFlags(graph).AllowMultipleLinks()) { graph.Links.RemoveAllWith(otherSocket); } graph.Links.Add(graph, socket, otherSocket); editor.Target = null; GUI.changed = true; Event.current.Use(); break; } }