xingweizhu
4 年前
当前提交
f81cba9d
共有 25 个文件被更改,包括 315 次插入 和 197 次删除
-
13com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
-
14com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanelWrapper.cs
-
37engine/src/shell/platform/unity/windows/uiwidgets_panel.cc
-
15engine/src/shell/platform/unity/windows/uiwidgets_panel.h
-
6engine/src/shell/platform/unity/windows/uiwidgets_system.cc
-
38com.unity.uiwidgets/Editor/third_parties/editor_coroutines/EditorCoroutines.cs
-
8Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/CountDemo.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/Editor.meta
-
132com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs
-
8com.unity.uiwidgets/Editor/third_parties.meta
-
15Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/UIWidgetsEditorWindowSample.asmdef
-
7Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/UIWidgetsEditorWindowSample.asmdef.meta
-
39com.unity.uiwidgets/Editor/third_parties/EditorCoroutines.cs
-
8com.unity.uiwidgets/Editor/third_parties/editor_coroutines.meta
-
21com.unity.uiwidgets/Editor/third_parties/editor_coroutines/LISENCE
-
148com.unity.uiwidgets/Runtime/engine2/UIWidgetsEditorPanel.cs
-
0/Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample.meta
-
0/com.unity.uiwidgets/Editor/third_parties/editor_coroutines/EditorCoroutines.cs
-
0/Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/CountDemo.cs
-
0/Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/CountDemo.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: fbf4348f25a14fb7a48fd287e0d01b88 |
|||
timeCreated: 1614220178 |
|
|||
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() { |
|||
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 41a89d8cd28257149b9e6d7116b7d598 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
{ |
|||
"name": "UIWidgetsEditorWindowSample", |
|||
"references": [ |
|||
"Unity.UIWidgets", |
|||
"Unity.UIWidgets.Editor" |
|||
], |
|||
"optionalUnityReferences": [], |
|||
"includePlatforms": [], |
|||
"excludePlatforms": [], |
|||
"allowUnsafeCode": false, |
|||
"overrideReferences": false, |
|||
"precompiledReferences": [], |
|||
"autoReferenced": true, |
|||
"defineConstraints": [] |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0ee4c4c70c305834389c168df0125409 |
|||
AssemblyDefinitionImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d2360e9d4e895a442a14215d1d4953f7 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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. |
|
|||
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
|
|||
|
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue