浏览代码

add debug mode in editor

/siyaoH-1.17-PlatformMessage
Shiyun Wen 4 年前
当前提交
656f4e65
共有 8 个文件被更改,包括 37 次插入62 次删除
  1. 17
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/GalleryMain.cs
  2. 1
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/GalleryMain.cs
  3. 4
      com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs
  4. 6
      com.unity.uiwidgets/Editor/UIWidgetsPanelEditor.cs
  5. 40
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
  6. 4
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanelWrapper.cs
  7. 17
      com.unity.uiwidgets/Runtime/foundation/debug.cs
  8. 10
      com.unity.uiwidgets/Runtime/scheduler2/binding.cs

17
Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/GalleryMain.cs


using System.Collections.Generic;
using UIWidgetsGallery.gallery;
using Unity.UIWidgets.Editor;
using Unity.UIWidgets.engine2;
using UnityEngine;
[MenuItem("UIWidgets/SetDebugLog")]
public static void SetDebugMode()
{
if (PlayerPrefs.GetInt("DisableDebugMode") == 1)
{
PlayerPrefs.SetInt("DisableDebugMode",0);
}
else
{
PlayerPrefs.SetInt("DisableDebugMode",1);
}
UIWidgetsPanel.ShowDebugLog = PlayerPrefs.GetInt("DisableDebugMode") == 1 ? false : true;
}
[MenuItem("UIWidgets/EditorSample")]
public static void CountDemo()
{

protected override void onEnable()
{
DisableDebugLog();
AddFont("Material Icons", new List<string> {"MaterialIcons-Regular.ttf"}, new List<int> {0});
AddFont("CupertinoIcons", new List<string> {"CupertinoIcons.ttf"}, new List<int> {0});
AddFont("GalleryIcons", new List<string> {"gallery/GalleryIcons.ttf"}, new List<int> {0});

1
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/GalleryMain.cs


protected override void onEnable()
{
DisableDebugLog();
AddFont("Material Icons", new List<string> {"MaterialIcons-Regular.ttf"}, new List<int> {0});
AddFont("CupertinoIcons", new List<string> {"CupertinoIcons.ttf"}, new List<int> {0});
AddFont("GalleryIcons", new List<string> {"gallery/GalleryIcons.ttf"}, new List<int> {0});

4
com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs


_configurations.AddFont(family,textFont);
}
public void DisableDebugLog() {
_configurations.DisableDebugLog();
}
Vector2? _getPointerPosition(Vector2 position) {
return new Vector2(x: position.x, y: position.y);
}

6
com.unity.uiwidgets/Editor/UIWidgetsPanelEditor.cs


base.OnInspectorGUI();
var pixelRatioProperty = serializedObject.FindProperty("devicePixelRatioOverride");
var antiAliasingProperty = serializedObject.FindProperty("hardwareAntiAliasing");
var ShowDebugLog = serializedObject.FindProperty("m_ShowDebugLog");
//var ShowDebugLog = serializedObject.FindProperty("m_ShowDebugLog");
EditorGUILayout.PropertyField(ShowDebugLog);
//EditorGUILayout.PropertyField(ShowDebugLog);
/*if (EditorGUI.EndChangeCheck()) {
UIWidgetsPanel.ShowDebugLog = ShowDebugLog.boolValue;
}*/

40
com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs


private Dictionary<string, TextFont> _textFonts = new Dictionary<string, TextFont>();
bool _debugMode = true;
public bool debugMode {
get { return _debugMode; }
}
_debugMode = true;
}
public void AddFont(string family, TextFont font) {
_textFonts[key: family] = font;

return result;
}
public void DisableDebugLog() {
_debugMode = false;
}
public void EnableDebugLog() {
_debugMode = true;
}
static bool _ShowDebugLog;
public float devicePixelRatioOverride;
public bool hardwareAntiAliasing;

public bool m_ShowDebugLog;
Configurations _configurations;
UIWidgetsPanelWrapper _wrapper;

return currentDpi / 96;
}
}
public static bool ShowDebugLog {
get { return _ShowDebugLog; }
set {
/* foreach (var panel in panels) {
panel._ShowDebugLog = value;
}
*/
_ShowDebugLog = value;
}
}
protected virtual void Update() {
Input_Update();
}

foreach (var font in fonts) {
AddFont(family: font.family, font: font);
}
}
if (m_ShowDebugLog) {
EnableDebugLog();
}
_wrapper.Initiate(this, width: _currentWidth, height: _currentHeight, dpr: _currentDevicePixelRatio,
_configurations: _configurations);

protected virtual void onEnable() {
}
public void EnableDebugLog() {
_configurations.EnableDebugLog();
}
public void DisableDebugLog() {
_configurations.DisableDebugLog();
}
protected void AddFont(string family, TextFont font) {
_configurations.AddFont(family,font);
}

4
com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanelWrapper.cs


public float devicePixelRatio { get; private set; }
public bool ShowDebugLog { get; set; }
public void Initiate(IUIWidgetsWindow host, int width, int height, float dpr, Configurations _configurations) {
D.assert(renderTexture == null);
_recreateRenderTexture(width: width, height: height, devicePixelRatio: dpr);

var fontsetting = new Dictionary<string, object>();
fontsetting.Add("fonts", _configurations.fontsToObject());
_enableUIWidgetsPanel(JSONMessageCodec.instance.toJson(message: fontsetting));
ShowDebugLog = _configurations.debugMode;
NativeConsole.OnEnable();
}

UIWidgetsPanel_onDisable(ptr: _ptr);
UIWidgetsPanel_dispose(ptr: _ptr);
_ptr = IntPtr.Zero;
ShowDebugLog = true;
_handle.Free();
_handle = default;

17
com.unity.uiwidgets/Runtime/foundation/debug.cs


using System;
using System.Diagnostics;
using System.Linq;
using Unity.UIWidgets.engine2;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Canvas = Unity.UIWidgets.ui.Canvas;

public static bool debugPrintMouseHoverEvents = false;
private static bool _disableDebugLog = false;
public static HSVColor debugCurrentRepaintColor =
HSVColor.fromAHSV(0.4f, 60.0f, 1.0f, 1.0f);

[Conditional("UNITY_ASSERTIONS")]
public static void assert(Func<bool> result, Func<string> message = null) {
if ( !result() && !_disableDebugLog) {
if ( UIWidgetsPanel.ShowDebugLog && !result() ) {
throw new AssertionError(message != null ? message() : "");
}
}

if ( !result && !_disableDebugLog ) {
if (UIWidgetsPanel.ShowDebugLog && !result ) {
}
public static void disableDebugLog() {
_disableDebugLog = true;
}
public static void resetDebugLog() {
_disableDebugLog = false;
}
}
public static void _debugDrawDoubleRect(Canvas canvas, Rect outerRect, Rect innerRect, Color color) {
var path = new Path();
path.fillType = PathFillType.evenOdd;

10
com.unity.uiwidgets/Runtime/scheduler2/binding.cs


public void handleBeginFrame(TimeSpan? rawTimeStamp) {
Timeline.startSync("Frame");
if (!UIWidgetsPanelWrapper.current.ShowDebugLog) {
D.disableDebugLog();
}
_firstRawTimeStampInEpoch = _firstRawTimeStampInEpoch ?? rawTimeStamp;
_currentFrameTimeStamp = _adjustForEpoch(rawTimeStamp ?? currentSystemFrameTimeStamp);

_removedIds.Clear();
}
finally {
D.resetDebugLog();
if (!UIWidgetsPanelWrapper.current.ShowDebugLog) {
D.disableDebugLog();
}
D.assert(schedulerPhase == SchedulerPhase.midFrameMicrotasks);
Timeline.finishSync();
try {

}
}
finally {
D.resetDebugLog();
schedulerPhase = SchedulerPhase.idle;
D.assert(() => {
if (scheduler_.debugPrintEndFrameBanner) {

正在加载...
取消
保存