public static void DrawArrowCurve(Rect start, Rect end, NodeMachineEditor editor) { Vector3 startPos = new Vector3(start.x + start.width, start.y + start.height / 2, 0); Vector3 endPos = new Vector3(end.x, end.y + end.height / 2, 0); Vector3 startTan = startPos + Vector3.right * 50; Vector3 endTan = endPos + Vector3.left * 50; Handles.DrawBezier(startPos, endPos, startTan, endTan, Color.white, null, 5); GUI.DrawTexture(new Rect(endPos.x - 6, endPos.y - 10 / 2, 10, 10), arrowCapTex, ScaleMode.StretchToFill); }
public static void DrawMachineNoModelScreen(NodeMachineEditor editor) { GUILayout.BeginArea(new Rect(0, 0, editor.position.width, editor.position.height)); GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label(editor._selectedMachine?.name + " has no assigned model", _nothingOpenStyle); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.EndArea(); }
public static void DrawNothingOpenScreen(NodeMachineEditor editor) { GUILayout.BeginArea(new Rect(0, 0, editor.position.width, editor.position.height)); GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("Open a NodeMachine Model to start", _nothingOpenStyle); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.EndArea(); }
public static bool OnOpenAsset(int instanceID, int line) { string assetPath = AssetDatabase.GetAssetPath(instanceID); NodeMachineModel model = AssetDatabase.LoadAssetAtPath <NodeMachineModel>(assetPath); if (model != null) { model.ReloadModel(); NodeMachineEditor window = (NodeMachineEditor)EditorWindow.GetWindow(typeof(NodeMachineEditor)); window.LoadModel(model); NodeMachineEditor.ShowWindow(window); return(true); } return(false); //let unity open it. }
// TODO: needed? /* * public static void DrawArrow(Rect start, Rect end, bool programmatic, NodeMachineEditor editor) * { * Vector3 startPos = new Vector3(start.x + start.width / 2, start.y + start.height / 2, 0); * Vector3 endPos = new Vector3(end.x + end.width / 2, end.y + end.height / 2, 0); * Vector2 arrowPos = new Vector2((endPos.x - startPos.x) / 2 + startPos.x, (endPos.y - startPos.y) / 2 + startPos.y); * Handles.color = Color.white; * if (programmatic) * Handles.DrawAAPolyLine(programmaticLineTex, 5f, startPos, endPos); * else * Handles.DrawAAPolyLine(5f, startPos, endPos); * float xDis = endPos.x - startPos.x; * float yDis = endPos.y - startPos.y; * float arrowAngle = Mathf.Rad2Deg * Mathf.Atan2(yDis, xDis); * GUIUtility.RotateAroundPivot(arrowAngle, arrowPos); * GUI.DrawTexture(new Rect(arrowPos.x - 5, arrowPos.y - 5, 10, 10), arrowCapTex, ScaleMode.StretchToFill); * GUIUtility.RotateAroundPivot(-arrowAngle, arrowPos); * }*/ public static void DrawArrow(Rect start, Vector2 end, NodeMachineEditor editor) { Vector3 startPos = new Vector3(start.x + start.width / 2, start.y + start.height / 2, 0); Vector3 endPos = new Vector3(end.x, end.y, 0); Handles.color = Color.white; Handles.DrawAAPolyLine(5f, startPos, endPos); float xDis = endPos.x - startPos.x; float yDis = endPos.y - startPos.y; float arrowAngle = Mathf.Rad2Deg * Mathf.Atan2(yDis, xDis); GUIUtility.RotateAroundPivot(arrowAngle, end); GUI.DrawTexture(new Rect(endPos.x - 6, endPos.y - 10 / 2, 10, 10), arrowCapTex, ScaleMode.StretchToFill); GUIUtility.RotateAroundPivot(-arrowAngle, end); }
public ConditionNodeGUIContent(ConditionNode node, NodeMachineEditor editor) : base(node, editor) { List <Condition.Comparison> comparisonEnums = new List <Condition.Comparison>(); foreach (Condition.Comparison comparison in (Condition.Comparison[])Enum.GetValues(typeof(Condition.Comparison))) { comparisonEnums.Add(comparison); } _comparisons = new string[comparisonEnums.Count]; for (int i = 0; i < _comparisons.Length; i++) { _comparisons[i] = comparisonEnums[i].ToString(); } shrinkTextWithZoom = true; }
/// <summary> /// Draws a transparent link between 2 nodes. /// </summary> /// <param name="link">The link to draw.</param> /// <param name="active">For live preview: true if the link is currently in use.</param> /// <param name="editor">The <c>NodeMachineEditor</c> to draw to.</param> public static void DrawTransparentLink(Link link, bool active, NodeMachineEditor editor) { if (!editor._model.GetNodeFromID(link._from).visible || !editor._model.GetNodeFromID(link._to).visible) { if (!editor._showInivisibleNodes) { return; } } Rect start = editor._model.GetNodeFromID(link._from).drawnTransform; Rect end = editor._model.GetNodeFromID(link._to).drawnTransform; start.position -= editor._nodeEditor.position; end.position -= editor._nodeEditor.position; float dirOffset = start.y > end.y ? -15 / editor._zoom : 15 / editor._zoom; Vector3 startPos = new Vector3(start.x + start.width / 2 + dirOffset, start.y + start.height / 2, 0); Vector3 endPos = new Vector3(end.x + end.width / 2 + dirOffset, end.y + end.height / 2, 0); Vector2 arrowPos = new Vector2((endPos.x - startPos.x) / 2 + startPos.x, (endPos.y - startPos.y) / 2 + startPos.y); Handles.color = Color.white; Handles.DrawAAPolyLine(whiteLineTex_t, 5f, startPos, endPos); Rect transform = new Rect(arrowPos.x - (25 / 2), arrowPos.y - (25 / 2), 25f, 25f); link._transform = new Rect(transform.position + editor._nodeEditor.position, transform.size); GUIStyle style = _linkBoxStyle_t; if (active) { style = _linkBoxStyleClicked_t; } GUI.Box(transform, "", style); float xDis = endPos.x - startPos.x; float yDis = endPos.y - startPos.y; float arrowAngle = Mathf.Rad2Deg * Mathf.Atan2(yDis, xDis); GUIUtility.RotateAroundPivot(arrowAngle, arrowPos); GUI.DrawTexture(new Rect(arrowPos.x - 5, arrowPos.y - 5, 10, 10), arrowCapTex_t, ScaleMode.StretchToFill); GUIUtility.RotateAroundPivot(-arrowAngle, arrowPos); }
public ElseNodeGUIContent(ElseNode node, NodeMachineEditor editor) : base(node, editor) { this.text = "else"; this.shrinkTextWithZoom = true; }
public NodeMenuItem[] AddNodeMenuItems(NodeMachineModel model, Vector2 mousePosition, NodeMachineEditor editor) { HashSet <Type> types = StateNodeMenuHandler.LoadStateTypes(model); HashSet <NodeMenuItem> menuItems = new HashSet <NodeMenuItem>(); int eventCount = 0; foreach (Type type in types) { foreach (MethodInfo method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { EventAttribute methodEventInfo = method.GetCustomAttribute <EventAttribute>(); if (methodEventInfo != null) { eventCount++; menuItems.Add(new NodeMenuItem("Events/" + type.ToString() + "/" + method.Name, () => { EventNode node = new EventNode(type, method.Name, model, mousePosition); editor.AddNode(node); }, false, false)); } } } if (eventCount == 0) { menuItems.Add(new NodeMenuItem("Events", null, false, true)); } return(menuItems.ToArray()); }
public FunctionNodeGUIContent(FunctionNode node, NodeMachineEditor editor) : base(node, editor) { }
public NodeMenuItem[] AddNodeMenuItems(NodeMachineModel model, Vector2 mousePosition, NodeMachineEditor editor) { HashSet <Type> types = LoadStateTypes(model); HashSet <NodeMenuItem> menuItems = new HashSet <NodeMenuItem>(); int stateCount = 0; foreach (Type type in types) { foreach (MethodInfo method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { StateAttribute methodStateInfo = method.GetCustomAttribute <StateAttribute>(); if (methodStateInfo != null) { if (!methodStateInfo.Visible) { continue; } stateCount++; bool runOnEncounter = methodStateInfo.RunOnEncounter; menuItems.Add(new NodeMenuItem("States/" + type.ToString() + "/" + method.Name, () => { StateNode node = new StateNode(type, method.Name, model, mousePosition); node.runOnEncounter = runOnEncounter; editor.AddNode(node); }, false, false)); } } } if (stateCount == 0) { menuItems.Add(new NodeMenuItem("States", null, false, true)); } return(menuItems.ToArray()); }
public StateNodeGUIContent(StateNode node, NodeMachineEditor editor) : base(node, editor) { }
public EventNodeGUIContent(EventNode node, NodeMachineEditor editor) : base(node, editor) { }
public NodeMenuItem[] AddNodeMenuItems(NodeMachineModel model, Vector2 mousePosition, NodeMachineEditor editor) { NodeMenuItem menuItem; if (model.machinePropsSchema.Count > 0) { menuItem = new NodeMenuItem("Conditional/Condition", () => { // TODO : CONDITIONS AND PROPERTIES WITH NO STANDARD TYPES??? KeyValuePair <string, Type> kvp = model.machinePropsSchema.First(); Condition.ConditionType?tryParseType = Condition.ParseConditionType(kvp.Value); if (tryParseType == null) { EditorUtility.DisplayDialog("Error", "There was an error while creating the condition!", "OK"); return; } Condition.ConditionType fieldType = (Condition.ConditionType)tryParseType; string fieldName = kvp.Key; Condition condition = new Condition(fieldName, fieldType, Condition.Comparison.EQUAL, Condition.GetDefaultValue(fieldType, kvp.Value)); ConditionNode node = new ConditionNode(editor._model, condition, mousePosition); editor.AddNode(node); }, false, false); } else { menuItem = new NodeMenuItem("Conditional/Condition", null, false, true); } NodeMenuItem[] menuItems = { menuItem }; return(menuItems); }
public DebugNodeGUIContent(DebugNode node, NodeMachineEditor editor) : base(node, editor) { }
/// <summary> /// Draws a node to the editor. /// </summary> /// <param name="node">The node to draw.</param> /// <param name="editor">The <c>NodeMachineEditor</c> to draw to.</param> public static bool DrawNode(Node node, NodeMachineEditor editor, Event e) { return(DrawNode(node, null, editor, e)); }
public NodeMenuItem[] AddNodeMenuItems(NodeMachineModel model, Vector2 mousePosition, NodeMachineEditor editor) { return(null); }
/// <summary> /// Draws a node to the editor. /// </summary> /// <param name="node">The node to draw.</param> /// <param name="overrideBackground">If set, the node will be drawn with the given texture path instead of the one given by the node.</param> /// <param name="editor">The <c>NodeMachineEditor</c> to draw to.</param> public static bool DrawNode(Node node, string overrideBackground, NodeMachineEditor editor, Event e) { if (!node.visible) { if (!editor._showInivisibleNodes) { return(false); } } Vector2 drawnNodePos = (node.transform.position / editor._zoom) + editor._offset; Rect nodeRect = new Rect( drawnNodePos.x, drawnNodePos.y, node.transform.width / editor._zoom, node.transform.height / editor._zoom); nodeRect.position -= new Vector2(nodeRect.width / 2, nodeRect.height / 2); GUIStyle style = _stateNodeStyle; string background = overrideBackground == null || overrideBackground == "" ? node.background : overrideBackground; if (!cachedBackgrounds.ContainsKey(background)) { cachedBackgrounds.Add(background, EditorGUIUtility.Load(background) as Texture2D); } style.normal.background = cachedBackgrounds[background]; /* * string title = ""; * if (node is StateNode) { * title = (node as StateNode).ToString(); * } */ NodeGUIContent nodeGUIContent = null; if (cachedNodeGUIContents.ContainsKey(node)) { nodeGUIContent = cachedNodeGUIContents[node]; } else { Type nodeType = node.GetType(); Assembly assembly = Assembly.Load("Assembly-CSharp-Editor"); Type guiContentType = assembly.GetTypes().Where(t => t.GetCustomAttribute <NodeGUIAttribute>()?.NodeType == nodeType && typeof(NodeGUIContent).IsAssignableFrom(t) ).LastOrDefault(); if (guiContentType != null) { nodeGUIContent = System.Activator.CreateInstance(guiContentType, new object[] { node, editor }) as NodeGUIContent; } cachedNodeGUIContents.Add(node, nodeGUIContent); } if (node is RunnableNode && EditorApplication.isPlaying && editor._selectedMachine != null) { if (editor._selectedMachine.CurrentRunnables.Contains(node)) { GUI.Box(nodeRect, nodeActive); } } int fontSize = 12; if (nodeGUIContent?.shrinkTextWithZoom == true) { style.fontSize = (int)Mathf.Round(fontSize / editor._zoom); } GUI.Box(nodeRect, (nodeGUIContent != null ? nodeGUIContent.text : node.ToString()), style); style.fontSize = fontSize; Rect drawnTransform = new Rect(); drawnTransform.position = nodeRect.position + editor._nodeEditor.position; drawnTransform.size = nodeRect.size; node.drawnTransform = drawnTransform; bool needsSaving = nodeGUIContent?.DrawContent(e) == true; if (node is RunnableNode && EditorApplication.isPlaying && editor._selectedMachine != null) { if (editor._selectedMachine.CurrentRunnables.Contains(node)) { GUI.DrawTexture(new Rect(nodeRect.position + new Vector2(12.5f, 12.5f), new Vector2(25, 25)), runningIconTex); } } return(needsSaving); }
public TriggerNodeGUIContent(TriggerNode node, NodeMachineEditor editor) : base(node, editor) { }
/// <summary> /// Draws a grid to the node editor. /// </summary> /// <param name="gridSpacingUnzoomed">The spacing between grid lines.</param> /// <param name="gridOpacity">The opacity to draw lines with.</param> /// <param name="gridColor">The color to draw lines with.</param> /// <param name="editor">The <c>NodeMachineEditor</c> to draw to.</param> public static void DrawGrid(float gridSpacingUnzoomed, float gridOpacity, Color gridColor, NodeMachineEditor editor) { float gridSpacing = gridSpacingUnzoomed / editor._zoom; int widthDivs = Mathf.CeilToInt(editor._nodeEditor.width / gridSpacing); int heightDivs = Mathf.CeilToInt(editor._nodeEditor.height / gridSpacing); Handles.BeginGUI(); Handles.color = new Color(gridColor.r, gridColor.g, gridColor.b, gridOpacity); Vector2 newOffset = new Vector3(editor._offset.x % gridSpacing, editor._offset.y % gridSpacing); for (int i = 0; i < widthDivs; i++) { DrawLine(new Vector2(gridSpacing * i, -gridSpacing) + newOffset, new Vector2(gridSpacing * i, editor.position.height) + newOffset); } for (int j = 0; j < heightDivs; j++) { DrawLine(new Vector2(-gridSpacing, gridSpacing * j) + newOffset, new Vector2(editor.position.width, gridSpacing * j) + newOffset); } // DEBUG code for offset positioning /* * Handles.color = Color.magenta; * DrawLine(new Vector2(editor._offset.x, editor.position.height / 2), new Vector2(editor.position.width / 2, editor.position.height / 2)); * * GUI.Label(new Rect((editor._offset.x + ((editor.position.width / 2) - editor._offset.x) / 2) - 50f, editor.position.height / 2 - 20f, 100f, 20f), ((editor.position.width / 2) - editor._offset.x).ToString()); * * Handles.color = Color.red; * DrawLine(new Vector2(editor.position.width / 2, 0), new Vector2(editor.position.width / 2, editor.position.height)); * * Handles.color = Color.blue; * DrawLine(new Vector2(editor._offset.x, 0), new Vector2(editor._offset.x, editor.position.height)); */ Handles.color = Color.white; Handles.EndGUI(); }
public EntryNodeGUIContent(EntryNode node, NodeMachineEditor editor) : base(node, editor) { text = "Entry"; }
public NodeGUIContent(Node node, NodeMachineEditor editor) { this._editor = editor; this._node = node; }