浏览代码
Merge branch 'widgets_panel' into 'master'
Merge branch 'widgets_panel' into 'master'
WidgetCanvas => UIWidgetsPanel See merge request upm-packages/ui-widgets/com.unity.uiwidgets!92/main
Shenhua Gu
6 年前
当前提交
a76b4fe6
共有 62 个文件被更改,包括 627 次插入 和 642 次删除
-
25README.md
-
6Runtime/editor/editor_window.cs
-
4Runtime/widgets/app.cs
-
11Samples/MaterialSample/DividerButton.cs
-
10Samples/ReduxSample/CounterApp/CounterApp.unity
-
8Samples/ReduxSample/CounterApp/CounterAppSample.cs
-
10Samples/ReduxSample/ObjectFinder/ObjectFinderApp.cs
-
14Samples/UIWidgetSample/UIWidgetSample.unity
-
13Samples/UIWidgetSample/ToDoAppSample.cs
-
18Samples/UIWidgetSample/TextInputSample.cs
-
24Samples/UIWidgetSample/NavigationSample.cs
-
10Samples/UIWidgetSample/MaterialSample.cs
-
10Samples/UIWidgetSample/ExpansionPanelSample.cs
-
28Samples/UIWidgetSample/DragDropSample.cs
-
15Samples/UIWidgetSample/CustomPaintSample.cs
-
55Samples/UIWidgetSample/AsScreenSample.cs
-
2Tests/Editor/EditableTextWiget.cs
-
2Tests/Editor/Widgets.cs
-
9Runtime/editor/editor_utils.cs
-
328Runtime/engine/UIWidgetsPanel.cs
-
29Samples/UIWidgetSample/PageViewSample.cs
-
44Samples/UIWidgetSample/ScrollbarSample.cs
-
20Samples/UIWidgetSample/UIWidgetsSamplePanel.cs
-
11Samples/UIWidgetSample/UIWidgetsSamplePanel.cs.meta
-
45Samples/UIWidgetSample/Utils.cs
-
11Samples/UIWidgetSample/Utils.cs.meta
-
27Editor/EditorExample.cs
-
11Editor/EditorExample.cs.meta
-
8Editor/editor.meta
-
366Runtime/engine/WidgetCanvas.cs
-
6Samples/ReduxSample/ReduxSample.asmdef
-
7Samples/ReduxSample/ReduxSample.asmdef.meta
-
6Samples/UIWidgetSample/UIWidgetSample.asmdef
-
7Samples/UIWidgetSample/UIWidgetSample.asmdef.meta
-
27Samples/UIWidgetSample/PageViewCanvas.cs
-
42Samples/UIWidgetSample/ScrollbarCanvas.cs
-
0/Runtime/engine/UIWidgetsPanel.cs.meta
-
0/Samples/MaterialSample/DividerButton.cs.meta
-
0/Samples/MaterialSample/DividerButton.cs
-
0/Samples/ReduxSample/CounterApp/CounterAppSample.cs.meta
-
0/Samples/ReduxSample/CounterApp/CounterAppSample.cs
-
0/Samples/UIWidgetSample/ToDoAppSample.cs.meta
-
0/Samples/UIWidgetSample/ToDoAppSample.cs
-
0/Samples/UIWidgetSample/TextInputSample.cs.meta
-
0/Samples/UIWidgetSample/TextInputSample.cs
-
0/Samples/UIWidgetSample/ScrollbarSample.cs.meta
-
0/Samples/UIWidgetSample/PageViewSample.cs.meta
-
0/Samples/UIWidgetSample/NavigationSample.cs.meta
-
0/Samples/UIWidgetSample/NavigationSample.cs
-
0/Samples/UIWidgetSample/MaterialSample.cs.meta
-
0/Samples/UIWidgetSample/MaterialSample.cs
-
0/Samples/UIWidgetSample/ExpansionPanelSample.cs.meta
-
0/Samples/UIWidgetSample/ExpansionPanelSample.cs
-
0/Samples/UIWidgetSample/DragDropSample.cs.meta
-
0/Samples/UIWidgetSample/DragDropSample.cs
-
0/Samples/UIWidgetSample/CustomPaintSample.cs.meta
-
0/Samples/UIWidgetSample/CustomPaintSample.cs
-
0/Samples/UIWidgetSample/AsScreenSample.cs.meta
-
0/Samples/UIWidgetSample/AsScreenSample.cs
-
0/Runtime/editor/editor_utils.cs
-
0/Runtime/editor/editor_utils.cs.meta
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.async; |
|||
using Unity.UIWidgets.editor; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using UnityEngine.EventSystems; |
|||
using UnityEngine.UI; |
|||
using RawImage = UnityEngine.UI.RawImage; |
|||
using Rect = UnityEngine.Rect; |
|||
|
|||
namespace Unity.UIWidgets.engine { |
|||
public class UIWidgetWindowAdapter : WindowAdapter { |
|||
readonly UIWidgetsPanel _uiWidgetsPanel; |
|||
bool _needsPaint; |
|||
|
|||
protected override void updateSafeArea() { |
|||
this._padding = new WindowPadding( |
|||
Screen.safeArea.x, |
|||
Screen.safeArea.y, |
|||
Screen.width - Screen.safeArea.width, |
|||
Screen.height - Screen.safeArea.height); |
|||
} |
|||
|
|||
public override void scheduleFrame(bool regenerateLayerTree = true) { |
|||
base.scheduleFrame(regenerateLayerTree); |
|||
this._needsPaint = true; |
|||
} |
|||
|
|||
public UIWidgetWindowAdapter(UIWidgetsPanel uiWidgetsPanel) { |
|||
this._uiWidgetsPanel = uiWidgetsPanel; |
|||
} |
|||
|
|||
|
|||
public override void OnGUI(Event evt) { |
|||
if (this.displayMetricsChanged()) { |
|||
this._needsPaint = true; |
|||
} |
|||
|
|||
if (evt.type == EventType.Repaint) { |
|||
if (!this._needsPaint) { |
|||
return; |
|||
} |
|||
|
|||
this._needsPaint = false; |
|||
} |
|||
|
|||
base.OnGUI(evt); |
|||
} |
|||
|
|||
protected override Surface createSurface() { |
|||
return new EditorWindowSurface(this._uiWidgetsPanel.applyRenderTexture); |
|||
} |
|||
|
|||
public override GUIContent titleContent { |
|||
get { return new GUIContent(this._uiWidgetsPanel.gameObject.name); } |
|||
} |
|||
|
|||
protected override float queryDevicePixelRatio() { |
|||
return this._uiWidgetsPanel.devicePixelRatio; |
|||
} |
|||
|
|||
protected override Vector2 queryWindowSize() { |
|||
var rect = this._uiWidgetsPanel.rectTransform.rect; |
|||
var size = new Vector2(rect.width,rect.height) * |
|||
this._uiWidgetsPanel.canvas.scaleFactor / this._uiWidgetsPanel.devicePixelRatio; |
|||
size.x = Mathf.Round(size.x); |
|||
size.y = Mathf.Round(size.y); |
|||
return size; |
|||
} |
|||
} |
|||
|
|||
[RequireComponent(typeof(RectTransform))] |
|||
public class UIWidgetsPanel : RawImage, IPointerDownHandler, IPointerUpHandler, IDragHandler, |
|||
IPointerEnterHandler, IPointerExitHandler { |
|||
static Event _repaintEvent; |
|||
|
|||
[SerializeField] protected float devicePixelRatioOverride; |
|||
WindowAdapter _windowAdapter; |
|||
Texture _texture; |
|||
Vector2 _lastMouseMove; |
|||
|
|||
HashSet<int> _enteredPointers; |
|||
|
|||
bool _mouseEntered { |
|||
get { return !this._enteredPointers.isEmpty(); } |
|||
} |
|||
|
|||
readonly ScrollInput _scrollInput = new ScrollInput(); |
|||
DisplayMetrics _displayMetrics; |
|||
|
|||
const int mouseButtonNum = 3; |
|||
|
|||
protected override void OnEnable() { |
|||
base.OnEnable(); |
|||
|
|||
//Disable the default touch -> mouse event conversion on mobile devices
|
|||
Input.simulateMouseWithTouches = false; |
|||
|
|||
this._displayMetrics = DisplayMetricsProvider.provider(); |
|||
|
|||
if (_repaintEvent == null) { |
|||
_repaintEvent = new Event {type = EventType.Repaint}; |
|||
} |
|||
|
|||
D.assert(this._windowAdapter == null); |
|||
this._windowAdapter = new UIWidgetWindowAdapter(this); |
|||
|
|||
this._windowAdapter.OnEnable(); |
|||
|
|||
Widget root; |
|||
using (this._windowAdapter.getScope()) { |
|||
root = this.createWidget(); |
|||
} |
|||
this._windowAdapter.attachRootWidget(root); |
|||
this._lastMouseMove = Input.mousePosition; |
|||
|
|||
this._enteredPointers = new HashSet<int>(); |
|||
} |
|||
|
|||
public float devicePixelRatio { |
|||
get { |
|||
return this.devicePixelRatioOverride > 0 |
|||
? this.devicePixelRatioOverride |
|||
: this._displayMetrics.DevicePixelRatio; |
|||
} |
|||
} |
|||
|
|||
protected override void OnDisable() { |
|||
D.assert(this._windowAdapter != null); |
|||
this._windowAdapter.OnDisable(); |
|||
this._windowAdapter = null; |
|||
base.OnDisable(); |
|||
} |
|||
|
|||
protected virtual Widget createWidget() { |
|||
return null; |
|||
} |
|||
|
|||
internal void applyRenderTexture(Rect screenRect, Texture texture, Material mat) { |
|||
this.texture = texture; |
|||
this.material = mat; |
|||
} |
|||
|
|||
void Update() { |
|||
this._displayMetrics.Update(); |
|||
if (EventSystem.current != null && EventSystem.current.currentSelectedGameObject != this.gameObject) { |
|||
this.unfocusIfNeeded(); |
|||
} |
|||
|
|||
if (this._mouseEntered) { |
|||
if (this._lastMouseMove.x != Input.mousePosition.x || this._lastMouseMove.y != Input.mousePosition.y) { |
|||
this.handleMouseMovement(); |
|||
} |
|||
} |
|||
|
|||
this._lastMouseMove = Input.mousePosition; |
|||
|
|||
if (this._mouseEntered) { |
|||
this.handleMouseScroll(); |
|||
} |
|||
|
|||
D.assert(this._windowAdapter != null); |
|||
this._windowAdapter.Update(); |
|||
this._windowAdapter.OnGUI(_repaintEvent); |
|||
} |
|||
|
|||
void OnGUI() { |
|||
this._displayMetrics.OnGUI(); |
|||
if (Event.current.type == EventType.KeyDown || Event.current.type == EventType.KeyUp) { |
|||
this._windowAdapter.OnGUI(Event.current); |
|||
} |
|||
} |
|||
|
|||
void handleMouseMovement() { |
|||
var pos = this.getPointPosition(Input.mousePosition); |
|||
this._windowAdapter.postPointerEvent(new PointerData( |
|||
timeStamp: Timer.timespanSinceStartup, |
|||
change: PointerChange.hover, |
|||
kind: PointerDeviceKind.mouse, |
|||
device: this.getMouseButtonDown(), |
|||
physicalX: pos.x, |
|||
physicalY: pos.y |
|||
)); |
|||
} |
|||
|
|||
void handleMouseScroll() { |
|||
if (Input.mouseScrollDelta.y != 0 || Input.mouseScrollDelta.x != 0) { |
|||
var scaleFactor = this.canvas.scaleFactor; |
|||
var pos = this.getPointPosition(Input.mousePosition); |
|||
this._scrollInput.onScroll(Input.mouseScrollDelta.x * scaleFactor, |
|||
Input.mouseScrollDelta.y * scaleFactor, |
|||
pos.x, |
|||
pos.y, |
|||
InputUtils.getScrollButtonKey()); |
|||
} |
|||
|
|||
var deltaScroll = this._scrollInput.getScrollDelta(); |
|||
if (deltaScroll != Vector2.zero) { |
|||
this._windowAdapter.postPointerEvent(new ScrollData( |
|||
timeStamp: Timer.timespanSinceStartup, |
|||
change: PointerChange.scroll, |
|||
kind: PointerDeviceKind.mouse, |
|||
device: this._scrollInput.getDeviceId(), |
|||
physicalX: this._scrollInput.getPointerPosX(), |
|||
physicalY: this._scrollInput.getPointerPosY(), |
|||
scrollX: deltaScroll.x, |
|||
scrollY: deltaScroll.y |
|||
)); |
|||
} |
|||
} |
|||
|
|||
int getMouseButtonDown() { |
|||
for (int key = 0; key < mouseButtonNum; key++) { |
|||
if (Input.GetMouseButton(key)) { |
|||
return InputUtils.getMouseButtonKey(key); |
|||
} |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
public void OnPointerDown(PointerEventData eventData) { |
|||
EventSystem.current.SetSelectedGameObject(this.gameObject, eventData); |
|||
var position = this.getPointPosition(eventData); |
|||
this._windowAdapter.postPointerEvent(new PointerData( |
|||
timeStamp: Timer.timespanSinceStartup, |
|||
change: PointerChange.down, |
|||
kind: InputUtils.getPointerDeviceKind(eventData), |
|||
device: InputUtils.getPointerDeviceKey(eventData), |
|||
physicalX: position.x, |
|||
physicalY: position.y |
|||
)); |
|||
} |
|||
|
|||
public void OnPointerUp(PointerEventData eventData) { |
|||
var position = this.getPointPosition(eventData); |
|||
this._windowAdapter.postPointerEvent(new PointerData( |
|||
timeStamp: Timer.timespanSinceStartup, |
|||
change: PointerChange.up, |
|||
kind: InputUtils.getPointerDeviceKind(eventData), |
|||
device: InputUtils.getPointerDeviceKey(eventData), |
|||
physicalX: position.x, |
|||
physicalY: position.y |
|||
)); |
|||
} |
|||
|
|||
public Vector2 getPointPosition(PointerEventData eventData) { |
|||
Vector2 localPoint; |
|||
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, eventData.position, |
|||
eventData.enterEventCamera, out localPoint); |
|||
var scaleFactor = this.canvas.scaleFactor; |
|||
localPoint.x = (localPoint.x - this.rectTransform.rect.min.x) * scaleFactor; |
|||
localPoint.y = (this.rectTransform.rect.max.y - localPoint.y) * scaleFactor; |
|||
return localPoint; |
|||
} |
|||
|
|||
public Vector2 getPointPosition(Vector2 position) { |
|||
Vector2 localPoint; |
|||
Camera eventCamera = null; |
|||
|
|||
if (this.canvas.renderMode != RenderMode.ScreenSpaceCamera) { |
|||
eventCamera = this.canvas.GetComponent<GraphicRaycaster>().eventCamera; |
|||
} |
|||
|
|||
|
|||
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, position, |
|||
eventCamera, out localPoint); |
|||
var scaleFactor = this.canvas.scaleFactor; |
|||
localPoint.x = (localPoint.x - this.rectTransform.rect.min.x) * scaleFactor; |
|||
localPoint.y = (this.rectTransform.rect.max.y - localPoint.y) * scaleFactor; |
|||
return localPoint; |
|||
} |
|||
|
|||
public void OnDrag(PointerEventData eventData) { |
|||
var position = this.getPointPosition(eventData); |
|||
this._windowAdapter.postPointerEvent(new PointerData( |
|||
timeStamp: Timer.timespanSinceStartup, |
|||
change: PointerChange.move, |
|||
kind: InputUtils.getPointerDeviceKind(eventData), |
|||
device: InputUtils.getPointerDeviceKey(eventData), |
|||
physicalX: position.x, |
|||
physicalY: position.y |
|||
)); |
|||
} |
|||
|
|||
public void OnPointerEnter(PointerEventData eventData) { |
|||
var pointerKey = InputUtils.getPointerDeviceKey(eventData); |
|||
this._enteredPointers.Add(pointerKey); |
|||
|
|||
this._lastMouseMove = eventData.position; |
|||
var position = this.getPointPosition(eventData); |
|||
this._windowAdapter.postPointerEvent(new PointerData( |
|||
timeStamp: Timer.timespanSinceStartup, |
|||
change: PointerChange.hover, |
|||
kind: InputUtils.getPointerDeviceKind(eventData), |
|||
device: pointerKey, |
|||
physicalX: position.x, |
|||
physicalY: position.y |
|||
)); |
|||
} |
|||
|
|||
public void OnPointerExit(PointerEventData eventData) { |
|||
var pointerKey = InputUtils.getPointerDeviceKey(eventData); |
|||
this._enteredPointers.Remove(pointerKey); |
|||
|
|||
var position = this.getPointPosition(eventData); |
|||
this._windowAdapter.postPointerEvent(new PointerData( |
|||
timeStamp: Timer.timespanSinceStartup, |
|||
change: PointerChange.hover, |
|||
kind: InputUtils.getPointerDeviceKind(eventData), |
|||
device: pointerKey, |
|||
physicalX: position.x, |
|||
physicalY: position.y |
|||
)); |
|||
} |
|||
|
|||
void unfocusIfNeeded() { |
|||
using (this._windowAdapter.getScope()) { |
|||
var focusNode = WidgetsBinding.instance.focusManager.currentFocus; |
|||
if (focusNode != null) { |
|||
focusNode.unfocus(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class PageViewSample : UIWidgetsSamplePanel { |
|||
|
|||
protected override Widget createWidget() { |
|||
return new WidgetsApp( |
|||
home: new Container( |
|||
width: 200, |
|||
height: 400, |
|||
child: new PageView( |
|||
children: new List<Widget>() { |
|||
new Container( |
|||
color: new Color(0xFFE91E63) |
|||
), |
|||
new Container( |
|||
color: new Color(0xFF00BCD4) |
|||
), |
|||
new Container( |
|||
color: new Color(0xFF673AB7) |
|||
) |
|||
} |
|||
)), |
|||
pageRouteBuilder: this.pageRouteBuilder); |
|||
} |
|||
} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class ScrollbarSample : UIWidgetsSamplePanel { |
|||
protected override Widget createWidget() { |
|||
var scroll = new Container( |
|||
decoration: new BoxDecoration( |
|||
border: Border.all(color: new Color(0xFFFFFF00)) |
|||
), |
|||
child: new Scrollbar( |
|||
child: new ListView( |
|||
children: new List<Widget> { |
|||
new Container(height: 40.0f, child: new Text("0")), |
|||
new Container(height: 40.0f, child: new Text("1")), |
|||
new Container(height: 40.0f, child: new Text("2")), |
|||
new Container(height: 40.0f, child: new Text("3")), |
|||
new Container(height: 40.0f, child: new Text("4")), |
|||
new Container(height: 40.0f, child: new Text("5")), |
|||
new Container(height: 40.0f, child: new Text("6")), |
|||
new Container(height: 40.0f, child: new Text("7")), |
|||
new Container(height: 40.0f, child: new Text("8")), |
|||
new Container(height: 40.0f, child: new Text("9")), |
|||
new Container(height: 40.0f, child: new Text("10")), |
|||
new Container(height: 40.0f, child: new Text("11")), |
|||
new Container(height: 40.0f, child: new Text("12")), |
|||
new Container(height: 40.0f, child: new Text("13")), |
|||
new Container(height: 40.0f, child: new Text("14")), |
|||
new Container(height: 40.0f, child: new Text("15")), |
|||
new Container(height: 40.0f, child: new Text("16")), |
|||
new Container(height: 40.0f, child: new Text("17")), |
|||
} |
|||
) |
|||
) |
|||
); |
|||
return new WidgetsApp( |
|||
home: scroll, |
|||
pageRouteBuilder: this.pageRouteBuilder); |
|||
} |
|||
} |
|||
} |
|
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.engine; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class UIWidgetsSamplePanel: UIWidgetsPanel { |
|||
|
|||
protected virtual PageRouteFactory pageRouteBuilder { |
|||
get { |
|||
return (RouteSettings settings, WidgetBuilder builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (BuildContext context, Animation<float> animation, |
|||
Animation<float> secondaryAnimation) => builder(context) |
|||
); |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4a21c5e1a50e24057a4ecf249fa86c1f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsSample { |
|||
|
|||
public static class Icons { |
|||
public static readonly IconData notifications = new IconData(0xe7f4, fontFamily: "Material Icons"); |
|||
public static readonly IconData account_circle = new IconData(0xe853, fontFamily: "Material Icons"); |
|||
public static readonly IconData search = new IconData(0xe8b6, fontFamily: "Material Icons"); |
|||
public static readonly IconData keyboard_arrow_down = new IconData(0xe313, fontFamily: "Material Icons"); |
|||
} |
|||
|
|||
public static class CLColors { |
|||
public static readonly Color primary = new Color(0xFFE91E63); |
|||
public static readonly Color secondary1 = new Color(0xFF00BCD4); |
|||
public static readonly Color secondary2 = new Color(0xFFF0513C); |
|||
public static readonly Color background1 = new Color(0xFF292929); |
|||
public static readonly Color background2 = new Color(0xFF383838); |
|||
public static readonly Color background3 = new Color(0xFFF5F5F5); |
|||
public static readonly Color background4 = new Color(0xFF00BCD4); |
|||
public static readonly Color icon1 = new Color(0xFFFFFFFF); |
|||
public static readonly Color icon2 = new Color(0xFFA4A4A4); |
|||
public static readonly Color text1 = new Color(0xFFFFFFFF); |
|||
public static readonly Color text2 = new Color(0xFFD8D8D8); |
|||
public static readonly Color text3 = new Color(0xFF959595); |
|||
public static readonly Color text4 = new Color(0xFF002835); |
|||
public static readonly Color text5 = new Color(0xFF9E9E9E); |
|||
public static readonly Color text6 = new Color(0xFF002835); |
|||
public static readonly Color text7 = new Color(0xFF5A5A5B); |
|||
public static readonly Color text8 = new Color(0xFF239988); |
|||
public static readonly Color text9 = new Color(0xFFB3B5B6); |
|||
public static readonly Color text10 = new Color(0xFF00BCD4); |
|||
public static readonly Color dividingLine1 = new Color(0xFF666666); |
|||
public static readonly Color dividingLine2 = new Color(0xFF404040); |
|||
|
|||
public static readonly Color transparent = new Color(0x00000000); |
|||
public static readonly Color white = new Color(0xFFFFFFFF); |
|||
public static readonly Color black = new Color(0xFF000000); |
|||
public static readonly Color red = new Color(0xFFFF0000); |
|||
public static readonly Color green = new Color(0xFF00FF00); |
|||
public static readonly Color blue = new Color(0xFF0000FF); |
|||
|
|||
public static readonly Color header = new Color(0xFF060B0C); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3781c9e4efebd4c928ef175761d31b58 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// -----------------------------------------------------------------------------
|
|||
//
|
|||
// Use this editor example C# file to develop editor (non-runtime) code.
|
|||
//
|
|||
// -----------------------------------------------------------------------------
|
|||
|
|||
namespace Unity.UIWidgets.Editor { |
|||
/// <summary>
|
|||
/// Provide a general description of the public class.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Packages require XmlDoc documentation for ALL Package APIs.
|
|||
/// https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/xml-documentation-comments
|
|||
/// </remarks>
|
|||
public class MyPublicEditorExampleClass { |
|||
/// <summary>
|
|||
/// Provide a description of what this private method does.
|
|||
/// </summary>
|
|||
/// <param name="parameter1"> Description of parameter 1 </param>
|
|||
/// <param name="parameter2"> Description of parameter 2 </param>
|
|||
/// <param name="parameter3"> Description of parameter 3 </param>
|
|||
/// <returns> Description of what the function returns </returns>
|
|||
public int CountThingsAndDoStuff(int parameter1, int parameter2, bool parameter3) { |
|||
return parameter3 ? (parameter1 + parameter2) : (parameter1 - parameter2); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 064eb42010c5a4828bd610b038b60701 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c339d59e8c37a49fdb2a6365764259fd |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.async; |
|||
using Unity.UIWidgets.editor; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using UnityEngine.EventSystems; |
|||
using UnityEngine.UI; |
|||
using RawImage = UnityEngine.UI.RawImage; |
|||
using Rect = UnityEngine.Rect; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
|
|||
namespace Unity.UIWidgets.engine { |
|||
public class UIWidgetWindowAdapter : WindowAdapter { |
|||
readonly WidgetCanvas _widgetCanvas; |
|||
bool _needsPaint; |
|||
|
|||
protected override void updateSafeArea() { |
|||
this._padding = new WindowPadding( |
|||
Screen.safeArea.x, |
|||
Screen.safeArea.y, |
|||
Screen.width - Screen.safeArea.width, |
|||
Screen.height - Screen.safeArea.height); |
|||
} |
|||
|
|||
public override void scheduleFrame(bool regenerateLayerTree = true) { |
|||
base.scheduleFrame(regenerateLayerTree); |
|||
this._needsPaint = true; |
|||
} |
|||
|
|||
public UIWidgetWindowAdapter(WidgetCanvas widgetCanvas) { |
|||
this._widgetCanvas = widgetCanvas; |
|||
} |
|||
|
|||
|
|||
public override void OnGUI(Event evt) { |
|||
if (this.displayMetricsChanged()) { |
|||
this._needsPaint = true; |
|||
} |
|||
|
|||
if (evt.type == EventType.Repaint) { |
|||
if (!this._needsPaint) { |
|||
return; |
|||
} |
|||
|
|||
this._needsPaint = false; |
|||
} |
|||
|
|||
base.OnGUI(evt); |
|||
} |
|||
|
|||
protected override Surface createSurface() { |
|||
return new EditorWindowSurface(this._widgetCanvas.applyRenderTexture); |
|||
} |
|||
|
|||
public override GUIContent titleContent { |
|||
get { return new GUIContent(this._widgetCanvas.gameObject.name); } |
|||
} |
|||
|
|||
protected override float queryDevicePixelRatio() { |
|||
return this._widgetCanvas.devicePixelRatio; |
|||
} |
|||
|
|||
protected override Vector2 queryWindowSize() { |
|||
var rect = RectTransformUtility.PixelAdjustRect(this._widgetCanvas.rectTransform, |
|||
this._widgetCanvas.canvas); |
|||
var size = new Vector2(rect.width, rect.height) / this._widgetCanvas.devicePixelRatio; |
|||
size.x = Mathf.Round(size.x); |
|||
size.y = Mathf.Round(size.y); |
|||
return size; |
|||
} |
|||
} |
|||
|
|||
[RequireComponent(typeof(RectTransform))] |
|||
public abstract class WidgetCanvas : RawImage, IPointerDownHandler, IPointerUpHandler, IDragHandler, |
|||
IPointerEnterHandler, IPointerExitHandler { |
|||
static Event _repaintEvent; |
|||
|
|||
[SerializeField] protected float devicePixelRatioOverride; |
|||
WindowAdapter _windowAdapter; |
|||
Texture _texture; |
|||
Vector2 _lastMouseMove; |
|||
|
|||
HashSet<int> _enteredPointers; |
|||
|
|||
bool _mouseEntered { |
|||
get { return !this._enteredPointers.isEmpty(); } |
|||
} |
|||
|
|||
readonly ScrollInput _scrollInput = new ScrollInput(); |
|||
DisplayMetrics _displayMetrics; |
|||
|
|||
const int mouseButtonNum = 3; |
|||
|
|||
protected override void OnEnable() { |
|||
base.OnEnable(); |
|||
|
|||
//Disable the default touch -> mouse event conversion on mobile devices
|
|||
Input.simulateMouseWithTouches = false; |
|||
|
|||
this._displayMetrics = DisplayMetricsProvider.provider(); |
|||
|
|||
if (_repaintEvent == null) { |
|||
_repaintEvent = new Event {type = EventType.Repaint}; |
|||
} |
|||
|
|||
D.assert(this._windowAdapter == null); |
|||
this._windowAdapter = new UIWidgetWindowAdapter(this); |
|||
|
|||
this._windowAdapter.OnEnable(); |
|||
var root = new WidgetsApp( |
|||
home: this.getWidget(), |
|||
window: this._windowAdapter, |
|||
routes: this.routes, |
|||
textStyle: this.textStyle, |
|||
pageRouteBuilder: this.pageRouteBuilder, |
|||
onGenerateRoute: this.onGenerateRoute, |
|||
onUnknownRoute: this.onUnknownRoute); |
|||
|
|||
|
|||
this._windowAdapter.attachRootWidget(root); |
|||
this._lastMouseMove = Input.mousePosition; |
|||
|
|||
this._enteredPointers = new HashSet<int>(); |
|||
} |
|||
|
|||
public float devicePixelRatio { |
|||
get { |
|||
return this.devicePixelRatioOverride > 0 |
|||
? this.devicePixelRatioOverride |
|||
: this._displayMetrics.DevicePixelRatio; |
|||
} |
|||
} |
|||
|
|||
protected virtual Dictionary<string, WidgetBuilder> routes { |
|||
get { return null; } |
|||
} |
|||
|
|||
protected virtual string initialRoute { |
|||
get { return null; } |
|||
} |
|||
|
|||
protected virtual RouteFactory onGenerateRoute { |
|||
get { return null; } |
|||
} |
|||
|
|||
protected virtual RouteFactory onUnknownRoute { |
|||
get { return null; } |
|||
} |
|||
|
|||
protected virtual TextStyle textStyle { |
|||
get { return null; } |
|||
} |
|||
|
|||
protected virtual PageRouteFactory pageRouteBuilder { |
|||
get { |
|||
return (RouteSettings settings, WidgetBuilder builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (BuildContext context, Animation<float> animation, |
|||
Animation<float> secondaryAnimation) => builder(context) |
|||
); |
|||
} |
|||
} |
|||
|
|||
protected override void OnDisable() { |
|||
D.assert(this._windowAdapter != null); |
|||
this._windowAdapter.OnDisable(); |
|||
this._windowAdapter = null; |
|||
base.OnDisable(); |
|||
} |
|||
|
|||
protected virtual Widget getWidget() { |
|||
return null; |
|||
} |
|||
|
|||
internal void applyRenderTexture(Rect screenRect, Texture texture, Material mat) { |
|||
this.texture = texture; |
|||
this.material = mat; |
|||
} |
|||
|
|||
void Update() { |
|||
this._displayMetrics.Update(); |
|||
if (EventSystem.current != null && EventSystem.current.currentSelectedGameObject != this.gameObject) { |
|||
this.unfocusIfNeeded(); |
|||
} |
|||
|
|||
if (this._mouseEntered) { |
|||
if (this._lastMouseMove.x != Input.mousePosition.x || this._lastMouseMove.y != Input.mousePosition.y) { |
|||
this.handleMouseMovement(); |
|||
} |
|||
} |
|||
|
|||
this._lastMouseMove = Input.mousePosition; |
|||
|
|||
if (this._mouseEntered) { |
|||
this.handleMouseScroll(); |
|||
} |
|||
|
|||
D.assert(this._windowAdapter != null); |
|||
this._windowAdapter.Update(); |
|||
this._windowAdapter.OnGUI(_repaintEvent); |
|||
} |
|||
|
|||
void OnGUI() { |
|||
this._displayMetrics.OnGUI(); |
|||
if (Event.current.type == EventType.KeyDown || Event.current.type == EventType.KeyUp) { |
|||
this._windowAdapter.OnGUI(Event.current); |
|||
} |
|||
} |
|||
|
|||
void handleMouseMovement() { |
|||
var pos = this.getPointPosition(Input.mousePosition); |
|||
this._windowAdapter.postPointerEvent(new PointerData( |
|||
timeStamp: Timer.timespanSinceStartup, |
|||
change: PointerChange.hover, |
|||
kind: PointerDeviceKind.mouse, |
|||
device: this.getMouseButtonDown(), |
|||
physicalX: pos.x, |
|||
physicalY: pos.y |
|||
)); |
|||
} |
|||
|
|||
void handleMouseScroll() { |
|||
if (Input.mouseScrollDelta.y != 0 || Input.mouseScrollDelta.x != 0) { |
|||
var scaleFactor = this.canvas.scaleFactor; |
|||
var pos = this.getPointPosition(Input.mousePosition); |
|||
this._scrollInput.onScroll(Input.mouseScrollDelta.x * scaleFactor, |
|||
Input.mouseScrollDelta.y * scaleFactor, |
|||
pos.x, |
|||
pos.y, |
|||
InputUtils.getScrollButtonKey()); |
|||
} |
|||
|
|||
var deltaScroll = this._scrollInput.getScrollDelta(); |
|||
if (deltaScroll != Vector2.zero) { |
|||
this._windowAdapter.postPointerEvent(new ScrollData( |
|||
timeStamp: Timer.timespanSinceStartup, |
|||
change: PointerChange.scroll, |
|||
kind: PointerDeviceKind.mouse, |
|||
device: this._scrollInput.getDeviceId(), |
|||
physicalX: this._scrollInput.getPointerPosX(), |
|||
physicalY: this._scrollInput.getPointerPosY(), |
|||
scrollX: deltaScroll.x, |
|||
scrollY: deltaScroll.y |
|||
)); |
|||
} |
|||
} |
|||
|
|||
int getMouseButtonDown() { |
|||
for (int key = 0; key < mouseButtonNum; key++) { |
|||
if (Input.GetMouseButton(key)) { |
|||
return InputUtils.getMouseButtonKey(key); |
|||
} |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
public void OnPointerDown(PointerEventData eventData) { |
|||
EventSystem.current.SetSelectedGameObject(this.gameObject, eventData); |
|||
var position = this.getPointPosition(eventData); |
|||
this._windowAdapter.postPointerEvent(new PointerData( |
|||
timeStamp: Timer.timespanSinceStartup, |
|||
change: PointerChange.down, |
|||
kind: InputUtils.getPointerDeviceKind(eventData), |
|||
device: InputUtils.getPointerDeviceKey(eventData), |
|||
physicalX: position.x, |
|||
physicalY: position.y |
|||
)); |
|||
} |
|||
|
|||
public void OnPointerUp(PointerEventData eventData) { |
|||
var position = this.getPointPosition(eventData); |
|||
this._windowAdapter.postPointerEvent(new PointerData( |
|||
timeStamp: Timer.timespanSinceStartup, |
|||
change: PointerChange.up, |
|||
kind: InputUtils.getPointerDeviceKind(eventData), |
|||
device: InputUtils.getPointerDeviceKey(eventData), |
|||
physicalX: position.x, |
|||
physicalY: position.y |
|||
)); |
|||
} |
|||
|
|||
public Vector2 getPointPosition(PointerEventData eventData) { |
|||
Vector2 localPoint; |
|||
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, eventData.position, |
|||
eventData.enterEventCamera, out localPoint); |
|||
var scaleFactor = this.canvas.scaleFactor; |
|||
localPoint.x = (localPoint.x - this.rectTransform.rect.min.x) * scaleFactor; |
|||
localPoint.y = (this.rectTransform.rect.max.y - localPoint.y) * scaleFactor; |
|||
return localPoint; |
|||
} |
|||
|
|||
public Vector2 getPointPosition(Vector2 position) { |
|||
Vector2 localPoint; |
|||
Camera eventCamera = null; |
|||
|
|||
if (this.canvas.renderMode != RenderMode.ScreenSpaceCamera) { |
|||
eventCamera = this.canvas.GetComponent<GraphicRaycaster>().eventCamera; |
|||
} |
|||
|
|||
|
|||
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, position, |
|||
eventCamera, out localPoint); |
|||
var scaleFactor = this.canvas.scaleFactor; |
|||
localPoint.x = (localPoint.x - this.rectTransform.rect.min.x) * scaleFactor; |
|||
localPoint.y = (this.rectTransform.rect.max.y - localPoint.y) * scaleFactor; |
|||
return localPoint; |
|||
} |
|||
|
|||
public void OnDrag(PointerEventData eventData) { |
|||
var position = this.getPointPosition(eventData); |
|||
this._windowAdapter.postPointerEvent(new PointerData( |
|||
timeStamp: Timer.timespanSinceStartup, |
|||
change: PointerChange.move, |
|||
kind: InputUtils.getPointerDeviceKind(eventData), |
|||
device: InputUtils.getPointerDeviceKey(eventData), |
|||
physicalX: position.x, |
|||
physicalY: position.y |
|||
)); |
|||
} |
|||
|
|||
public void OnPointerEnter(PointerEventData eventData) { |
|||
var pointerKey = InputUtils.getPointerDeviceKey(eventData); |
|||
this._enteredPointers.Add(pointerKey); |
|||
|
|||
this._lastMouseMove = eventData.position; |
|||
var position = this.getPointPosition(eventData); |
|||
this._windowAdapter.postPointerEvent(new PointerData( |
|||
timeStamp: Timer.timespanSinceStartup, |
|||
change: PointerChange.hover, |
|||
kind: InputUtils.getPointerDeviceKind(eventData), |
|||
device: pointerKey, |
|||
physicalX: position.x, |
|||
physicalY: position.y |
|||
)); |
|||
} |
|||
|
|||
public void OnPointerExit(PointerEventData eventData) { |
|||
var pointerKey = InputUtils.getPointerDeviceKey(eventData); |
|||
this._enteredPointers.Remove(pointerKey); |
|||
|
|||
var position = this.getPointPosition(eventData); |
|||
this._windowAdapter.postPointerEvent(new PointerData( |
|||
timeStamp: Timer.timespanSinceStartup, |
|||
change: PointerChange.hover, |
|||
kind: InputUtils.getPointerDeviceKind(eventData), |
|||
device: pointerKey, |
|||
physicalX: position.x, |
|||
physicalY: position.y |
|||
)); |
|||
} |
|||
|
|||
void unfocusIfNeeded() { |
|||
using (this._windowAdapter.getScope()) { |
|||
var focusNode = WidgetsBinding.instance.focusManager.currentFocus; |
|||
if (focusNode != null) { |
|||
focusNode.unfocus(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
{ |
|||
"name": "ReduxSample", |
|||
"references": ["Unity.UIWidgets"], |
|||
"includePlatforms": [], |
|||
"excludePlatforms": [] |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: da9b62bed239142ed9912e3274b2aa14 |
|||
AssemblyDefinitionImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
{ |
|||
"name": "UIWidgetSample", |
|||
"references": ["Unity.UIWidgets"], |
|||
"includePlatforms": [], |
|||
"excludePlatforms": [] |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f461a1d3753154b95a03ee91cfcbbbb7 |
|||
AssemblyDefinitionImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.engine; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class PageViewCanvas : WidgetCanvas { |
|||
protected override Widget getWidget() { |
|||
return new Container( |
|||
width: 200, |
|||
height: 400, |
|||
child: new PageView( |
|||
children: new List<Widget>() { |
|||
new Container( |
|||
color: new Color(0xFFE91E63) |
|||
), |
|||
new Container( |
|||
color: new Color(0xFF00BCD4) |
|||
), |
|||
new Container( |
|||
color: new Color(0xFF673AB7) |
|||
) |
|||
} |
|||
)); |
|||
} |
|||
} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.engine; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class ScrollbarCanvas : WidgetCanvas { |
|||
protected override Widget getWidget() { |
|||
return new Container( |
|||
decoration: new BoxDecoration( |
|||
border: Border.all(color: new Color(0xFFFFFF00)) |
|||
), |
|||
child: new Scrollbar( |
|||
child: new ListView( |
|||
children: new List<Widget> { |
|||
new Container(height: 40.0f, child: new Text("0")), |
|||
new Container(height: 40.0f, child: new Text("1")), |
|||
new Container(height: 40.0f, child: new Text("2")), |
|||
new Container(height: 40.0f, child: new Text("3")), |
|||
new Container(height: 40.0f, child: new Text("4")), |
|||
new Container(height: 40.0f, child: new Text("5")), |
|||
new Container(height: 40.0f, child: new Text("6")), |
|||
new Container(height: 40.0f, child: new Text("7")), |
|||
new Container(height: 40.0f, child: new Text("8")), |
|||
new Container(height: 40.0f, child: new Text("9")), |
|||
new Container(height: 40.0f, child: new Text("10")), |
|||
new Container(height: 40.0f, child: new Text("11")), |
|||
new Container(height: 40.0f, child: new Text("12")), |
|||
new Container(height: 40.0f, child: new Text("13")), |
|||
new Container(height: 40.0f, child: new Text("14")), |
|||
new Container(height: 40.0f, child: new Text("15")), |
|||
new Container(height: 40.0f, child: new Text("16")), |
|||
new Container(height: 40.0f, child: new Text("17")), |
|||
} |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue