浏览代码

refine code

/siyaoH-1.17-PlatformMessage
xingweizhu 4 年前
当前提交
f81cba9d
共有 25 个文件被更改,包括 315 次插入197 次删除
  1. 13
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
  2. 14
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanelWrapper.cs
  3. 37
      engine/src/shell/platform/unity/windows/uiwidgets_panel.cc
  4. 15
      engine/src/shell/platform/unity/windows/uiwidgets_panel.h
  5. 6
      engine/src/shell/platform/unity/windows/uiwidgets_system.cc
  6. 38
      com.unity.uiwidgets/Editor/third_parties/editor_coroutines/EditorCoroutines.cs
  7. 8
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/CountDemo.cs
  8. 3
      Samples/UIWidgetsSamples_2019_4/Assets/Editor.meta
  9. 132
      com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs
  10. 8
      com.unity.uiwidgets/Editor/third_parties.meta
  11. 15
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/UIWidgetsEditorWindowSample.asmdef
  12. 7
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/UIWidgetsEditorWindowSample.asmdef.meta
  13. 39
      com.unity.uiwidgets/Editor/third_parties/EditorCoroutines.cs
  14. 8
      com.unity.uiwidgets/Editor/third_parties/editor_coroutines.meta
  15. 21
      com.unity.uiwidgets/Editor/third_parties/editor_coroutines/LISENCE
  16. 148
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsEditorPanel.cs
  17. 0
      /Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample.meta
  18. 0
      /com.unity.uiwidgets/Editor/third_parties/editor_coroutines/EditorCoroutines.cs
  19. 0
      /Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/CountDemo.cs
  20. 0
      /Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/CountDemo.cs.meta

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


using UnityEngine.UI;
namespace Unity.UIWidgets.engine2 {
public enum UIWidgetsWindowType {
InvalidPanel = 0,
GameObjectPanel = 1,
EditorWindowPanel = 2
}
public interface IUIWidgetsWindow {
Offset windowPosToScreenPos(Offset offset);

void mainEntry();
void onNewFrameScheduled();
UIWidgetsWindowType getWindowType();
}
public partial class UIWidgetsPanel : RawImage, IUIWidgetsWindow {

public bool hardwareAntiAliasing;
public UIWidgetsWindowType getWindowType() {
return UIWidgetsWindowType.GameObjectPanel;
}
public bool isActive() {
return IsActive();
}

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


_recreateRenderTexture(width, height, dpr);
_handle = GCHandle.Alloc(this);
_ptr = UIWidgetsPanel_constructor((IntPtr) _handle, UIWidgetsPanel_entrypoint);
_ptr = UIWidgetsPanel_constructor((IntPtr) _handle, (int) host.getWindowType(), UIWidgetsPanel_entrypoint);
_host = host;
_enableUIWidgetsPanel(JSONMessageCodec.instance.toJson(settings));

UIWidgetsPanel_markNewFrameAvailable(_ptr, textureId);
}
public void onEditorUpdate() {
UIWidgetsPanel_onEditorUpdate(_ptr);
}
delegate void UIWidgetsPanel_EntrypointCallback(IntPtr handle);

}
[DllImport(NativeBindings.dllName)]
static extern IntPtr UIWidgetsPanel_constructor(IntPtr handle,
static extern IntPtr UIWidgetsPanel_constructor(IntPtr handle, int windowType,
UIWidgetsPanel_EntrypointCallback entrypointCallback);
[DllImport(NativeBindings.dllName)]

[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_markNewFrameAvailable(IntPtr ptr, int textureId);
#if UNITY_EDITOR
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onEditorUpdate(IntPtr ptr);
#else
static void UIWidgetsPanel_onEditorUpdate(IntPtr ptr) { throw new NotImplementedException(); }
#endif
}
#endregion

37
engine/src/shell/platform/unity/windows/uiwidgets_panel.cc


namespace uiwidgets {
fml::RefPtr<UIWidgetsPanel> UIWidgetsPanel::Create(
Mono_Handle handle, EntrypointCallback entrypoint_callback) {
return fml::MakeRefCounted<UIWidgetsPanel>(handle, entrypoint_callback);
Mono_Handle handle, UIWidgetsWindowType window_type, EntrypointCallback entrypoint_callback) {
return fml::MakeRefCounted<UIWidgetsPanel>(handle, window_type, entrypoint_callback);
UIWidgetsWindowType window_type,
: handle_(handle), entrypoint_callback_(entrypoint_callback) {}
: handle_(handle), window_type_(window_type), entrypoint_callback_(entrypoint_callback) {}
bool UIWidgetsPanel::NeedUpdateByPlayerLoop() {
return window_type_ == GameObjectPanel;
}
bool UIWidgetsPanel::NeedUpdateByEditorLoop() {
return window_type_ == EditorWindowPanel;
}
void UIWidgetsPanel::OnEnable(void* native_texture_ptr, size_t width,
size_t height, float device_pixel_ratio,

UIWIDGETS_API(UIWidgetsPanel*)
UIWidgetsPanel_constructor(
Mono_Handle handle,
Mono_Handle handle, int windowType,
const auto panel = UIWidgetsPanel::Create(handle, entrypoint_callback);
UIWidgetsWindowType window_type = static_cast<UIWidgetsWindowType>(windowType);
const auto panel = UIWidgetsPanel::Create(handle, window_type, entrypoint_callback);
panel->AddRef();
return panel.get();
}

UIWIDGETS_API(void)
UIWidgetsPanel_onMouseLeave(UIWidgetsPanel* panel) { panel->OnMouseLeave(); }
UIWIDGETS_API(void)
UIWidgetsPanel_onEditorUpdate(UIWidgetsPanel* panel) {
if (!panel->NeedUpdateByEditorLoop()) {
std::cerr << "only EditorWindowPanel can be updated using onEditorUpdate" << std::endl;
return;
}
//_Update
panel->ProcessMessages();
//_ProcessVSync
panel->ProcessVSync();
//_Wait
panel->ProcessMessages();
}
} // namespace uiwidgets

15
engine/src/shell/platform/unity/windows/uiwidgets_panel.h


namespace uiwidgets {
enum UIWidgetsWindowType {
InvalidPanel = 0,
GameObjectPanel = 1,
EditorWindowPanel = 2
};
struct MouseState {
bool state_is_down = false;
bool state_is_added = false;

typedef void (*EntrypointCallback)(Mono_Handle handle);
static fml::RefPtr<UIWidgetsPanel> Create(
Mono_Handle handle, EntrypointCallback entrypoint_callback);
Mono_Handle handle, UIWidgetsWindowType window_type, EntrypointCallback entrypoint_callback);
~UIWidgetsPanel();

void OnMouseLeave();
bool NeedUpdateByPlayerLoop();
bool NeedUpdateByEditorLoop();
UIWidgetsPanel(Mono_Handle handle, EntrypointCallback entrypoint_callback);
UIWidgetsPanel(Mono_Handle handle, UIWidgetsWindowType window_type, EntrypointCallback entrypoint_callback);
MouseState GetMouseState() { return mouse_state_; }

Mono_Handle handle_;
EntrypointCallback entrypoint_callback_;
UIWidgetsWindowType window_type_;
std::unique_ptr<UnitySurfaceManager> surface_manager_;
GLuint fbo_ = 0;

6
engine/src/shell/platform/unity/windows/uiwidgets_system.cc


void UIWidgetsSystem::Update() {
TimePoint next_event_time = TimePoint::max();
for (auto* uiwidgets_panel : uiwidgets_panels_) {
if (!uiwidgets_panel->NeedUpdateByPlayerLoop()) {
continue;
}
std::chrono::nanoseconds wait_duration = uiwidgets_panel->ProcessMessages();
if (wait_duration != std::chrono::nanoseconds::max()) {
next_event_time =

void UIWidgetsSystem::VSync() {
for (auto* uiwidgets_panel : uiwidgets_panels_) {
if (!uiwidgets_panel->NeedUpdateByPlayerLoop()) {
continue;
}
uiwidgets_panel->ProcessVSync();
}
}

38
com.unity.uiwidgets/Editor/third_parties/editor_coroutines/EditorCoroutines.cs


using System;
using System.Reflection;
namespace Unity.UIWidgets.editor2 {
public class EditorCoroutines
namespace marijnz.EditorCoroutines
{
public class EditorCoroutines
{
public class EditorCoroutine
{

return field.GetValue(instance);
}
}
public static class EditorCoroutineExtensions
{
public static EditorCoroutines.EditorCoroutine StartCoroutine(this EditorWindow thisRef, IEnumerator coroutine)
{
return EditorCoroutines.StartCoroutine(coroutine, thisRef);
}
public static EditorCoroutines.EditorCoroutine StartCoroutine(this EditorWindow thisRef, string methodName)
{
return EditorCoroutines.StartCoroutine(methodName, thisRef);
}
public static EditorCoroutines.EditorCoroutine StartCoroutine(this EditorWindow thisRef, string methodName, object value)
{
return EditorCoroutines.StartCoroutine(methodName, value, thisRef);
}
public static void StopCoroutine(this EditorWindow thisRef, IEnumerator coroutine)
{
EditorCoroutines.StopCoroutine(coroutine, thisRef);
}
public static void StopCoroutine(this EditorWindow thisRef, string methodName)
{
EditorCoroutines.StopCoroutine(methodName, thisRef);
}
public static void StopAllCoroutines(this EditorWindow thisRef)
{
EditorCoroutines.StopAllCoroutines(thisRef);
}
}
}

8
Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/CountDemo.cs


using System.Collections.Generic;
using Unity.UIWidgets.cupertino;
using Unity.UIWidgets.editor2;
using Unity.UIWidgets.engine2;
using Unity.UIWidgets.Editor;
using UnityEngine.UI;
namespace UIWidgetsSample
namespace UIWidgetsEditorWindowSample
{
public class EditorWindowCountDemo : UIWidgetsEditorPanel
{

}
}
internal class EditorWindowCounterState : State<CounterApp>
internal class EditorWindowCounterState : State<EditorWindowCounterApp>
{
private int count = 0;

3
Samples/UIWidgetsSamples_2019_4/Assets/Editor.meta


fileFormatVersion: 2
guid: fbf4348f25a14fb7a48fd287e0d01b88
timeCreated: 1614220178

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


using System.Collections;
using System.Collections.Generic;
using uiwidgets;
using Unity.UIWidgets.editor2;
using Unity.UIWidgets.engine2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEditor;
using UnityEngine;
using Rect = UnityEngine.Rect;
namespace Unity.UIWidgets.Editor {
public class UIWidgetsEditorPanel : EditorWindow, IUIWidgetsWindow {
UIWidgetsPanelWrapper _wrapper;
public UIWidgetsWindowType getWindowType() {
return UIWidgetsWindowType.EditorWindowPanel;
}
public bool isActive() {
return true;
}
public void startCoroutine(IEnumerator routing) {
this.StartCoroutine(routing);
}
public void onNewFrameScheduled() {
Repaint();
}
public Offset windowPosToScreenPos(Offset offset) {
return offset;
}
int _currentWidth {
get { return Mathf.RoundToInt(position.size.x); }
}
int _currentHeight {
get { return Mathf.RoundToInt(position.size.y); }
}
float _currentDevicePixelRatio {
get { return EditorGUIUtility.pixelsPerPoint; }
}
void OnDestroy() {
D.assert(_wrapper != null);
_wrapper?.Destroy();
_wrapper = null;
Input_OnDisable();
}
void OnEnable() {
D.assert(_wrapper == null);
_wrapper = new UIWidgetsPanelWrapper();
_wrapper.Initiate(this, _currentWidth, _currentHeight, _currentDevicePixelRatio, new Dictionary<string, object>());
Input_OnEnable();
}
void Update() {
_wrapper.onEditorUpdate();
}
void OnGUI()
{
if (_wrapper != null) {
if (_wrapper.didDisplayMetricsChanged(_currentWidth, _currentHeight, _currentDevicePixelRatio)) {
_wrapper.OnDisplayMetricsChanged(_currentWidth, _currentHeight, _currentDevicePixelRatio);
}
GUI.DrawTexture(new Rect(0.0f, 0.0f, position.width, position.height), _wrapper.renderTexture);
Input_OnGUIEvent(Event.current);
}
}
Vector2? _getPointerPosition(Vector2 position) {
return new Vector2(position.x, position.y);
}
int _buttonToPointerId(int buttonId) {
if (buttonId == 0) {
return -1;
}
else if (buttonId == 1) {
return -2;
}
return 0;
}
void Input_OnGUIEvent(Event evt) {
if (evt.type == EventType.MouseDown) {
var pos = _getPointerPosition(evt.mousePosition);
_wrapper.OnPointerDown(pos, _buttonToPointerId(evt.button));
}
else if (evt.type == EventType.MouseUp || evt.rawType == EventType.MouseUp) {
var pos = _getPointerPosition(evt.mousePosition);
_wrapper.OnPointerUp(pos, _buttonToPointerId(evt.button));
}
else if (evt.type == EventType.MouseDrag) {
var pos = _getPointerPosition(evt.mousePosition);
_wrapper.OnMouseMove(pos);
}
else if (evt.type == EventType.MouseMove) {
var pos = _getPointerPosition(evt.mousePosition);
_wrapper.OnMouseMove(pos);
}
}
public void mainEntry() {
main();
}
protected virtual void main() {
}
void Input_OnDisable() {
}
void Input_OnEnable() {
}
}
}

8
com.unity.uiwidgets/Editor/third_parties.meta


fileFormatVersion: 2
guid: 41a89d8cd28257149b9e6d7116b7d598
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

15
Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/UIWidgetsEditorWindowSample.asmdef


{
"name": "UIWidgetsEditorWindowSample",
"references": [
"Unity.UIWidgets",
"Unity.UIWidgets.Editor"
],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
}

7
Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/UIWidgetsEditorWindowSample.asmdef.meta


fileFormatVersion: 2
guid: 0ee4c4c70c305834389c168df0125409
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

39
com.unity.uiwidgets/Editor/third_parties/EditorCoroutines.cs


using System.Collections;
using UnityEditor;
using marijnz.EditorCoroutines;
namespace Unity.UIWidgets.Editor {
public static class UIWidgetsEditorCoroutineExtensions
{
public static EditorCoroutines.EditorCoroutine StartCoroutine(this EditorWindow thisRef, IEnumerator coroutine)
{
return EditorCoroutines.StartCoroutine(coroutine, thisRef);
}
public static EditorCoroutines.EditorCoroutine StartCoroutine(this EditorWindow thisRef, string methodName)
{
return EditorCoroutines.StartCoroutine(methodName, thisRef);
}
public static EditorCoroutines.EditorCoroutine StartCoroutine(this EditorWindow thisRef, string methodName, object value)
{
return EditorCoroutines.StartCoroutine(methodName, value, thisRef);
}
public static void StopCoroutine(this EditorWindow thisRef, IEnumerator coroutine)
{
EditorCoroutines.StopCoroutine(coroutine, thisRef);
}
public static void StopCoroutine(this EditorWindow thisRef, string methodName)
{
EditorCoroutines.StopCoroutine(methodName, thisRef);
}
public static void StopAllCoroutines(this EditorWindow thisRef)
{
EditorCoroutines.StopAllCoroutines(thisRef);
}
}
}

8
com.unity.uiwidgets/Editor/third_parties/editor_coroutines.meta


fileFormatVersion: 2
guid: d2360e9d4e895a442a14215d1d4953f7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

21
com.unity.uiwidgets/Editor/third_parties/editor_coroutines/LISENCE


MIT License
Copyright (c) 2017 Marijn Zwemmer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

148
com.unity.uiwidgets/Runtime/engine2/UIWidgetsEditorPanel.cs


using System.Collections;
using System.Collections.Generic;
using uiwidgets;
using Unity.UIWidgets.engine2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEditor;
using UnityEngine;
using Rect = UnityEngine.Rect;
namespace Unity.UIWidgets.editor2 {
#if UNITY_EDITOR
class MyApp : StatelessWidget
{
public override Widget build(BuildContext context)
{
return new WidgetsApp(
home: new Container(color: Colors.blue),
pageRouteBuilder: (settings, builder) =>
new PageRouteBuilder(
settings: settings,
pageBuilder: (Buildcontext, animation, secondaryAnimation) => builder(context)
)
);
}
}
public class UIWidgetsEditorPanel : EditorWindow, IUIWidgetsWindow {
UIWidgetsPanelWrapper _wrapper;
public bool isActive() {
return true;
}
public void startCoroutine(IEnumerator routing) {
this.StartCoroutine(routing);
}
public void onNewFrameScheduled() {
Repaint();
}
public Offset windowPosToScreenPos(Offset offset) {
return offset;
}
int _currentWidth {
get { return Mathf.RoundToInt(position.size.x); }
}
int _currentHeight {
get { return Mathf.RoundToInt(position.size.y); }
}
float _currentDevicePixelRatio {
get { return EditorGUIUtility.pixelsPerPoint; }
}
void OnDestroy() {
D.assert(_wrapper != null);
_wrapper?.Destroy();
_wrapper = null;
Input_OnDisable();
Debug.Log("destroy");
}
void OnEnable() {
D.assert(_wrapper == null);
_wrapper = new UIWidgetsPanelWrapper();
_wrapper.Initiate(this, _currentWidth, _currentHeight, _currentDevicePixelRatio, new Dictionary<string, object>());
Input_OnEnable();
Debug.Log("enabled");
}
void OnGUI()
{
if (_wrapper != null) {
if (_wrapper.didDisplayMetricsChanged(_currentWidth, _currentHeight, _currentDevicePixelRatio)) {
_wrapper.OnDisplayMetricsChanged(_currentWidth, _currentHeight, _currentDevicePixelRatio);
}
GUI.DrawTexture(new Rect(0.0f, 0.0f, position.width, position.height), _wrapper.renderTexture);
Input_OnGUIEvent(Event.current);
Repaint();
}
}
Vector2? _getPointerPosition(Vector2 position) {
return new Vector2(position.x * _currentDevicePixelRatio, position.y * _currentDevicePixelRatio);
}
int _buttonToPointerId(int buttonId) {
if (buttonId == 0) {
return -1;
}
else if (buttonId == 1) {
return -2;
}
return 0;
}
void Input_OnGUIEvent(Event evt) {
if (evt.type == EventType.MouseDown) {
var pos = _getPointerPosition(evt.mousePosition);
_wrapper.OnPointerDown(pos, _buttonToPointerId(evt.button));
}
else if (evt.type == EventType.MouseUp || evt.rawType == EventType.MouseUp) {
var pos = _getPointerPosition(evt.mousePosition);
_wrapper.OnPointerUp(pos, _buttonToPointerId(evt.button));
}
else if (evt.type == EventType.MouseDrag) {
var pos = _getPointerPosition(evt.mousePosition);
_wrapper.OnMouseMove(pos);
}
else if (evt.type == EventType.MouseMove) {
var pos = _getPointerPosition(evt.mousePosition);
_wrapper.OnMouseMove(pos);
}
}
public void mainEntry() {
main();
}
protected virtual void main() {
}
void Input_OnDisable() {
}
void Input_OnEnable() {
}
}
#endif
}

/Samples/UIWidgetsSamples_2019_4/Assets/EditorWindowSample.meta → /Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample.meta

/com.unity.uiwidgets/Runtime/engine2/EditorCoroutines.cs → /com.unity.uiwidgets/Editor/third_parties/editor_coroutines/EditorCoroutines.cs

/Samples/UIWidgetsSamples_2019_4/Assets/EditorWindowSample/CountDemo.cs → /Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/CountDemo.cs

/Samples/UIWidgetsSamples_2019_4/Assets/EditorWindowSample/CountDemo.cs.meta → /Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/CountDemo.cs.meta

正在加载...
取消
保存