iizzaya
5 年前
当前提交
25f6d10a
共有 11 个文件被更改,包括 139 次插入 和 204 次删除
-
33Runtime/Plugins/Raycast/RaycastManager.cs
-
145Runtime/Plugins/Raycast/Sample/Raycast Simple Testbed.unity
-
3Runtime/Plugins/Raycast/Sample/RaycastSimpleTestbedPanel.cs
-
2Runtime/Plugins/Raycast/Sample/RaycastTestbedPanel.cs
-
2Runtime/Plugins/Raycast/UIWidgetsRaycastablePanel.cs.meta
-
12Runtime/engine/UIWidgetsPanel.cs
-
49Runtime/Plugins/Raycast/Sample/DefaultSimpleTestbedPanel.cs
-
11Runtime/Plugins/Raycast/Sample/DefaultSimpleTestbedPanel.cs.meta
-
40Runtime/Plugins/Raycast/UIWidgetsRaycastablePanel.cs
-
46Runtime/Plugins/Raycast/UIWidgetsPanelRaycastFilter.cs
-
0/Runtime/Plugins/Raycast/UIWidgetsRaycastablePanel.cs.meta
|
|||
using Unity.UIWidgets.engine; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.plugins.raycast; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using Color = Unity.UIWidgets.ui.Color; |
|||
using Material = Unity.UIWidgets.material.Material; |
|||
|
|||
namespace Unity.UIWidgets.Sample { |
|||
public class DefaultSimpleTestbedPanel : UIWidgetsPanel { |
|||
protected override void OnEnable() { |
|||
FontManager.instance.addFont(Resources.Load<Font>("fonts/MaterialIcons-Regular"), "Material Icons"); |
|||
base.OnEnable(); |
|||
} |
|||
|
|||
protected override Widget createWidget() { |
|||
return new MaterialApp( |
|||
home: new DefaultSimpleTestbedWidget() |
|||
); |
|||
} |
|||
} |
|||
|
|||
public class DefaultSimpleTestbedWidget : StatefulWidget { |
|||
public DefaultSimpleTestbedWidget(Key key = null) : base(key) { } |
|||
|
|||
public override State createState() { |
|||
return new DefaultSimpleTestbedWidgetState(); |
|||
} |
|||
} |
|||
|
|||
public class DefaultSimpleTestbedWidgetState : State<DefaultSimpleTestbedWidget> { |
|||
public override Widget build(BuildContext context) { |
|||
return new Material( |
|||
color: new Color(0x44FFFF00), |
|||
child: new Center( |
|||
child: new Container( |
|||
child: new MaterialButton( |
|||
child: new Text("Material Button"), |
|||
onPressed: () => { }, |
|||
color: Colors.lightBlue |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 15ddf18357c864b1b822b471672fd391 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.engine; |
|||
using UnityEngine; |
|||
|
|||
namespace Unity.UIWidgets.plugins.raycast { |
|||
[RequireComponent(typeof(RectTransform))] |
|||
public class UIWidgetsRaycastablePanel : UIWidgetsPanel, ICanvasRaycastFilter { |
|||
int windowHashCode; |
|||
|
|||
protected override void InitWindowAdapter() { |
|||
base.InitWindowAdapter(); |
|||
this.windowHashCode = this.window.GetHashCode(); |
|||
RaycastManager.NewWindow(this.windowHashCode); |
|||
} |
|||
|
|||
protected override void OnDisable() { |
|||
base.OnDisable(); |
|||
RaycastManager.DisposeWindow(this.windowHashCode); |
|||
} |
|||
|
|||
public bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera) { |
|||
if (!this.enabled) { |
|||
return true; |
|||
} |
|||
|
|||
Vector2 local; |
|||
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, screenPoint, eventCamera, |
|||
out local); |
|||
|
|||
Rect rect = this.rectTransform.rect; |
|||
|
|||
// Convert top left corner as reference origin point.
|
|||
local.x += this.rectTransform.pivot.x * rect.width; |
|||
local.y -= this.rectTransform.pivot.y * rect.height; |
|||
local.x = local.x / this.devicePixelRatio; |
|||
local.y = -local.y / this.devicePixelRatio; |
|||
|
|||
return !RaycastManager.CheckCastThrough(this.windowHashCode, local); |
|||
} |
|||
} |
|||
} |
|
|||
using Unity.UIWidgets.engine; |
|||
using UnityEngine; |
|||
|
|||
namespace Unity.UIWidgets.plugins.raycast { |
|||
|
|||
[DisallowMultipleComponent] |
|||
[RequireComponent(typeof(UIWidgetsPanel))] |
|||
[DefaultExecutionOrder(1)] |
|||
public class UIWidgetsPanelRaycastFilter : MonoBehaviour, ICanvasRaycastFilter { |
|||
public bool reversed; |
|||
|
|||
UIWidgetsPanel panel; |
|||
int windowHashCode; |
|||
|
|||
void OnEnable() { |
|||
this.panel = this.GetComponent<UIWidgetsPanel>(); |
|||
this.windowHashCode = this.panel.window.GetHashCode(); |
|||
RaycastManager.VerifyWindow(this.windowHashCode); |
|||
} |
|||
|
|||
public bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera) { |
|||
if (!this.enabled) { |
|||
return true; |
|||
} |
|||
|
|||
Vector2 local; |
|||
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.panel.rectTransform, screenPoint, eventCamera, |
|||
out local); |
|||
|
|||
Rect rect = this.panel.rectTransform.rect; |
|||
|
|||
// Convert top left corner as reference origin point.
|
|||
local.x += this.panel.rectTransform.pivot.x * rect.width; |
|||
local.y -= this.panel.rectTransform.pivot.y * rect.height; |
|||
local.x = local.x / this.panel.devicePixelRatio; |
|||
local.y = -local.y / this.panel.devicePixelRatio; |
|||
|
|||
if (this.reversed) { |
|||
return RaycastManager.CheckCastThrough(this.windowHashCode, local); |
|||
} |
|||
else { |
|||
return !RaycastManager.CheckCastThrough(this.windowHashCode, local); |
|||
} |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue