浏览代码

Merge pull request #123 from Unity-Technologies/zxw/refine_debug_mode

Add a temporary working way to enable/disable debug at runtime and fix mac/ios occasional crash issue
/siyaoH-1.17-PlatformMessage
GitHub 4 年前
当前提交
3260d27e
共有 7 个文件被更改,包括 61 次插入58 次删除
  1. 2
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/GalleryMain.cs
  2. 7
      com.unity.uiwidgets/Editor/UIWidgetsPanelEditor.cs
  3. 2
      com.unity.uiwidgets/Runtime/engine/UIWidgetsMessageManager.cs
  4. 26
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
  5. 20
      com.unity.uiwidgets/Runtime/foundation/debug.cs
  6. 31
      engine/src/shell/platform/unity/darwin/ios/unity_surface_manager.mm
  7. 31
      engine/src/shell/platform/unity/darwin/macos/unity_surface_manager.mm

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


public class EditorWindowGallery : UIWidgetsEditorPanel
{
[MenuItem("UIWidgets/EditorSample")]
[MenuItem("UIWidgets/EditorSample/GalleryMain")]
public static void CountDemo()
{
CreateWindow<EditorWindowGallery>();

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


public class UIWidgetsPanelEditor : RawImageEditor {
public override void OnInspectorGUI() {
base.OnInspectorGUI();
base.OnInspectorGUI();
UIWidgetsPanel panel = (UIWidgetsPanel)target;
UIWidgetsPanel panel = (UIWidgetsPanel)target;
[MenuItem("UIWidgets/EnableDebug")]
public static void ToggleDebugMode(){
D.enableDebug = !D.enableDebug;

2
com.unity.uiwidgets/Runtime/engine/UIWidgetsMessageManager.cs


}
void UpdateNameIfNeed() {
#if UNITY_IOS || UNITY_ANDROID || UNITY_WEBGL
#if UNITY_ANDROID || UNITY_WEBGL
var name = gameObject.name;
if (name != _lastObjectName) {

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


}
public partial class UIWidgetsPanel : RawImage, IUIWidgetsWindow {
public static List<UIWidgetsPanel> panels = new List<UIWidgetsPanel>();
static List<UIWidgetsPanel> panels = new List<UIWidgetsPanel>();
static bool _ShowDebugLog;
static void registerPanel(UIWidgetsPanel panel) {
panels.Add(panel);
}
static void unregisterPanel(UIWidgetsPanel panel) {
panels.Remove(panel);
}
float _devicePixelRatioOverride;
public bool hardwareAntiAliasing;

return currentDpi / 96;
}
}
public static bool ShowDebugLog {
get { return _ShowDebugLog; }
set {
_ShowDebugLog = value;
}
}
bool _viewMetricsCallbackRegistered;

//the hook API cannot be automatically called on IOS, so we need try hook it here
Hooks.tryHook();
#endif
D.assert(_wrapper == null);
_configurations = new Configurations();
_wrapper = new UIWidgetsPanelWrapper();

_configurations.Clear();
texture = _wrapper.renderTexture;
Input_OnEnable();
panels.Add(this);
registerPanel(this);
unregisterPanel(this);
D.assert(_wrapper != null);
_wrapper?.Destroy();
_wrapper = null;

panels.Remove(this);
}
protected virtual void OnGUI() {

20
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 UnityEngine;

using Rect = Unity.UIWidgets.ui.Rect;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Unity.UIWidgets.foundation {

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

}
[Conditional("UNITY_ASSERTIONS")]
public static void assert(bool result, Func<string> message = null) {
if ( enableDebug && !result ) {
if ( enableDebug && !result ) {
#if UNITY_EDITOR
_enableDebug = PlayerPrefs.GetInt("UIWidgetsDebug") == 1;
_enableDebug = EditorPrefs.GetInt("UIWidgetsDebug") == 1;
}
return _enableDebug.Value;
}

}
_enableDebug = value;
PlayerPrefs.SetInt("UIWidgetsDebug",value ? 1 : 0);
EditorPrefs.SetInt("UIWidgetsDebug",value ? 1 : 0);
#else
public static bool enableDebug => debugEnableAtRuntimeInternal;
#endif
public static void _debugDrawDoubleRect(Canvas canvas, Rect outerRect, Rect innerRect, Color color) {
var path = new Path();
path.fillType = PathFillType.evenOdd;

31
engine/src/shell/platform/unity/darwin/ios/unity_surface_manager.mm


bool UnitySurfaceManager::ReleaseNativeRenderTexture()
{
//release gl resources
CFRelease(gl_tex_ref_);
CFRelease(gl_tex_cache_ref_);
//release metal resources
CFRelease(metal_tex_ref_);
CFRelease(metal_tex_cache_ref_);
//release cv pixelbuffer
CVPixelBufferRelease(pixelbuffer_ref);
FML_DCHECK(gl_tex_ != 0);
glDeleteTextures(1, &gl_tex_);
//gl_tex_ is released in CVOpenGLTextureRelease
CFRelease(gl_tex_cache_ref_);
CFRelease(gl_tex_ref_);
//release metal resources
metal_tex_ref_ = nullptr;
metal_tex_cache_ref_ = nullptr;
CFRelease(metal_tex_ref_);
metal_tex_ref_ = nullptr;
CFRelease(metal_tex_cache_ref_);
metal_tex_cache_ref_ = nullptr;
//release cv pixelbuffer
CVPixelBufferRelease(pixelbuffer_ref);
return true;
}
} // namespace uiwidgets

31
engine/src/shell/platform/unity/darwin/macos/unity_surface_manager.mm


bool UnitySurfaceManager::ReleaseNativeRenderTexture()
{
//release gl resources
CVOpenGLTextureRelease(gl_tex_ref_);
CVOpenGLTextureCacheRelease(gl_tex_cache_ref_);
//release metal resources
CFRelease(metal_tex_ref_);
CFRelease(metal_tex_cache_ref_);
//release pixel buffer
CVPixelBufferRelease(pixelbuffer_ref);
FML_DCHECK(gl_tex_ != 0);
glDeleteTextures(1, &gl_tex_);
//gl_tex_ is released in CVOpenGLTextureRelease
CFRelease(gl_tex_cache_ref_);
CFRelease(gl_tex_ref_);
//release metal resources
metal_tex_ref_ = nullptr;
metal_tex_cache_ref_ = nullptr;
CFRelease(metal_tex_ref_);
metal_tex_ref_ = nullptr;
CFRelease(metal_tex_cache_ref_);
metal_tex_cache_ref_ = nullptr;
//release cv pixelbuffer
CVPixelBufferRelease(pixelbuffer_ref);
return true;
}
} // namespace uiwidgets
正在加载...
取消
保存