Beispiel #1
0
        protected virtual void DeleteBlock(Flowchart flowchart, IBlock block)
        {
            foreach (var command in block.CommandList)
            {
                Undo.DestroyObjectImmediate(command);
            }

            Undo.DestroyObjectImmediate((Block)block);
            flowchart.ClearSelectedCommands();
        }
Beispiel #2
0
        public static Block CreateBlock(Flowchart flowchart, Vector2 position)
        {
            Block newBlock = flowchart.CreateBlock(position);
            Undo.RegisterCreatedObjectUndo(newBlock, "New Block");
            ShowBlockInspector(flowchart);
            flowchart.selectedBlock = newBlock;
            flowchart.ClearSelectedCommands();

            return newBlock;
        }
Beispiel #3
0
        public static Block CreateBlock(Flowchart flowchart, Vector2 position)
        {
            Block newBlock = flowchart.CreateBlock(position);

            Undo.RegisterCreatedObjectUndo(newBlock, "New Block");
            ShowBlockInspector(flowchart);
            flowchart.SelectedBlock = newBlock;
            flowchart.ClearSelectedCommands();

            return(newBlock);
        }
Beispiel #4
0
 protected virtual void SelectBlock(Flowchart flowchart, Block block)
 {
     // Select the block and also select currently executing command
     ShowBlockInspector(flowchart);
     flowchart.SelectedBlock = block;
     flowchart.ClearSelectedCommands();
     if (block.ActiveCommand != null)
     {
         flowchart.AddSelectedCommand(block.ActiveCommand);
     }
 }
Beispiel #5
0
        Command AddNewCommand()
        {
            Flowchart flowchart = FlowchartWindow.GetFlowchart();

            if (flowchart == null)
            {
                return(null);
            }

            var block = flowchart.SelectedBlock;

            if (block == null)
            {
                return(null);
            }

            var newCommand = Undo.AddComponent <Comment>(block.gameObject) as Command;

            newCommand.ItemId = flowchart.NextItemId();
            flowchart.ClearSelectedCommands();
            flowchart.AddSelectedCommand(newCommand);

            return(newCommand);
        }
Beispiel #6
0
 protected virtual void DeleteBlock(Flowchart flowchart, Block block)
 {
     foreach (Command command in block.commandList)
     {
         Undo.DestroyObjectImmediate(command);
     }
     
     Undo.DestroyObjectImmediate(block);
     flowchart.ClearSelectedCommands();
 }
Beispiel #7
0
 protected virtual void SelectBlock(Flowchart flowchart, Block block)
 {
     // Select the block and also select currently executing command
     ShowBlockInspector(flowchart);
     flowchart.selectedBlock = block;
     flowchart.ClearSelectedCommands();
     if (block.activeCommand != null)
     {
         flowchart.AddSelectedCommand(block.activeCommand);
     }
 }
Beispiel #8
0
        protected virtual void DrawFlowchartView(Flowchart flowchart)
        {
            Block[] blocks = flowchart.GetComponents<Block>();

            foreach (Block block in blocks)
            {
                flowchart.scrollViewRect.xMin = Mathf.Min(flowchart.scrollViewRect.xMin, block.nodeRect.xMin - 400);
                flowchart.scrollViewRect.xMax = Mathf.Max(flowchart.scrollViewRect.xMax, block.nodeRect.xMax + 400);
                flowchart.scrollViewRect.yMin = Mathf.Min(flowchart.scrollViewRect.yMin, block.nodeRect.yMin - 400);
                flowchart.scrollViewRect.yMax = Mathf.Max(flowchart.scrollViewRect.yMax, block.nodeRect.yMax + 400);
            }

            // Calc rect for script view
            Rect scriptViewRect = new Rect(0, 0, this.position.width / flowchart.zoom, this.position.height / flowchart.zoom);

            EditorZoomArea.Begin(flowchart.zoom, scriptViewRect);

            DrawGrid(flowchart);
            
            GLDraw.BeginGroup(scriptViewRect);

            if (Event.current.button == 0 && 
                Event.current.type == EventType.MouseDown &&
                !mouseOverVariables)
            {
                flowchart.selectedBlock = null;
                if (!EditorGUI.actionKey)
                {
                    flowchart.ClearSelectedCommands();
                }
                Selection.activeGameObject = flowchart.gameObject;
            }

            // The center of the Flowchart depends on the block positions and window dimensions, so we calculate it 
            // here in the FlowchartWindow class and store it on the Flowchart object for use later.
            CalcFlowchartCenter(flowchart, blocks);

            // Draw connections
            foreach (Block block in blocks)
            {
                DrawConnections(flowchart, block, false);
            }
            foreach (Block block in blocks)
            {
                DrawConnections(flowchart, block, true);
            }

            GUIStyle windowStyle = new GUIStyle();
            windowStyle.stretchHeight = true;

            BeginWindows();

            windowBlockMap.Clear();
            for (int i = 0; i < blocks.Length; ++i)
            {
                Block block = blocks[i];

                float nodeWidthA = nodeStyle.CalcSize(new GUIContent(block.blockName)).x + 10;
                float nodeWidthB = 0f;
                if (block.eventHandler != null)
                {
                    nodeWidthB = nodeStyle.CalcSize(new GUIContent(block.eventHandler.GetSummary())).x + 10;
                }

                block.nodeRect.width = Mathf.Max(Mathf.Max(nodeWidthA, nodeWidthB), 120);
                block.nodeRect.height = 40;

                if (Event.current.button == 0)
                {
                    if (Event.current.type == EventType.MouseDrag && dragWindowId == i)
                    {
                        block.nodeRect.x += Event.current.delta.x;
                        block.nodeRect.y += Event.current.delta.y;

                        forceRepaintCount = 6;
                    }
                    else if (Event.current.type == EventType.MouseUp &&
                             dragWindowId == i)
                    {
                        Vector2 newPos = new Vector2(block.nodeRect.x, block.nodeRect.y);
                        
                        block.nodeRect.x = startDragPosition.x;
                        block.nodeRect.y = startDragPosition.y;
                        
                        Undo.RecordObject(block, "Node Position");
                        
                        block.nodeRect.x = newPos.x;
                        block.nodeRect.y = newPos.y;

                        dragWindowId = -1;
                        forceRepaintCount = 6;
                    }
                }

                Rect windowRect = new Rect(block.nodeRect);
                windowRect.x += flowchart.scrollPos.x;
                windowRect.y += flowchart.scrollPos.y;

                GUILayout.Window(i, windowRect, DrawWindow, "", windowStyle);

                GUI.backgroundColor = Color.white;

                windowBlockMap.Add(block);
            }

            EndWindows();

            // Draw Event Handler labels
            foreach (Block block in blocks)
            {
                if (block.eventHandler != null)
                {
                    string handlerLabel = "";
                    EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(block.eventHandler.GetType());
                    if (info != null)
                    {
                        handlerLabel = "<" + info.EventHandlerName + "> ";
                    }

                    GUIStyle handlerStyle = new GUIStyle(EditorStyles.whiteLabel);
                    handlerStyle.wordWrap = true;
                    handlerStyle.margin.top = 0;
                    handlerStyle.margin.bottom = 0;
                    handlerStyle.alignment = TextAnchor.MiddleCenter;

                    Rect rect = new Rect(block.nodeRect);
                    rect.height = handlerStyle.CalcHeight(new GUIContent(handlerLabel), block.nodeRect.width);
                    rect.x += flowchart.scrollPos.x;
                    rect.y += flowchart.scrollPos.y - rect.height;

                    GUI.Label(rect, handlerLabel, handlerStyle);
                }
            }


            // Draw play icons beside all executing blocks
            if (Application.isPlaying)
            {
                foreach (Block b in blocks)
                {
                    if (b.IsExecuting())
                    {
                        b.executingIconTimer = Time.realtimeSinceStartup + Block.executingIconFadeTime;
                        b.activeCommand.executingIconTimer = Time.realtimeSinceStartup + Block.executingIconFadeTime;
                        forceRepaintCount = 6;
                    }

                    if (b.executingIconTimer > Time.realtimeSinceStartup)
                    {
                        Rect rect = new Rect(b.nodeRect);

                        rect.x += flowchart.scrollPos.x - 37;
                        rect.y += flowchart.scrollPos.y + 3;
                        rect.width = 34;
                        rect.height = 34;

                        if (!b.IsExecuting())
                        {
                            float alpha = (b.executingIconTimer - Time.realtimeSinceStartup) / Block.executingIconFadeTime;
                            alpha = Mathf.Clamp01(alpha);
                            GUI.color = new Color(1f, 1f, 1f, alpha); 
                        }

                        if (GUI.Button(rect, FungusEditorResources.texPlayBig as Texture, new GUIStyle()))
                        {
                            SelectBlock(flowchart, b);
                        }

                        GUI.color = Color.white;
                    }
                }
            }

            PanAndZoom(flowchart);

            GLDraw.EndGroup();

            EditorZoomArea.End();
        }
 protected static void SetBlockForInspector(Flowchart flowchart, Block block)
 {
     ShowBlockInspector(flowchart);
     flowchart.ClearSelectedCommands();
     if (block.ActiveCommand != null)
     {
         flowchart.AddSelectedCommand(block.ActiveCommand);
     }
 }
 protected virtual void DeselectAll(Flowchart flowchart)
 {
     Undo.RecordObject(flowchart, "Deselect");
     flowchart.ClearSelectedCommands();
     flowchart.ClearSelectedBlocks();
     Selection.activeGameObject = flowchart.gameObject;
 }
Beispiel #11
0
        protected virtual void DrawFlowchartView(Flowchart flowchart)
        {
            Block[] blocks = flowchart.GetComponents <Block>();

            foreach (var block in blocks)
            {
                var node = block as Node;
                if (node == null)
                {
                    continue;
                }

                var newRect = new Rect();
                newRect.xMin             = Mathf.Min(flowchart.ScrollViewRect.xMin, node._NodeRect.xMin - 400);
                newRect.xMax             = Mathf.Max(flowchart.ScrollViewRect.xMax, node._NodeRect.xMax + 400);
                newRect.yMin             = Mathf.Min(flowchart.ScrollViewRect.yMin, node._NodeRect.yMin - 400);
                newRect.yMax             = Mathf.Max(flowchart.ScrollViewRect.yMax, node._NodeRect.yMax + 400);
                flowchart.ScrollViewRect = newRect;
            }

            // Calc rect for script view
            Rect scriptViewRect = new Rect(0, 0, this.position.width / flowchart.Zoom, this.position.height / flowchart.Zoom);

            EditorZoomArea.Begin(flowchart.Zoom, scriptViewRect);

            DrawGrid(flowchart);

            GLDraw.BeginGroup(scriptViewRect);

            if (Event.current.button == 0 &&
                Event.current.type == EventType.MouseDown &&
                !mouseOverVariables)
            {
                flowchart.SelectedBlock = null;
                if (!EditorGUI.actionKey)
                {
                    flowchart.ClearSelectedCommands();
                }
                Selection.activeGameObject = flowchart.gameObject;
            }

            // The center of the Flowchart depends on the block positions and window dimensions, so we calculate it
            // here in the FlowchartWindow class and store it on the Flowchart object for use later.
            CalcFlowchartCenter(flowchart, blocks);

            // Draw connections
            foreach (var block in blocks)
            {
                DrawConnections(flowchart, block, false);
            }
            foreach (var block in blocks)
            {
                DrawConnections(flowchart, block, true);
            }

            GUIStyle windowStyle = new GUIStyle();

            windowStyle.stretchHeight = true;

            BeginWindows();

            windowBlockMap.Clear();
            for (int i = 0; i < blocks.Length; ++i)
            {
                var block = blocks[i];

                float nodeWidthA = nodeStyle.CalcSize(new GUIContent(block.BlockName)).x + 10;
                float nodeWidthB = 0f;
                if (block._EventHandler != null)
                {
                    nodeWidthB = nodeStyle.CalcSize(new GUIContent(block._EventHandler.GetSummary())).x + 10;
                }

                if (Event.current.button == 0)
                {
                    Rect tempRect = block._NodeRect;
                    tempRect.width  = Mathf.Max(Mathf.Max(nodeWidthA, nodeWidthB), 120);
                    tempRect.height = 40;

                    if (Event.current.type == EventType.MouseDrag && dragWindowId == i)
                    {
                        tempRect.x += Event.current.delta.x;
                        tempRect.y += Event.current.delta.y;

                        forceRepaintCount = 6;
                    }
                    else if (Event.current.type == EventType.MouseUp &&
                             dragWindowId == i)
                    {
                        Vector2 newPos = new Vector2(tempRect.x, tempRect.y);

                        tempRect.x = startDragPosition.x;
                        tempRect.y = startDragPosition.y;

                        Undo.RecordObject((Block)block, "Node Position");

                        tempRect.x = newPos.x;
                        tempRect.y = newPos.y;

                        dragWindowId      = -1;
                        forceRepaintCount = 6;
                    }

                    block._NodeRect = tempRect;
                }

                Rect windowRect = new Rect(block._NodeRect);
                windowRect.x += flowchart.ScrollPos.x;
                windowRect.y += flowchart.ScrollPos.y;

                GUILayout.Window(i, windowRect, DrawWindow, "", windowStyle);

                GUI.backgroundColor = Color.white;

                windowBlockMap.Add(block);
            }

            EndWindows();

            // Draw Event Handler labels
            foreach (var block in blocks)
            {
                if (block._EventHandler != null)
                {
                    string handlerLabel            = "";
                    EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(block._EventHandler.GetType());
                    if (info != null)
                    {
                        handlerLabel = "<" + info.EventHandlerName + "> ";
                    }

                    GUIStyle handlerStyle = new GUIStyle(EditorStyles.whiteLabel);
                    handlerStyle.wordWrap      = true;
                    handlerStyle.margin.top    = 0;
                    handlerStyle.margin.bottom = 0;
                    handlerStyle.alignment     = TextAnchor.MiddleCenter;

                    Rect rect = new Rect(block._NodeRect);
                    rect.height = handlerStyle.CalcHeight(new GUIContent(handlerLabel), block._NodeRect.width);
                    rect.x     += flowchart.ScrollPos.x;
                    rect.y     += flowchart.ScrollPos.y - rect.height;

                    GUI.Label(rect, handlerLabel, handlerStyle);
                }
            }

            // Draw play icons beside all executing blocks
            if (Application.isPlaying)
            {
                foreach (var b in blocks)
                {
                    if (b.IsExecuting())
                    {
                        b.ExecutingIconTimer = Time.realtimeSinceStartup + FungusConstants.ExecutingIconFadeTime;
                        b.ActiveCommand.ExecutingIconTimer = Time.realtimeSinceStartup + FungusConstants.ExecutingIconFadeTime;
                        forceRepaintCount = 6;
                    }

                    if (b.ExecutingIconTimer > Time.realtimeSinceStartup)
                    {
                        Rect rect = new Rect(b._NodeRect);

                        rect.x     += flowchart.ScrollPos.x - 37;
                        rect.y     += flowchart.ScrollPos.y + 3;
                        rect.width  = 34;
                        rect.height = 34;

                        if (!b.IsExecuting())
                        {
                            float alpha = (b.ExecutingIconTimer - Time.realtimeSinceStartup) / FungusConstants.ExecutingIconFadeTime;
                            alpha     = Mathf.Clamp01(alpha);
                            GUI.color = new Color(1f, 1f, 1f, alpha);
                        }

                        if (GUI.Button(rect, FungusEditorResources.texPlayBig as Texture, new GUIStyle()))
                        {
                            SelectBlock(flowchart, b);
                        }

                        GUI.color = Color.white;
                    }
                }
            }

            PanAndZoom(flowchart);

            GLDraw.EndGroup();

            EditorZoomArea.End();
        }