浏览代码

fix add settings

/siyaoH-1.17-PlatformMessage
Shiyun Wen 4 年前
当前提交
5ecb8a4e
共有 5 个文件被更改,包括 479 次插入465 次删除
  1. 10
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/GalleryMain.cs
  2. 29
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/GalleryMain.cs
  3. 177
      com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs
  4. 307
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
  5. 421
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanelWrapper.cs

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


using System.Collections.Generic;
using UIWidgetsGallery.gallery;
using Unity.UIWidgets.Editor;
using Unity.UIWidgets.widgets;
using ui_ = Unity.UIWidgets.widgets.ui_;
namespace UIWidgetsEditorWindowSample
{

public static void CountDemo()
{
{
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});
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});
}
protected override void main()

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


using System.Collections.Generic;
using UIWidgetsGallery.gallery;
using Unity.UIWidgets.engine2;
using ui_ = Unity.UIWidgets.widgets.ui_;
using Unity.UIWidgets.widgets;
namespace UIWidgetsGallery
{
public class GalleryMain : UIWidgetsPanel
{
protected new void OnEnable()
{
base.OnEnable();
}
namespace UIWidgetsGallery {
public class GalleryMain : UIWidgetsPanel {
protected override void main() {
protected override void main()
{
//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});
AddFont("1", new List<string>{"gallery/GalleryIcons.ttf"}, new List<int>{0});
}
protected new void OnEnable() {
base.OnEnable();
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});
}
}

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


using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Unity.UIWidgets.services;
using TextFont = Unity.UIWidgets.engine2.UIWidgetsPanel.TextFont;
using Font = Unity.UIWidgets.engine2.UIWidgetsPanel.Font;
readonly Dictionary<string, UIWidgetsPanel.TextFont> _internalTextFonts =
new Dictionary<string, UIWidgetsPanel.TextFont>();
int _currentWidth {
get { return Mathf.RoundToInt(f: position.size.x); }
}
int _currentHeight {
get { return Mathf.RoundToInt(f: position.size.y); }
}
float _currentDevicePixelRatio {
get { return EditorGUIUtility.pixelsPerPoint; }
}
void Update() {
_wrapper.onEditorUpdate();
}
void OnEnable() {
D.assert(_wrapper == null);
_wrapper = new UIWidgetsPanelWrapper();
onEnable();
_wrapper.Initiate(this, width: _currentWidth, height: _currentHeight, dpr: _currentDevicePixelRatio,
settings: _internalTextFonts);
_internalTextFonts.Clear();
Input_OnEnable();
}
void OnDestroy() {
D.assert(_wrapper != null);
_wrapper?.Destroy();
_wrapper = null;
Input_OnDisable();
}
void OnGUI() {
if (_wrapper != null) {
if (_wrapper.didDisplayMetricsChanged(width: _currentWidth, height: _currentHeight,
dpr: _currentDevicePixelRatio)) {
_wrapper.OnDisplayMetricsChanged(width: _currentWidth, height: _currentHeight,
dpr: _currentDevicePixelRatio);
}
GUI.DrawTexture(new Rect(0.0f, 0.0f, width: position.width, height: position.height),
image: _wrapper.renderTexture);
Input_OnGUIEvent(evt: Event.current);
}
}
this.StartCoroutine(routing);
this.StartCoroutine(coroutine: routing);
public void onNewFrameScheduled() {
Repaint();
}

}
int _currentWidth {
get { return Mathf.RoundToInt(position.size.x); }
}
int _currentHeight {
get { return Mathf.RoundToInt(position.size.y); }
public void mainEntry() {
main();
float _currentDevicePixelRatio {
get { return EditorGUIUtility.pixelsPerPoint; }
}
void OnDestroy() {
D.assert(_wrapper != null);
_wrapper?.Destroy();
_wrapper = null;
Input_OnDisable();
protected virtual void onEnable() {
protected virtual void onEnable() {}
Dictionary<string,TextFont> _internalTextFonts = new Dictionary<string, TextFont>();
UnityEngine.Debug.LogError($"The size of {family}‘s assets should be equal to the weights'.");
Debug.LogError($"The size of {family}‘s assets should be equal to the weights'.");
TextFont textFont = new TextFont();
textFont.family = family;
Font[] fonts = new Font[assets.Count];
for (int j = 0; j < assets.Count; j++) {
Font font = new Font();
font.asset = assets[j];
font.weight = weights[j];
fonts[j] = font;
}
textFont.fonts = fonts;
_internalTextFonts.Add(family,textFont);
}
void OnEnable() {
D.assert(_wrapper == null);
_wrapper = new UIWidgetsPanelWrapper();
onEnable();
_wrapper.Initiate(this, _currentWidth, _currentHeight, _currentDevicePixelRatio, _internalTextFonts);
_internalTextFonts.Clear();
Input_OnEnable();
}
void Update() {
_wrapper.onEditorUpdate();
}
if (_internalTextFonts.ContainsKey(key: family)) {
var textFont = _internalTextFonts[key: family];
var fonts = new UIWidgetsPanel.Font[assets.Count];
for (var j = 0; j < assets.Count; j++) {
var font = new UIWidgetsPanel.Font();
font.asset = assets[index: j];
font.weight = weights[index: j];
fonts[j] = font;
}
void OnGUI()
{
if (_wrapper != null) {
if (_wrapper.didDisplayMetricsChanged(_currentWidth, _currentHeight, _currentDevicePixelRatio)) {
_wrapper.OnDisplayMetricsChanged(_currentWidth, _currentHeight, _currentDevicePixelRatio);
textFont.fonts = fonts;
_internalTextFonts[key: family] = textFont;
}
else {
var textFont = new UIWidgetsPanel.TextFont();
textFont.family = family;
var fonts = new UIWidgetsPanel.Font[assets.Count];
for (var j = 0; j < assets.Count; j++) {
var font = new UIWidgetsPanel.Font();
font.asset = assets[index: j];
font.weight = weights[index: j];
fonts[j] = font;
GUI.DrawTexture(new Rect(0.0f, 0.0f, position.width, position.height), _wrapper.renderTexture);
Input_OnGUIEvent(Event.current);
textFont.fonts = fonts;
_internalTextFonts.Add(key: family, value: textFont);
return new Vector2(position.x, position.y);
return new Vector2(x: position.x, y: position.y);
else if (buttonId == 1) {
if (buttonId == 1) {
return -2;
}

void Input_OnGUIEvent(Event evt) {
if (evt.type == EventType.MouseDown) {
var pos = _getPointerPosition(evt.mousePosition);
_wrapper.OnPointerDown(pos, _buttonToPointerId(evt.button));
var pos = _getPointerPosition(position: evt.mousePosition);
_wrapper.OnPointerDown(pos: pos, _buttonToPointerId(buttonId: evt.button));
var pos = _getPointerPosition(evt.mousePosition);
_wrapper.OnPointerUp(pos, _buttonToPointerId(evt.button));
var pos = _getPointerPosition(position: evt.mousePosition);
_wrapper.OnPointerUp(pos: pos, _buttonToPointerId(buttonId: evt.button));
var pos = _getPointerPosition(evt.mousePosition);
_wrapper.OnMouseMove(pos);
var pos = _getPointerPosition(position: evt.mousePosition);
_wrapper.OnMouseMove(pos: pos);
var pos = _getPointerPosition(evt.mousePosition);
_wrapper.OnMouseMove(pos);
var pos = _getPointerPosition(position: evt.mousePosition);
_wrapper.OnMouseMove(pos: pos);
var pos = _getPointerPosition(evt.mousePosition);
_wrapper.OnMouseScroll(delta, pos);
var pos = _getPointerPosition(position: evt.mousePosition);
_wrapper.OnMouseScroll(delta: delta, pos: pos);
}
public void mainEntry() {
main();
}
protected virtual void main() {

}
}
}

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


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.services;
using TextFont = Unity.UIWidgets.engine2.UIWidgetsPanel.TextFont;
using Font = Unity.UIWidgets.engine2.UIWidgetsPanel.Font;
public interface IUIWidgetsWindow {
Offset windowPosToScreenPos(Offset offset);

}
public partial class UIWidgetsPanel : RawImage, IUIWidgetsWindow {
UIWidgetsPanelWrapper _wrapper;
public static List<UIWidgetsPanel> panels = new List<UIWidgetsPanel>();
static bool _ShowDebugLog;
public UIWidgetsWindowType getWindowType() {
return UIWidgetsWindowType.GameObjectPanel;
}
public bool isActive() {
return IsActive();
}
public TextFont[] fonts;
public void startCoroutine(IEnumerator routing) {
StartCoroutine(routing);
}
public bool m_ShowDebugLog;
public void onNewFrameScheduled() {
}
public Offset windowPosToScreenPos(Offset offset) {
Camera camera = null;
if (canvas.renderMode != RenderMode.ScreenSpaceCamera) {
camera = canvas.GetComponent<GraphicRaycaster>().eventCamera;
}
var pos = new Vector2(offset.dx, offset.dy);
pos = pos * _currentDevicePixelRatio / canvas.scaleFactor;
var rect = rectTransform.rect;
pos.x += rect.min.x;
pos.y = rect.max.y - pos.y;
var worldPos = rectTransform.TransformPoint(new Vector2(pos.x, pos.y));
var screenPos = RectTransformUtility.WorldToScreenPoint(camera, worldPos);
return new Offset(screenPos.x, Screen.height - screenPos.y);
}
[Serializable]
public struct Font {
public string asset;
public int weight;
}
[Serializable]
public struct TextFont {
public string family;
[SerializeField] public Font[] fonts;
}
public TextFont[] fonts;
readonly Dictionary<string, TextFont> _internalTextFonts = new Dictionary<string, TextFont>();
UIWidgetsPanelWrapper _wrapper;
int _currentWidth {
get { return Mathf.RoundToInt(rectTransform.rect.width * canvas.scaleFactor); }

float _currentDevicePixelRatio {
get {
float currentDpi = Screen.dpi;
var currentDpi = Screen.dpi;
if (currentDpi == 0) {
currentDpi = canvas.GetComponent<CanvasScaler>().fallbackScreenDPI;
}

}
public bool m_ShowDebugLog = false;
public static List<UIWidgetsPanel> panels = new List<UIWidgetsPanel>();
get => _ShowDebugLog;
get { return _ShowDebugLog; }
set {
foreach (var panel in panels) {
panel.m_ShowDebugLog = value;

}
}
static bool _ShowDebugLog = false;
protected virtual void onEnable() {}
Dictionary<string,TextFont> _internalTextFonts = new Dictionary<string, TextFont>();
protected void AddFont(string family, List<string> assets, List<int> weights) {
if (assets.Count != weights.Count) {
UnityEngine.Debug.LogError($"The size of {family}‘s assets should be equal to the weights'.");
return;
}
if (!_internalTextFonts.ContainsKey(family)) {
TextFont textFont = new TextFont();
textFont.family = family;
Font[] fonts = new Font[assets.Count];
for (int j = 0; j < assets.Count; j++) {
Font font = new Font();
font.asset = assets[j];
font.weight = weights[j];
fonts[j] = font;
}
textFont.fonts = fonts;
_internalTextFonts.Add(family,textFont);
}
protected virtual void Update() {
Input_Update();
}
protected void OnEnable() {

onEnable();
foreach (var font in fonts) {
if(!_internalTextFonts.ContainsKey(font.family))
_internalTextFonts.Add(font.family,font);
}
onEnable();
addFontFromInspector(fonts: fonts);
else {
onEnable();
}
_wrapper.Initiate(this, _currentWidth, _currentHeight, _currentDevicePixelRatio, _internalTextFonts);
_wrapper.Initiate(this, width: _currentWidth, height: _currentHeight, dpr: _currentDevicePixelRatio,
settings: _internalTextFonts);
texture = _wrapper.renderTexture;
_internalTextFonts.Clear();
Input_OnEnable();

TextFont[] loadTextFont() {
TextFont[] textFonts = new TextFont[_internalTextFonts.Count];
List<TextFont> fontValues = _internalTextFonts.Values.ToList();
for (int i = 0; i < fontValues.Count; i++) {
textFonts[i] = fontValues[i];
protected override void OnDisable() {
D.assert(_wrapper != null);
_wrapper?.Destroy();
_wrapper = null;
texture = null;
_internalTextFonts.Clear();
Input_OnDisable();
base.OnDisable();
panels.Remove(this);
}
protected virtual void OnGUI() {
Input_OnGUI();
}
protected override void OnRectTransformDimensionsChange() {
if (_wrapper != null && _wrapper.didDisplayMetricsChanged(width: _currentWidth, height: _currentHeight,
dpr: _currentDevicePixelRatio)) {
_wrapper.OnDisplayMetricsChanged(width: _currentWidth, height: _currentHeight,
dpr: _currentDevicePixelRatio);
texture = _wrapper.renderTexture;
}
}
public UIWidgetsWindowType getWindowType() {
return UIWidgetsWindowType.GameObjectPanel;
}
public bool isActive() {
return IsActive();
}
public void startCoroutine(IEnumerator routing) {
StartCoroutine(routine: routing);
}
public void onNewFrameScheduled() {
}
public Offset windowPosToScreenPos(Offset offset) {
Camera camera = null;
if (canvas.renderMode != RenderMode.ScreenSpaceCamera) {
camera = canvas.GetComponent<GraphicRaycaster>().eventCamera;
return textFonts;
var pos = new Vector2(x: offset.dx, y: offset.dy);
pos = pos * _currentDevicePixelRatio / canvas.scaleFactor;
var rect = rectTransform.rect;
pos.x += rect.min.x;
pos.y = rect.max.y - pos.y;
var worldPos = rectTransform.TransformPoint(new Vector2(x: pos.x, y: pos.y));
var screenPos = RectTransformUtility.WorldToScreenPoint(cam: camera, worldPoint: worldPos);
return new Offset(dx: screenPos.x, Screen.height - screenPos.y);
protected virtual void main() {
protected virtual void onEnable() {
}
protected void AddFont(string family, List<string> assets, List<int> weights) {
if (assets.Count != weights.Count) {
Debug.LogError($"The size of {family}‘s assets should be equal to the weights'.");
return;
}
if (_internalTextFonts.ContainsKey(key: family)) {
var textFont = _internalTextFonts[key: family];
var fonts = new Font[assets.Count];
for (var j = 0; j < assets.Count; j++) {
var font = new Font();
font.asset = assets[index: j];
font.weight = weights[index: j];
fonts[j] = font;
}
textFont.fonts = fonts;
_internalTextFonts[key: family] = textFont;
}
else {
var textFont = new TextFont();
textFont.family = family;
var fonts = new Font[assets.Count];
for (var j = 0; j < assets.Count; j++) {
var font = new Font();
font.asset = assets[index: j];
font.weight = weights[index: j];
fonts[j] = font;
}
textFont.fonts = fonts;
_internalTextFonts.Add(key: family, value: textFont);
}
protected override void OnRectTransformDimensionsChange() {
if (_wrapper != null && _wrapper.didDisplayMetricsChanged(_currentWidth, _currentHeight, _currentDevicePixelRatio)) {
_wrapper.OnDisplayMetricsChanged(_currentWidth, _currentHeight, _currentDevicePixelRatio);
texture = _wrapper.renderTexture;
void addFontFromInspector(TextFont[] fonts) {
foreach (var font in fonts) {
if (_internalTextFonts.ContainsKey(key: font.family)) {
_internalTextFonts[key: font.family] = font;
}
else {
_internalTextFonts.Add(key: font.family, value: font);
}
protected override void OnDisable() {
D.assert(_wrapper != null);
_wrapper?.Destroy();
_wrapper = null;
texture = null;
_internalTextFonts.Clear();
Input_OnDisable();
base.OnDisable();
panels.Remove(this);
protected virtual void main() {
protected virtual void Update() {
Input_Update();
[Serializable]
public struct Font {
public string asset;
public int weight;
protected virtual void OnGUI() {
Input_OnGUI();
[Serializable]
public struct TextFont {
public string family;
[SerializeField] public Font[] fonts;
}
}

Vector2 _lastMousePosition;
public void OnDrag(PointerEventData eventData) {
var pos = _getPointerPosition(position: Input.mousePosition);
_wrapper.OnDrag(pos: pos, pointerId: eventData.pointerId);
}
public void OnPointerDown(PointerEventData eventData) {
var pos = _getPointerPosition(position: Input.mousePosition);
_wrapper.OnPointerDown(pos: pos, pointerId: eventData.pointerId);
}
public void OnPointerEnter(PointerEventData eventData) {
D.assert(eventData.pointerId < 0);
_isEntered = true;
_lastMousePosition = Input.mousePosition;
}
public void OnPointerExit(PointerEventData eventData) {
D.assert(eventData.pointerId < 0);
_isEntered = false;
_wrapper.OnPointerLeave();
}
public void OnPointerUp(PointerEventData eventData) {
var pos = _getPointerPosition(position: Input.mousePosition);
_wrapper.OnPointerUp(pos: pos, pointerId: eventData.pointerId);
}
Camera worldCamera = canvas.worldCamera;
var worldCamera = canvas.worldCamera;
rectTransform, position, worldCamera, out var localPoint)) {
rect: rectTransform, screenPoint: position, cam: worldCamera, out var localPoint)) {
var scaleFactor = canvas.scaleFactor;
localPoint.x = (localPoint.x - rectTransform.rect.min.x) * scaleFactor;
localPoint.y = (rectTransform.rect.max.y - localPoint.y) * scaleFactor;

}
void Input_OnGUI() {
Event e = Event.current;
var e = Event.current;
_wrapper.OnKeyDown(e);
_wrapper.OnKeyDown(e: e);
var pos = _getPointerPosition(Input.mousePosition);
_wrapper.OnMouseMove(pos);
var pos = _getPointerPosition(position: Input.mousePosition);
_wrapper.OnMouseMove(pos: pos);
var pos = _getPointerPosition(Input.mousePosition);
_wrapper.OnMouseScroll(Input.mouseScrollDelta, pos);
}
public void OnPointerDown(PointerEventData eventData) {
var pos = _getPointerPosition(Input.mousePosition);
_wrapper.OnPointerDown(pos, eventData.pointerId);
}
public void OnPointerUp(PointerEventData eventData) {
var pos = _getPointerPosition(Input.mousePosition);
_wrapper.OnPointerUp(pos, eventData.pointerId);
}
public void OnPointerEnter(PointerEventData eventData) {
D.assert(eventData.pointerId < 0);
_isEntered = true;
_lastMousePosition = Input.mousePosition;
}
public void OnPointerExit(PointerEventData eventData) {
D.assert(eventData.pointerId < 0);
_isEntered = false;
_wrapper.OnPointerLeave();
}
public void OnDrag(PointerEventData eventData) {
var pos = _getPointerPosition(Input.mousePosition);
_wrapper.OnDrag(pos, eventData.pointerId);
var pos = _getPointerPosition(position: Input.mousePosition);
_wrapper.OnMouseScroll(delta: Input.mouseScrollDelta, pos: pos);
}
}
}

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


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using AOT;
using Unity.UIWidgets.engine2;

using Unity.UIWidgets.ui;
using UnityEngine;
using TextFont = Unity.UIWidgets.engine2.UIWidgetsPanel.TextFont;
using Font = Unity.UIWidgets.engine2.UIWidgetsPanel.Font;
#region Platform: Windows Specific Functionalities
#region Platform: Windows Specific Functionalities
RenderTexture _renderTexture;
public RenderTexture renderTexture {
get { return _renderTexture; }
}
public RenderTexture renderTexture { get; private set; }
D.assert(_renderTexture == null);
D.assert(renderTexture == null);
width, height, RenderTextureFormat.ARGB32, 0) {
width: width, height: height, colorFormat: RenderTextureFormat.ARGB32, 0) {
autoGenerateMips = false,
autoGenerateMips = false
_renderTexture = new RenderTexture(desc) {hideFlags = HideFlags.HideAndDontSave};
_renderTexture.Create();
renderTexture = new RenderTexture(desc: desc) {hideFlags = HideFlags.HideAndDontSave};
renderTexture.Create();
_devicePixelRatio = devicePixelRatio;
this.devicePixelRatio = devicePixelRatio;
D.assert(_renderTexture != null);
ObjectUtils.SafeDestroy(_renderTexture);
_renderTexture = null;
D.assert(renderTexture != null);
ObjectUtils.SafeDestroy(obj: renderTexture);
renderTexture = null;
UIWidgetsPanel_onEnable(_ptr, _renderTexture.GetNativeTexturePtr(),
_width, _height, _devicePixelRatio, Application.streamingAssetsPath, font_settings);
UIWidgetsPanel_onEnable(ptr: _ptr, renderTexture.GetNativeTexturePtr(),
width: _width, height: _height, dpi: devicePixelRatio,
streamingAssetsPath: Application.streamingAssetsPath, font_settings: font_settings);
UIWidgetsPanel_onRenderTexture(_ptr,
_renderTexture.GetNativeTexturePtr(),
_width, _height, _devicePixelRatio);
UIWidgetsPanel_onRenderTexture(ptr: _ptr,
renderTexture.GetNativeTexturePtr(),
width: _width, height: _height, dpi: devicePixelRatio);
_renderTexture = null;
renderTexture = null;
[DllImport(NativeBindings.dllName)]
[DllImport(dllName: NativeBindings.dllName)]
[DllImport(NativeBindings.dllName)]
[DllImport(dllName: NativeBindings.dllName)]
#endregion
#endregion
#region Platform: MacOs Specific Functionalities
#region Platform: MacOs Specific Functionalities
public partial class UIWidgetsPanelWrapper {
Texture _renderTexture;

#endif
#endregion
#endregion
#region Window Common Properties and Functions
#region Window Common Properties and Functions
public partial class UIWidgetsPanelWrapper {
public static UIWidgetsPanelWrapper current {
get { return Window.instance._panel; }
}
public partial class UIWidgetsPanelWrapper {
public static UIWidgetsPanelWrapper current {
get { return Window.instance._panel; }
}
IntPtr _ptr;
GCHandle _handle;
IntPtr _ptr;
GCHandle _handle;
int _width;
int _height;
float _devicePixelRatio;
int _width;
int _height;
IUIWidgetsWindow _host;
public IUIWidgetsWindow window { get; private set; }
public IUIWidgetsWindow window {
get { return _host; }
}
public Isolate isolate { get; private set; }
public Isolate isolate { get; private set; }
public float devicePixelRatio { get; private set; }
public float devicePixelRatio {
get { return _devicePixelRatio; }
}
public void Initiate(IUIWidgetsWindow host, int width, int height, float dpr,
Dictionary<string, TextFont> settings) {
D.assert(_renderTexture == null);
_recreateRenderTexture(width, height, dpr);
public void Initiate(IUIWidgetsWindow host, int width, int height, float dpr,
Dictionary<string, UIWidgetsPanel.TextFont> settings) {
D.assert(renderTexture == null);
_recreateRenderTexture(width: width, height: height, devicePixelRatio: dpr);
_handle = GCHandle.Alloc(this);
_ptr = UIWidgetsPanel_constructor((IntPtr) _handle, (int) host.getWindowType(), UIWidgetsPanel_entrypoint);
_host = host;
_handle = GCHandle.Alloc(this);
_ptr = UIWidgetsPanel_constructor((IntPtr) _handle, (int) host.getWindowType(),
entrypointCallback: UIWidgetsPanel_entrypoint);
window = host;
TextFont[] textFonts = loadTextFont(settings);
var fontsetting = new Dictionary<string, object>();
fontsetting.Add("fonts", fontsToObject(textFonts));
_enableUIWidgetsPanel(JSONMessageCodec.instance.toJson(fontsetting));
NativeConsole.OnEnable();
}
public TextFont[] loadTextFont(Dictionary<string,TextFont> TextFontsList) {
TextFont[] textFonts = new TextFont[TextFontsList.Count];
List<TextFont> fontValues = TextFontsList.Values.ToList();
for (int i = 0; i < fontValues.Count; i++) {
textFonts[i] = fontValues[i];
var fontsetting = new Dictionary<string, object>();
fontsetting.Add("fonts", fontsToObject(settings: settings));
_enableUIWidgetsPanel(JSONMessageCodec.instance.toJson(message: fontsetting));
NativeConsole.OnEnable();
return textFonts;
}
public void _entryPoint() {
try {
isolate = Isolate.current;
Window.instance._panel = this;
public void _entryPoint() {
try {
isolate = Isolate.current;
Window.instance._panel = this;
_host.mainEntry();
window.mainEntry();
}
catch (Exception ex) {
Debug.LogException(new Exception("exception in main", innerException: ex));
}
catch (Exception ex) {
Debug.LogException(new Exception("exception in main", ex));
public bool didDisplayMetricsChanged(int width, int height, float dpr) {
return width != _width || height != _height || dpr != devicePixelRatio;
}
public bool didDisplayMetricsChanged(int width, int height, float dpr) {
return width != _width || height != _height || dpr != _devicePixelRatio;
}
public void OnDisplayMetricsChanged(int width, int height, float dpr) {
if (_ptr != IntPtr.Zero && _renderTexture) {
if (_recreateRenderTexture(width, height, dpr)) {
_resizeUIWidgetsPanel();
public void OnDisplayMetricsChanged(int width, int height, float dpr) {
if (_ptr != IntPtr.Zero && renderTexture) {
if (_recreateRenderTexture(width: width, height: height, devicePixelRatio: dpr)) {
_resizeUIWidgetsPanel();
}
}
public object fontsToObject(UIWidgetsPanel.TextFont[] textFont) {
if (textFont == null || textFont.Length == 0) {
public object fontsToObject(Dictionary<string, UIWidgetsPanel.TextFont> settings) {
if (settings == null || settings.Count == 0) {
var result = new object[textFont.Length];
for (int i = 0; i < textFont.Length; i++) {
var result = new object[settings.Count];
var i = 0;
foreach (var setting in settings) {
font.Add("family", textFont[i].family);
var dic = new Dictionary<string, object>[textFont[i].fonts.Length];
for (int j = 0; j < textFont[i].fonts.Length; j++) {
font.Add("family", value: setting.Key);
var dic = new Dictionary<string, object>[setting.Value.fonts.Length];
for (var j = 0; j < setting.Value.fonts.Length; j++) {
if (textFont[i].fonts[j].asset.Length > 0) {
dic[j].Add("asset", textFont[i].fonts[j].asset);
if (setting.Value.fonts[j].asset.Length > 0) {
dic[j].Add("asset", value: setting.Value.fonts[j].asset);
if (textFont[i].fonts[j].weight > 0) {
dic[j].Add("weight", textFont[i].fonts[j].weight);
if (setting.Value.fonts[j].weight > 0) {
dic[j].Add("weight", value: setting.Value.fonts[j].weight);
font.Add("fonts", dic);
font.Add("fonts", value: dic);
i++;
public void Destroy() {
UIWidgetsPanel_onDisable(_ptr);
UIWidgetsPanel_dispose(_ptr);
_ptr = IntPtr.Zero;
_handle.Free();
_handle = default;
public void Destroy() {
UIWidgetsPanel_onDisable(ptr: _ptr);
UIWidgetsPanel_dispose(ptr: _ptr);
_ptr = IntPtr.Zero;
_disableUIWidgetsPanel();
D.assert(!isolate.isValid);
}
_handle.Free();
_handle = default;
bool _recreateRenderTexture(int width, int height, float devicePixelRatio) {
if (_renderTexture != null && _width == width && _height == height &&
_devicePixelRatio == devicePixelRatio) {
return false;
_disableUIWidgetsPanel();
D.assert(result: !isolate.isValid);
if (_renderTexture) {
_destroyRenderTexture();
bool _recreateRenderTexture(int width, int height, float devicePixelRatio) {
if (renderTexture != null && _width == width && _height == height &&
this.devicePixelRatio == devicePixelRatio) {
return false;
}
if (renderTexture) {
_destroyRenderTexture();
}
_createRenderTexture(width: width, height: height, devicePixelRatio: devicePixelRatio);
return true;
_createRenderTexture(width, height, devicePixelRatio);
return true;
}
public int registerTexture(Texture texture) {
return UIWidgetsPanel_registerTexture(ptr: _ptr, texture.GetNativeTexturePtr());
}
public int registerTexture(Texture texture) {
return UIWidgetsPanel_registerTexture(_ptr, texture.GetNativeTexturePtr());
}
public void unregisterTexture(int textureId) {
UIWidgetsPanel_unregisterTexture(ptr: _ptr, textureId: textureId);
}
public void unregisterTexture(int textureId) {
UIWidgetsPanel_unregisterTexture(_ptr, textureId);
}
public void markNewFrameAvailable(int textureId) {
UIWidgetsPanel_markNewFrameAvailable(ptr: _ptr, textureId: textureId);
}
public void markNewFrameAvailable(int textureId) {
UIWidgetsPanel_markNewFrameAvailable(_ptr, textureId);
}
public void onEditorUpdate() {
UIWidgetsPanel_onEditorUpdate(ptr: _ptr);
}
public void onEditorUpdate() {
UIWidgetsPanel_onEditorUpdate(_ptr);
}
delegate void UIWidgetsPanel_EntrypointCallback(IntPtr handle);
delegate void UIWidgetsPanel_EntrypointCallback(IntPtr handle);
[MonoPInvokeCallback(typeof(UIWidgetsPanel_EntrypointCallback))]
static void UIWidgetsPanel_entrypoint(IntPtr handle) {
var gcHandle = (GCHandle) handle;
var panel = (UIWidgetsPanelWrapper) gcHandle.Target;
panel._entryPoint();
}
[MonoPInvokeCallback(typeof(UIWidgetsPanel_EntrypointCallback))]
static void UIWidgetsPanel_entrypoint(IntPtr handle) {
GCHandle gcHandle = (GCHandle) handle;
UIWidgetsPanelWrapper panel = (UIWidgetsPanelWrapper) gcHandle.Target;
panel._entryPoint();
}
[DllImport(dllName: NativeBindings.dllName)]
static extern IntPtr UIWidgetsPanel_constructor(IntPtr handle, int windowType,
UIWidgetsPanel_EntrypointCallback entrypointCallback);
[DllImport(NativeBindings.dllName)]
static extern IntPtr UIWidgetsPanel_constructor(IntPtr handle, int windowType,
UIWidgetsPanel_EntrypointCallback entrypointCallback);
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_dispose(IntPtr ptr);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_dispose(IntPtr ptr);
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onDisable(IntPtr ptr);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onDisable(IntPtr ptr);
[DllImport(NativeBindings.dllName)]
static extern int UIWidgetsPanel_registerTexture(IntPtr ptr, IntPtr nativeTexturePtr);
[DllImport(dllName: NativeBindings.dllName)]
static extern int UIWidgetsPanel_registerTexture(IntPtr ptr, IntPtr nativeTexturePtr);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_unregisterTexture(IntPtr ptr, int textureId);
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_unregisterTexture(IntPtr ptr, int textureId);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_markNewFrameAvailable(IntPtr ptr, int textureId);
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_markNewFrameAvailable(IntPtr ptr, int textureId);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onEditorUpdate(IntPtr ptr);
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onEditorUpdate(IntPtr ptr);
}
}
#endregion
#endregion
#region Input Events Handles
#region Input Events Handles
public partial class UIWidgetsPanelWrapper {
public void OnMouseMove(Vector2? pos) {
if (pos == null) {
return;
public partial class UIWidgetsPanelWrapper {
public void OnMouseMove(Vector2? pos) {
if (pos == null) {
return;
}
UIWidgetsPanel_onMouseMove(ptr: _ptr, x: pos.Value.x, y: pos.Value.y);
UIWidgetsPanel_onMouseMove(_ptr, pos.Value.x, pos.Value.y);
}
public void OnMouseScroll(Vector2 delta, Vector2? pos) {
if (pos == null) {
return;
}
public void OnMouseScroll(Vector2 delta, Vector2? pos) {
if (pos == null) {
return;
UIWidgetsPanel_onScroll(ptr: _ptr, x: delta.x, y: delta.y, px: pos.Value.x, py: pos.Value.y);
UIWidgetsPanel_onScroll(_ptr, delta.x, delta.y, pos.Value.x, pos.Value.y);
}
public void OnPointerDown(Vector2? pos, int pointerId) {
if (pos == null) {
return;
public void OnPointerDown(Vector2? pos, int pointerId) {
if (pos == null) {
return;
}
// mouse event
if (pointerId < 0) {
UIWidgetsPanel_onMouseDown(ptr: _ptr, x: pos.Value.x, y: pos.Value.y, button: pointerId);
}
// mouse event
if (pointerId < 0) {
UIWidgetsPanel_onMouseDown(_ptr, pos.Value.x, pos.Value.y, pointerId);
}
}
public void OnPointerUp(Vector2? pos, int pointerId) {
if (pos == null) {
return;
}
public void OnPointerUp(Vector2? pos, int pointerId) {
if (pos == null) {
return;
// mouse event
if (pointerId < 0) {
UIWidgetsPanel_onMouseUp(ptr: _ptr, x: pos.Value.x, y: pos.Value.y, button: pointerId);
}
// mouse event
if (pointerId < 0) {
UIWidgetsPanel_onMouseUp(_ptr, pos.Value.x, pos.Value.y, pointerId);
}
}
public void OnDrag(Vector2? pos, int pointerId) {
if (pos == null) {
return;
}
public void OnDrag(Vector2? pos, int pointerId) {
if (pos == null) {
return;
// mouse event
if (pointerId < 0) {
UIWidgetsPanel_onMouseMove(ptr: _ptr, x: pos.Value.x, y: pos.Value.y);
}
// mouse event
if (pointerId < 0) {
UIWidgetsPanel_onMouseMove(_ptr, pos.Value.x, pos.Value.y);
public void OnPointerLeave() {
UIWidgetsPanel_onMouseLeave(ptr: _ptr);
}
public void OnPointerLeave() {
UIWidgetsPanel_onMouseLeave(_ptr);
}
public void OnKeyDown(Event e) {
UIWidgetsPanel_onKey(_ptr, e.keyCode, e.type == EventType.KeyDown);
if (e.character != 0 || e.keyCode == KeyCode.Backspace) {
PointerEventConverter.KeyEvent.Enqueue(new Event(e));
// TODO: add on char
// UIWidgetsPanel_onChar(_ptr, e.character);
public void OnKeyDown(Event e) {
UIWidgetsPanel_onKey(ptr: _ptr, keyCode: e.keyCode, e.type == EventType.KeyDown);
if (e.character != 0 || e.keyCode == KeyCode.Backspace) {
PointerEventConverter.KeyEvent.Enqueue(new Event(other: e));
// TODO: add on char
// UIWidgetsPanel_onChar(_ptr, e.character);
}
}
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onChar(IntPtr ptr, char c);
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onChar(IntPtr ptr, char c);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onKey(IntPtr ptr, KeyCode keyCode, bool isKeyDown);
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onKey(IntPtr ptr, KeyCode keyCode, bool isKeyDown);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onMouseDown(IntPtr ptr, float x, float y, int button);
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onMouseDown(IntPtr ptr, float x, float y, int button);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onMouseUp(IntPtr ptr, float x, float y, int button);
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onMouseUp(IntPtr ptr, float x, float y, int button);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onMouseMove(IntPtr ptr, float x, float y);
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onMouseMove(IntPtr ptr, float x, float y);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onMouseLeave(IntPtr ptr);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onScroll(IntPtr ptr, float x, float y, float px, float py);
}
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onMouseLeave(IntPtr ptr);
#endregion
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onScroll(IntPtr ptr, float x, float y, float px, float py);
}
#endregion
}
正在加载...
取消
保存