浏览代码

draw frame delta time for debug

/siyaoH-1.17-debugDraw
siyao 3 年前
当前提交
90006589
共有 3 个文件被更改,包括 81 次插入0 次删除
  1. 13
      com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs
  2. 53
      com.unity.uiwidgets/Runtime/rendering/viewport.cs
  3. 15
      com.unity.uiwidgets/Runtime/ui/hooks.cs

13
com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs


long nextCollectAt = 0;
protected virtual void Update() {
if (GlobalValue.playerPre == null) {
GlobalValue.playerPre = DateTime.Now;
} else if (GlobalValue.playerCur == null) {
GlobalValue.playerCur = DateTime.Now;
}
else {
GlobalValue.playerPre = GlobalValue.playerCur;
GlobalValue.playerCur = DateTime.Now;
GlobalValue.playerFrameRates.AddLast(2000f*(GlobalValue.playerCur - GlobalValue.playerPre).Value.TotalSeconds);
if (GlobalValue.playerFrameRates.Count > 50) {
GlobalValue.playerFrameRates.RemoveFirst();
}
}
if (!_viewMetricsCallbackRegistered) {
_viewMetricsCallbackRegistered = true;
UIWidgetsMessageManager.instance?.AddChannelMessageDelegate("ViewportMetricsChanged",

53
com.unity.uiwidgets/Runtime/rendering/viewport.cs


using System;
using System.Collections.Generic;
using uiwidgets;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;

using Canvas = Unity.UIWidgets.ui.Canvas;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
using TextStyle = Unity.UIWidgets.ui.TextStyle;
namespace Unity.UIWidgets.rendering {
public enum CacheExtentStyle {

}
}
public class GlobalValue {
public static int x;
public static DateTime? pre;
public static DateTime? cur;
public static LinkedList<double> frameRates = new LinkedList<double>();
public static DateTime? playerPre;
public static DateTime? playerCur;
public static LinkedList<double> playerFrameRates = new LinkedList<double>();
}
public abstract class RenderViewportBase<ParentDataClass> :
ContainerRenderObjectMixinRenderBox<RenderSliver, ParentDataClass>,
RenderAbstractViewport

}
}
int a = 0;
public void _paintContents(PaintingContext context, Offset offset) {
foreach (RenderSliver child in childrenInPaintOrder) {
if (child.geometry.visible) {

a++;
var p = new Paint();
p.color = Colors.blue;
for (int i = 0; i < a%10; i++) {
context.canvas.drawRect(Rect.fromLTRB(i * 20, 0, i * 20 + 10, 50), p );
}
p.color = Colors.red;
for (int i = 0; i < GlobalValue.x%10; i++) {
context.canvas.drawRect(Rect.fromLTRB(i * 20, 50, i * 20 + 10, 100), p );
}
if (GlobalValue.cur != null && GlobalValue.pre != null) {
var pr = new ParagraphBuilder(new ParagraphStyle(
textDirection: TextDirection.ltr,
textAlign: TextAlign.left
));
var seconds = (GlobalValue.cur.Value - GlobalValue.pre.Value).TotalSeconds;
pr.pushStyle(new TextStyle(color: Colors.blue));
pr.addText($"{seconds}\n{1.0 /seconds}\n{GlobalValue.x - a}");
var prr = pr.build();
prr.layout(new ParagraphConstraints(width: 400));
context.canvas.drawParagraph(prr, new Offset(30, 100));
}
int index = 0;
foreach(var f in GlobalValue.frameRates) {
p.color = Color.fromRGBO(255,0,0, 0.5f);
context.canvas.drawCircle(new Offset(10 + index * 3, 300 - (float)(f * 1.0f)), 3, p);
index++;
}
index = 0;
foreach(var f in GlobalValue.playerFrameRates) {
p.color = Color.fromRGBO(0,0,255, 0.5f);
context.canvas.drawCircle(new Offset(10 + index * 3, 300 - (float)(f * 1)), 3, p);
index++;
}
context.canvas.drawRect(Rect.fromLTRB(0 , 300, 500, 310), p );
}
protected override void debugPaintSize(PaintingContext context, Offset offset) {

15
com.unity.uiwidgets/Runtime/ui/hooks.cs


using Unity.UIWidgets.async;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using UnityEngine;

[MonoPInvokeCallback(typeof(Window_drawFrameCallback))]
static void Window_drawFrame() {
GlobalValue.x += 1;
if (GlobalValue.pre == null) {
GlobalValue.pre = DateTime.Now;
} else if (GlobalValue.cur == null) {
GlobalValue.cur = DateTime.Now;
}
else {
GlobalValue.pre = GlobalValue.cur;
GlobalValue.cur = DateTime.Now;
GlobalValue.frameRates.AddLast(2000f*(GlobalValue.cur - GlobalValue.pre).Value.TotalSeconds);
if (GlobalValue.frameRates.Count > 50) {
GlobalValue.frameRates.RemoveFirst();
}
}
try {
Window.instance.onDrawFrame?.Invoke();
}

正在加载...
取消
保存