コード例 #1
0
        protected virtual void DrawFlowchartView(Flowchart flowchart)
        {
            Block[] blocks = flowchart.GetComponentsInChildren <Block>(true);

            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;
            }

            // 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 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();
        }
コード例 #2
0
        protected virtual void DrawScriptView(FungusScript fungusScript)
        {
            Sequence[] sequences = fungusScript.GetComponentsInChildren <Sequence>(true);

            foreach (Sequence s in sequences)
            {
                fungusScript.scrollViewRect.xMin = Mathf.Min(fungusScript.scrollViewRect.xMin, s.nodeRect.xMin - 400);
                fungusScript.scrollViewRect.xMax = Mathf.Max(fungusScript.scrollViewRect.xMax, s.nodeRect.xMax + 400);
                fungusScript.scrollViewRect.yMin = Mathf.Min(fungusScript.scrollViewRect.yMin, s.nodeRect.yMin - 400);
                fungusScript.scrollViewRect.yMax = Mathf.Max(fungusScript.scrollViewRect.yMax, s.nodeRect.yMax + 400);
            }

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

            EditorZoomArea.Begin(fungusScript.zoom, scriptViewRect);

            DrawGrid(fungusScript);

            GLDraw.BeginGroup(scriptViewRect);

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

            // Draw connections
            foreach (Sequence s in sequences)
            {
                DrawConnections(fungusScript, s, false);
            }
            foreach (Sequence s in sequences)
            {
                DrawConnections(fungusScript, s, true);
            }

            GUIStyle windowStyle = new GUIStyle();

            windowStyle.stretchHeight = true;

            BeginWindows();

            windowSequenceMap.Clear();
            for (int i = 0; i < sequences.Length; ++i)
            {
                Sequence sequence = sequences[i];

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

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

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

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

                        sequence.nodeRect.x = startDragPosition.x;
                        sequence.nodeRect.y = startDragPosition.y;

                        Undo.RecordObject(sequence, "Node Position");

                        sequence.nodeRect.x = newPos.x;
                        sequence.nodeRect.y = newPos.y;

                        dragWindowId      = -1;
                        forceRepaintCount = 6;
                    }
                }

                Rect windowRect = new Rect(sequence.nodeRect);
                windowRect.x += fungusScript.scrollPos.x;
                windowRect.y += fungusScript.scrollPos.y;

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

                GUI.backgroundColor = Color.white;

                windowSequenceMap.Add(sequence);
            }

            EndWindows();

            // Draw play icons beside all executing sequences
            if (Application.isPlaying)
            {
                foreach (Sequence s in sequences)
                {
                    if (s.IsExecuting())
                    {
                        s.executingIconTimer = playIconFadeTime;
                        forceRepaintCount    = 6;
                    }

                    if (s.executingIconTimer > 0f)
                    {
                        s.executingIconTimer = Mathf.Max(s.executingIconTimer - Time.deltaTime, 0f);

                        Rect rect = new Rect(s.nodeRect);

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

                        if (!s.IsExecuting() && s.executingIconTimer < playIconFadeTime)
                        {
                            float alpha = s.executingIconTimer / playIconFadeTime;
                            GUI.color = new Color(1f, 1f, 1f, alpha);
                        }

                        if (GUI.Button(rect, FungusEditorResources.texPlayBig as Texture, new GUIStyle()))
                        {
                            SelectSequence(fungusScript, s);
                        }

                        GUI.color = Color.white;
                    }
                }
            }

            // Right click to drag view
            if (Event.current.button == 1 && Event.current.type == EventType.MouseDrag)
            {
                fungusScript.scrollPos += Event.current.delta;
                forceRepaintCount       = 6;
            }
            else if (Event.current.type == EventType.ScrollWheel)
            {
                fungusScript.zoom -= Event.current.delta.y * 0.01f;
                fungusScript.zoom  = Mathf.Clamp(fungusScript.zoom, minZoomValue, maxZoomValue);
                forceRepaintCount  = 6;
            }

            GLDraw.EndGroup();

            EditorZoomArea.End();
        }