Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
        public void useNode(SequenceNode c)
        {
            if (c.Content != null)
            {
                c.Content = null;
            }

            c.ChildSlots = 0;

            node = c;
        }
Ejemplo n.º 3
0
 public override ISequenceInterpreter createSequenceInterpreterFor(SequenceNode node)
 {
     foreach (ISequenceInterpreter si in sequenceInterpreters)
     {
         if (si.CanHandle(node))
         {
             return(si.Clone());
         }
     }
     return(null);
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public override bool RemoveNode(SequenceNode node)
        {
            var r = base.RemoveNode(node);

                        #if UNITY_EDITOR
            if (r)
            {
                UnityEditor.AssetDatabase.SaveAssets();
            }
                        #endif

            return(r);
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
        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);
            }
        }
Ejemplo n.º 10
0
        public override int NodeEditorIndex(SequenceNode node)
        {
            int i = 0;

            foreach (NodeEditor nodeEditor in nodeEditors)
            {
                if (nodeEditor.manages(node))
                {
                    return(i);
                }
                else
                {
                    i++;
                }
            }

            return(0);
        }
Ejemplo n.º 11
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);
                    }
                }
            }
        }
Ejemplo n.º 12
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 13
0
 public void UseNode(SequenceNode node)
 {
     this.node    = node;
     this.content = node.Content as ISimpleContent;
 }
Ejemplo n.º 14
0
 public SequenceInterpreter(Sequence sequence)
 {
     this.sequence = sequence;
     currentNode   = sequence.Root;
 }
Ejemplo n.º 15
0
 public bool manages(SequenceNode c)
 {
     return(c.Content != null && c.Content is SerializableGameEvent);
 }
Ejemplo n.º 16
0
 public bool manages(SequenceNode c)
 {
     return(c.Content == null);
 }
Ejemplo n.º 17
0
 public bool CanHandle(SequenceNode node)
 {
     return(node != null && node.Content != null && (node.Content is Dialog || node.Content is Options));
 }
Ejemplo n.º 18
0
 public bool manages(SequenceNode c)
 {
     return(c.Content != null && c.Content is Object);
 }
Ejemplo n.º 19
0
 public abstract ISequenceInterpreter createSequenceInterpreterFor(SequenceNode node);
Ejemplo n.º 20
0
 public void UseNode(SequenceNode node)
 {
     this.node = node;
 }
Ejemplo n.º 21
0
        /********************
        * 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();
        }
Ejemplo n.º 22
0
 public void UseNode(SequenceNode node)
 {
     this.node = node;
     launched  = false;
     chosen    = -1;
 }
Ejemplo n.º 23
0
 public bool CanHandle(SequenceNode node)
 {
     return(node.Content is ISimpleContent);
 }
Ejemplo n.º 24
0
        public void Tick()
        {
            if (node.Content is Dialog)
            {
                Dialog dialog = node.Content as Dialog;
                if (!launched)
                {
                    fragments = new Queue <Fragment>(dialog.Fragments);
                    launched  = true;
                    next      = true;
                    chosen    = -1;
                }
                if (next)
                {
                    if (fragments.Count > 0)
                    {
                        // Launch next fragment event
                        var nextFragment = fragments.Dequeue().Clone();

                        // Parse the formulas
                        nextFragment.Name      = ParseFormulas(nextFragment.Name);
                        nextFragment.Parameter = ParseFormulas(nextFragment.Parameter);
                        nextFragment.Character = ParseFormulas(nextFragment.Character);
                        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;

                    // 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;
                if (node.Childs.Length > chosen)
                {
                    nextNode = node.Childs[chosen];
                }
                chosen = -1;
            }
        }
Ejemplo n.º 25
0
 public bool manages(SequenceNode c)
 {
     return(c.Content != null && c.Content is Dialog);
 }
Ejemplo n.º 26
0
 public bool CanHandle(SequenceNode node)
 {
     return(node != null && node.Content != null && node.Content is Checkable);
 }
Ejemplo n.º 27
0
 public abstract int NodeEditorIndex(SequenceNode node);
Ejemplo n.º 28
0
        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;
            }
        }
Ejemplo n.º 29
0
 public bool CanHandle(SequenceNode node)
 {
     return(node != null && node.Content != null && node.Content is IGameEvent);
 }