Пример #1
0
            private Vector2 DrawNode(Node node, float x, float y, ref double parentPreviousFrame, ref double parentPreviousFrameMax)
            {
                var subGraph = node.data as Graph;

                var offset = node.GetOffset();
                var px     = x;
                var py     = y;

                var size  = node.GetSize();
                var style = node.GetStyle();

                if (subGraph != null)
                {
                    size.y += subGraph.graphSize.y;
                }

                var boxRect       = new Rect(x, y, size.x, size.y);
                var boxRectOffset = new Rect(boxRect.x + offset.x, boxRect.y + offset.y, boxRect.width, boxRect.height);

                if (this.vertical == false)
                {
                    px += size.x + Styles.horizontalSpacing;
                }
                else
                {
                    py += size.y + Styles.verticalSpacing;
                }

                if (this.checkpointCollector != null)
                {
                    if (node.data is ISystemBase)
                    {
                        var checkpoints = this.checkpointCollector.GetCheckpointsBetween(this.prevCheckpoint, node.checkpoint);
                        if (checkpoints.Count > 0)
                        {
                            var nextConnection = node.connections[0];
                            if ((nextConnection is CustomUserNode) == false)
                            {
                                node.connections.RemoveAt(0);

                                var prevNode = node;
                                foreach (var chk in checkpoints)
                                {
                                    if (chk.obj is ISystemBase)
                                    {
                                        continue;
                                    }

                                    prevNode = this.AddNode(prevNode, new CustomUserNode(chk.obj), chk.obj, chk.step);
                                }

                                prevNode.ConnectTo(nextConnection);
                            }
                        }
                    }
                }

                var cpx = px;
                var cpy = py;

                for (int i = 0; i < node.connections.Count; ++i)
                {
                    var nodeSize   = node.connections[i].GetSize();
                    var nodeOffset = node.connections[i].GetOffset();
                    this.DrawConnection(boxRectOffset, new Rect(cpx + nodeOffset.x, cpy + nodeOffset.y, nodeSize.x, nodeSize.y), node, node.connections[i]);
                    cpy += nodeSize.y + Styles.verticalSpacing;
                }
                GUI.Box(boxRectOffset, string.Empty, style);

                var mData = string.Empty;

                if (this.checkpointCollector != null && node.checkpoint != null)
                {
                    var tickTime  = this.worldGraph.world.GetTickTime();
                    var watcherTs = this.checkpointCollector.GetWatcher(node.checkpoint, node.worldStep);
                    if (watcherTs >= node.maxTs)
                    {
                        node.maxTs = watcherTs;
                    }
                    var curColor = Styles.GetColorForMeasuring(tickTime, watcherTs);
                    var maxColor = Styles.GetColorForMeasuring(tickTime, node.maxTs);

                    var maxTs = node.maxTs;
                    parentPreviousFrame += watcherTs;
                    if (node.maxTs > parentPreviousFrameMax)
                    {
                        parentPreviousFrameMax = node.maxTs;
                    }

                    if (node is Container)
                    {
                        if (subGraph != null)
                        {
                            watcherTs = subGraph.sumPreviousFrame;
                            maxTs     = subGraph.previousFrameMax;
                        }
                    }

                    mData = string.Format("<color=#{2}>{0}ms</color>  <color=#{3}>Max: {1}ms</color>", watcherTs.ToString("#0.000"), maxTs.ToString("#0.000"), Styles.ColorToHex(curColor), Styles.ColorToHex(maxColor));

                    GUI.Label(boxRectOffset, mData, Styles.measureLabel);
                }

                node.OnGUI(boxRectOffset);
                if (subGraph != null)
                {
                    subGraph.prevCheckpoint = this.prevCheckpoint;
                    subGraph.OnGUI(boxRect);
                    if (subGraph.vertical == true)
                    {
                        size.y += subGraph.graphSize.y;
                    }

                    parentPreviousFrame += subGraph.sumPreviousFrame;
                    if (subGraph.previousFrameMax > parentPreviousFrameMax)
                    {
                        parentPreviousFrameMax = subGraph.previousFrameMax;
                    }
                }

                if (node.checkpoint != null)
                {
                    this.prevCheckpoint = node.checkpoint;
                }

                for (int i = 0; i < node.connections.Count; ++i)
                {
                    var nodeSize = this.DrawNode(node.connections[i], px, py, ref parentPreviousFrame, ref parentPreviousFrameMax);
                    py += nodeSize.y + Styles.verticalSpacing;

                    if (this.vertical == true)
                    {
                        this.graphSize.y += nodeSize.y + Styles.verticalSpacing;
                    }
                }

                return(size);
            }