void DoChildSelector(int id) { var myNode = nodes[id]; switch (Event.current.type) { case EventType.MouseDown: // Right Button if (Event.current.button == 1) { var menu = new GenericMenu(); var i = 0; string text = string.Empty; menu.AddItem(new GUIContent("Set sequence root"), false, (node) => sequence.Root = node as SequenceNode, myNode); foreach (var a in editors[myNode].ChildNames) { text = (a == "") ? (i + "") : a; menu.AddItem(new GUIContent("Set node for " + text), false, (t) => { // Detach myNode.Childs [(int)t] = null; lookingChildNode = myNode; lookingChildSlot = (int)t; }, i); i++; } menu.ShowAsContext(); } break; } }
public void useNode(SequenceNode c) { node = c; attr = c.Content.GetType().GetCustomAttributes(true).ToList().Find(a => a is NodeContentAttribute) as NodeContentAttribute; node.Name = attr != null ? attr.Name : node.Content.GetType().ToString(); editor = Editor.CreateEditor(c.Content as Object); }
/********************** * Node windows *********************/ void NodeWindow(int id) { SequenceNode myNode = nodes[id]; // Editor selection DoContentEditor(id); switch (Event.current.type) { case EventType.MouseMove: if (new Rect(0, 0, myNode.Position.width, myNode.Position.height).Contains(Event.current.mousePosition)) { if (hovering != id) { this.Repaint(); } hovering = id; hoveringNode = myNode; } break; } DoChildSelector(id); DoNodeWindowEditorSelection(id); DoResizeEditorWindow(id); GUI.DragWindow(); }
public void Tick() { if (!SequenceFinished) { if (currentInterpreter == null) { currentInterpreter = SequenceInterpreterFactory.Intance.createSequenceInterpreterFor(currentNode); currentInterpreter.UseNode(currentNode); } Sequence.current = sequence; currentInterpreter.Tick(); Sequence.current = null; if (currentInterpreter.HasFinishedInterpretation()) { currentNode = abort ? null : currentInterpreter.NextNode(); if (currentInterpreter is Object) { Object.DestroyImmediate(currentInterpreter as Object); } currentInterpreter = null; } } }
public void Abort(bool instant = false) { abort = true; if (instant) { currentNode = null; currentInterpreter = null; } }
public override ISequenceInterpreter createSequenceInterpreterFor(SequenceNode node) { foreach (ISequenceInterpreter si in sequenceInterpreters) { if (si.CanHandle(node)) { return(si.Clone()); } } return(null); }
public void useNode(SequenceNode c) { if (c.Content != null) { c.Content = null; } c.ChildSlots = 0; node = c; }
public virtual bool RemoveNode(string id) { var contains = nodeDict.ContainsKey(id); if (contains) { var node = nodeDict[id]; nodeDict.Remove(id); SequenceNode.DestroyImmediate(node, true); } return(contains); }
public override bool RemoveNode(SequenceNode node) { var r = base.RemoveNode(node); #if UNITY_EDITOR if (r) { UnityEditor.AssetDatabase.SaveAssets(); } #endif return(r); }
public void useNode(SequenceNode c) { if (c.Content == null || !(c.Content is SerializableGameEvent)) { c.Content = ScriptableObject.CreateInstance <SerializableGameEvent> (); } var sge = c.Content as SerializableGameEvent; if (sge.Name == null) { sge.Name = ""; } this.node = c; }
public void useNode(SequenceNode c) { if (c.Content == null || !(c.Content is Dialog)) { c.Content = ScriptableObject.CreateInstance <Dialog>(); } myNode = c; editor = Editor.CreateEditor(c.Content as Dialog) as DialogEditor; // This could be used aswell, but I only advise this your class inherrits from UnityEngine.Object or has a CustomPropertyDrawer // Since you'll find your item using: serializedObject.FindProperty("list").GetArrayElementAtIndex(index).objectReferenceValue // which is a UnityEngine.Object // reorderableList = new ReorderableList(serializedObject, serializedObject.FindProperty("list"), true, true, true, true); }
public virtual bool RemoveNode(SequenceNode node) { var id = string.Empty; foreach (var kv in nodeDict) { if (kv.Value == node) { id = kv.Key; break; } } return(string.IsNullOrEmpty(id) ? false : RemoveNode(id)); }
private void findNodes(SequenceNode node, Dictionary <SequenceNode, bool> checkList) { if (node == null) { return; } if (checkList.ContainsKey(node)) { checkList[node] = true; } foreach (var c in node.Childs) { findNodes(c, checkList); } }
public override int NodeEditorIndex(SequenceNode node) { int i = 0; foreach (NodeEditor nodeEditor in nodeEditors) { if (nodeEditor.manages(node)) { return(i); } else { i++; } } return(0); }
void drawLines(Rect from, SequenceNode to, Color c, Color notHoveringColor, bool parentHovered = false) { if (to == null) { return; } var hoveringMe = hoveringNode != null && hoveringNode == to; var useColor = parentHovered || hoveringNode == null || hoveringMe ? c : notHoveringColor; // Visible loop line if (from.width != -1 && from.height != -1) { curveFromTo(from, to.Position, useColor); } if (!loopCheck.ContainsKey(to)) { loopCheck.Add(to, true); float h = to.Position.height / (to.Childs.Length * 1.0f); for (int i = 0; i < to.Childs.Length; i++) { Rect fromRect = sumRect(to.Position, new Rect(0, h * i, 0, h - to.Position.height)); // Looking child line if (lookingChildNode == to && i == lookingChildSlot) { if (hovering != -1) { curveFromTo(fromRect, nodes[hovering].Position, useColor); } else { curveFromTo(fromRect, new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 1, 1), useColor); } } else { drawLines(fromRect, to.Childs[i], c, notHoveringColor, hoveringMe); } } } }
void drawSlots(Sequence sequence) { // Draw the rest of the lines in red foreach (var n in sequence.Nodes) { // InputSlot drawSlot(new Vector2(n.Position.x, n.Position.y + 3 + n.Position.height / 2)); // OutputSlots float h = n.Position.height / (n.Childs.Length * 1.0f); for (int i = 0; i < n.Childs.Length; i++) { if (drawSlot(new Vector2(n.Position.x + n.Position.width, n.Position.y + h * i + h / 2f))) { // Detach n.Childs[i] = null; lookingChildNode = n; lookingChildSlot = i; } } } }
public bool CanHandle(SequenceNode node) { return(node != null && node.Content != null && (node.Content is Dialog || node.Content is Options)); }
public bool manages(SequenceNode c) { return(c.Content != null && c.Content is SerializableGameEvent); }
public bool manages(SequenceNode c) { return(c.Content == null); }
public bool CanHandle(SequenceNode node) { return(node != null && node.Content != null && node.Content is Checkable); }
public void UseNode(SequenceNode node) { this.node = node; }
public bool CanHandle(SequenceNode node) { return(node != null && node.Content != null && node.Content is IGameEvent); }
/******************** * GRAPH * ******************/ void DoGraph(Rect rect) { float maxX = rect.width, maxY = rect.height; foreach (var node in sequence.Nodes) { var px = node.Position.x + node.Position.width + 50; var py = node.Position.y + node.Position.height + 50; maxX = Mathf.Max(maxX, px); maxY = Mathf.Max(maxY, py); } scrollRect = new Rect(0, 0, maxX, maxY); scroll = GUI.BeginScrollView(rect, scroll, scrollRect); // Clear mouse hover if (Event.current.type == EventType.MouseMove) { if (hovering != -1) { this.Repaint(); } hovering = -1; hoveringNode = null; } GUI.Box(scrollRect, "", "preBackground"); drawBackground(scrollRect); BeginWindows(); { nodes.Clear(); createWindows(sequence); if (Event.current.type == EventType.Repaint) { foreach (var n in selection) { GUI.Box(new Rect( n.Position.position - new Vector2(0, 0), n.Position.size + new Vector2(0, 0)), "", selectedStyle); } } drawSlots(sequence); if (Event.current.type == EventType.Repaint) { drawLines(sequence); } } EndWindows(); switch (Event.current.type) { case EventType.MouseMove: if (lookingChildNode != null) { this.Repaint(); Event.current.Use(); } break; case EventType.MouseDrag: { if (EditorGUIUtility.hotControl == 0) { scroll -= Event.current.delta; Repaint(); } } break; case EventType.MouseDown: { if (Event.current.button == 0) { // Selecting if (GUIUtility.hotControl == 0) { // Start selecting GUIUtility.hotControl = this.GetHashCode(); startPoint = Event.current.mousePosition; selection.Clear(); Event.current.Use(); } } } break; case EventType.MouseUp: { if (Event.current.button == 0) { if (GUIUtility.hotControl == this.GetHashCode()) { GUIUtility.hotControl = 0; UpdateSelection(); Event.current.Use(); } } else if (Event.current.button == 1) { // Right click var menu = new GenericMenu(); var mousePos = Event.current.mousePosition; int i = 0; foreach (var a in GetPossibleCreations()) { menu.AddItem(new GUIContent("Create/" + a.Key), false, (t) => { var kv = (KeyValuePair <string, Type>)t; var newObject = CreateInstance(kv.Value); var child = sequence.CreateNode(newObject); child.Position = new Rect(mousePos, child.Position.size); }, a); i++; } menu.ShowAsContext(); } } break; case EventType.Repaint: // Draw selection rect if (GUIUtility.hotControl == GetHashCode()) { UpdateSelection(); Handles.BeginGUI(); Handles.color = Color.white; Handles.DrawSolidRectangleWithOutline( Rect.MinMaxRect(startPoint.x, startPoint.y, Event.current.mousePosition.x, Event.current.mousePosition.y), new Color(.3f, .3f, .3f, .3f), Color.gray); Handles.EndGUI(); } break; } GUI.EndScrollView(); }
public abstract ISequenceInterpreter createSequenceInterpreterFor(SequenceNode node);
public void UseNode(SequenceNode node) { this.node = node; launched = false; chosen = -1; }
public void UseNode(SequenceNode node) { this.node = node; this.content = node.Content as ISimpleContent; }
public void Tick() { if (node.Content is Dialog) { Dialog dialog = node.Content as Dialog; if (!launched) { wasLooking = CameraManager.Instance.Target; fragments = new Queue <Fragment>(dialog.Fragments); launched = true; next = true; chosen = -1; } if (next) { if (fragments.Count > 0) { if (fragments.Peek().Entity != null) { CameraManager.Instance.LookTo(fragments.Peek().Entity.gameObject); } // Launch next fragment event var nextFragment = fragments.Dequeue().Clone(); // Parse the formulas nextFragment.Name = ParseFormulas(nextFragment.Name); nextFragment.Msg = ParseFormulas(nextFragment.Msg); var ge = new GameEvent(); ge.name = "show dialog fragment"; ge.setParameter("fragment", nextFragment); ge.setParameter("launcher", this); ge.setParameter("synchronous", true); eventLaunched = ge; Game.main.enqueueEvent(ge); next = false; } else { chosen = 0; } } } else if (node.Content is Options) { if (!launched) { chosen = -1; Options options = (node.Content as Options).Clone() as Options; wasLooking = CameraManager.Instance.Target; // Launch options event var ge = new GameEvent(); ge.name = "show dialog options"; optionsList = options.Values; launchedOptionsList = optionsList.FindAll(o => o.Fork == null || o.Fork.check()); // Parse the formulas options.Question = ParseFormulas(options.Question); launchedOptionsList.ForEach(o => o.Parameter = ParseFormulas(o.Parameter)); launchedOptionsList.ForEach(o => o.Text = ParseFormulas(o.Text)); ge.setParameter("options", launchedOptionsList); ge.setParameter("message", options.Question); ge.setParameter("launcher", this); ge.setParameter("synchronous", true); eventLaunched = ge; Game.main.enqueueEvent(ge); launched = true; } } if (chosen != -1) { finished = true; CameraManager.Instance.LookTo(wasLooking); if (node.Childs.Length > chosen) { nextNode = node.Childs[chosen]; } chosen = -1; } }
public abstract int NodeEditorIndex(SequenceNode node);
public bool CanHandle(SequenceNode node) { return(node.Content is ISimpleContent); }
void DoNodeWindowEditorSelection(int id) { var myNode = nodes[id]; switch (Event.current.type) { case EventType.MouseDown: // Left button if (Event.current.button == 0) { if (hovering == id) { toSelect = false; focusing = hovering; if (Event.current.control) { if (selection.Contains(myNode)) { selection.Remove(myNode); } else { selection.Add(myNode); } } else { toSelect = true; if (!selection.Contains(myNode)) { selection.Clear(); selection.Add(myNode); } } } if (lookingChildNode != null) { // link creation between nodes lookingChildNode.Childs[lookingChildSlot] = myNode; // finishing search lookingChildNode = null; } if (myNode.Content is UnityEngine.Object) { Selection.activeObject = myNode.Content as UnityEngine.Object; } } break; case EventType.MouseDrag: toSelect = false; break; case EventType.MouseUp: { if (toSelect) { selection.Clear(); selection.Add(myNode); } } break; } }