Init
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ae7139eb33276844be313c61d8bae89
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,131 @@
|
||||
#if PICO_OPENXR_SDK
|
||||
using System;
|
||||
using System.Collections;
|
||||
#if UNITY_XR_COMPOSITIONLAYERS
|
||||
using Unity.XR.CompositionLayers;
|
||||
using Unity.XR.CompositionLayers.Extensions;
|
||||
using UnityEngine.XR.OpenXR.CompositionLayers;
|
||||
#endif
|
||||
using Unity.XR.PICO.TOBSupport;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
public class VirtualDisplayDemo_OpenXR : MonoBehaviour
|
||||
{
|
||||
private string tag = "VirtualDisplayDemo ----";
|
||||
#if UNITY_XR_COMPOSITIONLAYERS
|
||||
private CompositionLayer _overlay = null;
|
||||
private TexturesExtension _sourceTextures = null;
|
||||
#endif
|
||||
|
||||
public Text mylog;
|
||||
private bool isBind = false;
|
||||
private int displayId = -1;
|
||||
|
||||
public const int VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR = 16;
|
||||
public const int VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY = 8;
|
||||
public const int VIRTUAL_DISPLAY_FLAG_PRESENTATION = 2;
|
||||
public const int VIRTUAL_DISPLAY_FLAG_PUBLIC = 1;
|
||||
public const int VIRTUAL_DISPLAY_FLAG_SECURE = 4;
|
||||
public const int SOURCE_KEYBOARD = 257;
|
||||
public const int ACTION_DOWN = 0;
|
||||
public const int ACTION_UP = 1;
|
||||
public const int ACTION_MOVE = 2;
|
||||
int KEYCODE_BACK = 4;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
#if UNITY_XR_COMPOSITIONLAYERS
|
||||
|
||||
_overlay = GetComponent<CompositionLayer>();
|
||||
if (_overlay == null)
|
||||
{
|
||||
_overlay = gameObject.AddComponent<CompositionLayer>();
|
||||
}
|
||||
#endif
|
||||
|
||||
PXR_Enterprise.InitEnterpriseService();
|
||||
}
|
||||
|
||||
public void showLog(string log)
|
||||
{
|
||||
Debug.Log(tag + log);
|
||||
mylog.text = log;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
showLog("tobDemo:start");
|
||||
PXR_Enterprise.BindEnterpriseService(b =>
|
||||
{
|
||||
showLog("Bind绑定的返回值测试:" + b);
|
||||
isBind = true;
|
||||
|
||||
PXR_Enterprise.SwitchSystemFunction(
|
||||
(int)SystemFunctionSwitchEnum.SFS_BASIC_SETTING_SHOW_APP_QUIT_CONFIRM_DIALOG, (int)SwitchEnum.S_OFF,
|
||||
b =>
|
||||
{
|
||||
// showLog("SFS_BASIC_SETTING_SHOW_APP_QUIT_CONFIRM_DIALOG:" + b);
|
||||
});
|
||||
|
||||
int flags = VIRTUAL_DISPLAY_FLAG_PUBLIC;
|
||||
flags |= 1 << 6; //DisplayManager.VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH
|
||||
flags |= 1 << 7; //DisplayManager.VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT
|
||||
flags |= 1 << 8; //DisplayManager.VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL
|
||||
flags |= VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY;
|
||||
#if UNITY_XR_COMPOSITIONLAYERS
|
||||
StartCoroutine(CreateVirtualDisplay(flags));
|
||||
#endif
|
||||
showLog("CreateVirtualDisplay displayId:" + displayId);
|
||||
});
|
||||
}
|
||||
#if UNITY_XR_COMPOSITIONLAYERS
|
||||
private IEnumerator CreateVirtualDisplay(int flags)
|
||||
{
|
||||
IntPtr surface = IntPtr.Zero;
|
||||
yield return new WaitUntil(() =>
|
||||
{
|
||||
surface = OpenXRLayerUtility.GetLayerAndroidSurfaceObject(_overlay.GetInstanceID());
|
||||
|
||||
displayId = PXR_Enterprise.CreateVirtualDisplay("VirtualDisplayDemo", surface,
|
||||
320, flags,720,1280);
|
||||
return (surface != IntPtr.Zero);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
public void OpenApp()
|
||||
{
|
||||
showLog("StartApp ret:");
|
||||
Intent m = new Intent();
|
||||
m.setComponent("com.pico.myapplication", "com.pico.myapplication.MainActivity");
|
||||
int ret = PXR_Enterprise.StartApp(displayId, m);
|
||||
showLog("StartApp ret:" + ret);
|
||||
}
|
||||
|
||||
public void KillApp()
|
||||
{
|
||||
int[] args1 = {};
|
||||
string[] args2 = {"com.pico.myapplication"};
|
||||
PXR_Enterprise.KillAppsByPidOrPackageName(args1, args2);
|
||||
}
|
||||
|
||||
public void ReleaseVirtualDisplay()
|
||||
{
|
||||
int ret = PXR_Enterprise.ReleaseVirtualDisplay(displayId);
|
||||
showLog("ReleaseVirtualDisplay ret:" + ret);
|
||||
}
|
||||
|
||||
public void InjectEvent(int action, float x, float y)
|
||||
{
|
||||
int ret = PXR_Enterprise.InjectEvent(displayId, action, SOURCE_KEYBOARD, 720*x,1280*y);
|
||||
}
|
||||
|
||||
public void bcak()
|
||||
{
|
||||
int ret = PXR_Enterprise.InjectEvent(displayId, ACTION_DOWN, SOURCE_KEYBOARD, KEYCODE_BACK);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f06b7308d86d8ad4b90e32cbc0dcdb2a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3435bd49e96ca5040baf62d3d31b65fd
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,191 @@
|
||||
#if PICO_OPENXR_SDK
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.XR;
|
||||
|
||||
|
||||
#if XRI_240
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
#endif
|
||||
#if XRI_300
|
||||
using UnityEngine.XR.Interaction.Toolkit.Interactors;
|
||||
#endif
|
||||
|
||||
public class VirtualDisplayEvent_OpenXR : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler,
|
||||
IInitializePotentialDragHandler
|
||||
{
|
||||
public string tag = "VirtualDisplayEvent----";
|
||||
#if XRI_240||XRI_300
|
||||
public XRRayInteractor xrLeftRayInteractor;
|
||||
public XRRayInteractor xrRightRayInteractor;
|
||||
private XRRayInteractor currentRayInteractor;
|
||||
#endif
|
||||
|
||||
public VirtualDisplayDemo_OpenXR virtualDisplayController;
|
||||
|
||||
public Text mylog;
|
||||
|
||||
private GameObject mDisplay;
|
||||
private RectTransform mDisplayTran;
|
||||
private int mKeyEvent;
|
||||
private const int KEYEVENT_DEFAULT = -1;
|
||||
private const int KEYEVENT_DOWN = 0;
|
||||
private const int KEYEVENT_UP = 1;
|
||||
bool LeftState = false;
|
||||
private bool mLeftTriggerPressTemp = false;
|
||||
bool RightState = false;
|
||||
private bool mRightTriggerPressTemp = false;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
mDisplay = this.gameObject;
|
||||
mDisplayTran = mDisplay.GetComponent<RectTransform>();
|
||||
mKeyEvent = KEYEVENT_DEFAULT;
|
||||
#if XRI_240||XRI_300
|
||||
currentRayInteractor = xrRightRayInteractor;
|
||||
#endif
|
||||
|
||||
}
|
||||
public void showLog(string log)
|
||||
{
|
||||
Debug.Log(tag + log);
|
||||
mylog.text = log;
|
||||
}
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
InputDevices.GetDeviceAtXRNode(XRNode.LeftHand).TryGetFeatureValue(CommonUsages.isTracked, out LeftState);
|
||||
InputDevices.GetDeviceAtXRNode(XRNode.RightHand)
|
||||
.TryGetFeatureValue(CommonUsages.isTracked, out RightState);
|
||||
if (RightState)
|
||||
{
|
||||
InputDevices.GetDeviceAtXRNode(XRNode.RightHand)
|
||||
.TryGetFeatureValue(CommonUsages.triggerButton, out mRightTriggerPressTemp);
|
||||
if (mRightTriggerPressTemp)
|
||||
{
|
||||
#if XRI_240||XRI_300
|
||||
currentRayInteractor = xrRightRayInteractor;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (LeftState)
|
||||
{
|
||||
InputDevices.GetDeviceAtXRNode(XRNode.LeftHand)
|
||||
.TryGetFeatureValue(CommonUsages.triggerButton, out mLeftTriggerPressTemp);
|
||||
if (mLeftTriggerPressTemp)
|
||||
{
|
||||
#if XRI_240||XRI_300
|
||||
currentRayInteractor = xrLeftRayInteractor;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mKeyEvent != KEYEVENT_DEFAULT)
|
||||
{
|
||||
DispatchMessageToAndroid(mKeyEvent, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
mKeyEvent = KEYEVENT_DOWN;
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
mKeyEvent = KEYEVENT_UP;
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
mKeyEvent = KEYEVENT_DOWN;
|
||||
}
|
||||
|
||||
public void OnInitializePotentialDrag(PointerEventData eventData)
|
||||
{
|
||||
eventData.useDragThreshold = false;
|
||||
}
|
||||
|
||||
private void DispatchMessageToAndroid(int actionType, PointerEventData eventData)
|
||||
{
|
||||
#if XRI_240||XRI_300
|
||||
Vector3 eventPoint = mDisplay.transform.InverseTransformPoint(currentRayInteractor.rayEndPoint);
|
||||
if (Application.platform == RuntimePlatform.Android)
|
||||
{
|
||||
InstrumentationInput(eventPoint, actionType);
|
||||
}
|
||||
else
|
||||
{
|
||||
float x = (eventPoint.x + mDisplayTran.sizeDelta.x / 2) / mDisplayTran.sizeDelta.x;
|
||||
float y = (mDisplayTran.sizeDelta.y / 2 - eventPoint.y) / mDisplayTran.sizeDelta.y;
|
||||
mKeyEvent = KEYEVENT_DEFAULT;
|
||||
Debug.Log(actionType + "--->" + x + ", " + y + ", " + eventPoint.x + ", " + eventPoint.y);
|
||||
}
|
||||
#else
|
||||
showLog("com.unity.xr.interaction.toolkit Version needs to be greater than 2.3.x");
|
||||
// Debug.LogError("com.unity.xr.interaction.toolkit Version needs to be greater than 2.3.x");
|
||||
#endif
|
||||
}
|
||||
|
||||
private bool mIsUp = true;
|
||||
private float mLastX, mLastY;
|
||||
|
||||
private void InstrumentationInput(Vector3 eventPoint, int actionType)
|
||||
{
|
||||
|
||||
float eventX = eventPoint.x;
|
||||
float eventY = eventPoint.y;
|
||||
float x = (eventX + mDisplayTran.sizeDelta.x / 2) / mDisplayTran.sizeDelta.x;
|
||||
float y = (mDisplayTran.sizeDelta.y / 2 - eventY) / mDisplayTran.sizeDelta.y;
|
||||
|
||||
if (mIsUp && (eventX == 0.0f || eventY == 0.0f || x > 0.99f || x < 0.01f || y > 0.99f || y < 0.01f))
|
||||
{
|
||||
//处理在屏幕外操作的问题
|
||||
showLog("input--->out of the screen---1");
|
||||
mKeyEvent = KEYEVENT_DEFAULT;
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionType == KEYEVENT_DOWN)
|
||||
{
|
||||
if (mIsUp)
|
||||
{
|
||||
mIsUp = false;
|
||||
virtualDisplayController.InjectEvent(VirtualDisplayDemo_OpenXR.ACTION_DOWN,x,y);
|
||||
showLog("down--->" + x + ", " + y + ", " + eventX + ", " + eventY);
|
||||
}
|
||||
|
||||
if (!mIsUp)
|
||||
{
|
||||
if (eventX == 0.0f || eventY == 0.0f || x > 0.99f || x < 0.01f || y > 0.99f || y < 0.01f)
|
||||
{
|
||||
//处理划出屏幕,还未抬起的问题
|
||||
showLog("input--->out of the screen---2");
|
||||
mIsUp = true;
|
||||
mKeyEvent = KEYEVENT_DEFAULT;
|
||||
virtualDisplayController.InjectEvent(VirtualDisplayDemo_OpenXR.ACTION_UP,x,y);
|
||||
showLog("up--->" + mLastX + ", " + mLastY + ", " + eventX + ", " + eventY);
|
||||
}
|
||||
else
|
||||
{
|
||||
virtualDisplayController.InjectEvent(VirtualDisplayDemo_OpenXR.ACTION_MOVE,x,y);
|
||||
showLog("move--->" + x + ", " + y + ", " + eventX + ", " + eventY);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (actionType == KEYEVENT_UP)
|
||||
{
|
||||
mIsUp = true;
|
||||
mKeyEvent = KEYEVENT_DEFAULT;
|
||||
virtualDisplayController.InjectEvent(VirtualDisplayDemo_OpenXR.ACTION_UP,x,y);
|
||||
showLog("up--->" + x + ", " + y + ", " + eventPoint.x + ", " + eventPoint.y);
|
||||
}
|
||||
|
||||
mLastX = x;
|
||||
mLastY = y;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08f33d7dda159e143969c80188c1203f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 885ac79e2188a9546a58dc2a5dd526f8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,102 @@
|
||||
#if !PICO_OPENXR_SDK
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.XR.PICO.TOBSupport;
|
||||
using Unity.XR.PXR;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class VirtualDisplayDemo : MonoBehaviour
|
||||
{
|
||||
private string tag = "VirtualDisplayDemo ----";
|
||||
private PXR_CompositionLayer overlay = null;
|
||||
public Text mylog;
|
||||
private bool isBind = false;
|
||||
private int displayId = -1;
|
||||
|
||||
public const int VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR = 16;
|
||||
public const int VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY = 8;
|
||||
public const int VIRTUAL_DISPLAY_FLAG_PRESENTATION = 2;
|
||||
public const int VIRTUAL_DISPLAY_FLAG_PUBLIC = 1;
|
||||
public const int VIRTUAL_DISPLAY_FLAG_SECURE = 4;
|
||||
public const int SOURCE_KEYBOARD = 257;
|
||||
public const int ACTION_DOWN = 0;
|
||||
public const int ACTION_UP = 1;
|
||||
public const int ACTION_MOVE = 2;
|
||||
int KEYCODE_BACK = 4;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
overlay = GetComponent<PXR_CompositionLayer>();
|
||||
if (overlay == null)
|
||||
{
|
||||
Debug.LogError("PXRLog Overlay is null!");
|
||||
overlay = gameObject.AddComponent<PXR_CompositionLayer>();
|
||||
}
|
||||
|
||||
overlay.isExternalAndroidSurface = true;
|
||||
PXR_Enterprise.InitEnterpriseService();
|
||||
}
|
||||
|
||||
public void showLog(string log)
|
||||
{
|
||||
Debug.Log(tag + log);
|
||||
mylog.text = log;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
showLog("tobDemo:start");
|
||||
PXR_Enterprise.BindEnterpriseService(b =>
|
||||
{
|
||||
showLog("Bind绑定的返回值测试:" + b);
|
||||
isBind = true;
|
||||
|
||||
PXR_Enterprise.SwitchSystemFunction(
|
||||
(int)SystemFunctionSwitchEnum.SFS_BASIC_SETTING_SHOW_APP_QUIT_CONFIRM_DIALOG, (int)SwitchEnum.S_OFF,
|
||||
b =>
|
||||
{
|
||||
// showLog("SFS_BASIC_SETTING_SHOW_APP_QUIT_CONFIRM_DIALOG:" + b);
|
||||
});
|
||||
|
||||
int flags = VIRTUAL_DISPLAY_FLAG_PUBLIC;
|
||||
flags |= 1 << 6; //DisplayManager.VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH
|
||||
flags |= 1 << 7; //DisplayManager.VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT
|
||||
flags |= 1 << 8; //DisplayManager.VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL
|
||||
flags |= VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY;
|
||||
|
||||
displayId = PXR_Enterprise.CreateVirtualDisplay("VirtualDisplayDemo", overlay.externalAndroidSurfaceObject,
|
||||
320, flags);
|
||||
showLog("CreateVirtualDisplay displayId:" + displayId);
|
||||
});
|
||||
}
|
||||
|
||||
public void OpenApp()
|
||||
{
|
||||
showLog("StartApp ret:");
|
||||
Intent m = new Intent();
|
||||
m.setComponent("com.pico.myapplication", "com.pico.myapplication.MainActivity");
|
||||
int ret = PXR_Enterprise.StartApp(displayId, m);
|
||||
showLog("StartApp ret:" + ret);
|
||||
}
|
||||
|
||||
|
||||
public void ReleaseVirtualDisplay()
|
||||
{
|
||||
int ret = PXR_Enterprise.ReleaseVirtualDisplay(displayId);
|
||||
showLog("ReleaseVirtualDisplay ret:" + ret);
|
||||
}
|
||||
|
||||
public void InjectEvent(int action, float x, float y)
|
||||
{
|
||||
int ret = PXR_Enterprise.InjectEvent(displayId, action, SOURCE_KEYBOARD, x, y);
|
||||
}
|
||||
|
||||
public void bcak()
|
||||
{
|
||||
int ret = PXR_Enterprise.InjectEvent(displayId, ACTION_DOWN, SOURCE_KEYBOARD, KEYCODE_BACK);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9eff5f4fc4057284d87f413c0a63b1a0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6971024d1aca1a545ab8ad133a569d1a
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,181 @@
|
||||
#if !PICO_OPENXR_SDK
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.XR.PXR;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.XR;
|
||||
|
||||
#if !XRI_300
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
#else
|
||||
using UnityEngine.XR.Interaction.Toolkit.Interactors;
|
||||
#endif
|
||||
|
||||
public class VirtualDisplayEvent : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler,
|
||||
IInitializePotentialDragHandler
|
||||
{
|
||||
public string tag = "VirtualDisplayEvent----";
|
||||
public XRRayInteractor xrLeftRayInteractor;
|
||||
public XRRayInteractor xrRightRayInteractor;
|
||||
public VirtualDisplayDemo virtualDisplayController;
|
||||
|
||||
public Text mylog;
|
||||
private XRRayInteractor currentRayInteractor;
|
||||
private GameObject mDisplay;
|
||||
private RectTransform mDisplayTran;
|
||||
private int mKeyEvent;
|
||||
private const int KEYEVENT_DEFAULT = -1;
|
||||
private const int KEYEVENT_DOWN = 0;
|
||||
private const int KEYEVENT_UP = 1;
|
||||
bool LeftState = false;
|
||||
private bool mLeftTriggerPressTemp = false;
|
||||
bool RightState = false;
|
||||
private bool mRightTriggerPressTemp = false;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
mDisplay = this.gameObject;
|
||||
mDisplayTran = mDisplay.GetComponent<RectTransform>();
|
||||
mKeyEvent = KEYEVENT_DEFAULT;
|
||||
currentRayInteractor = xrRightRayInteractor;
|
||||
}
|
||||
public void showLog(string log)
|
||||
{
|
||||
Debug.Log(tag + log);
|
||||
mylog.text = log;
|
||||
}
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
InputDevices.GetDeviceAtXRNode(XRNode.LeftHand).TryGetFeatureValue(PXR_Usages.controllerStatus, out LeftState);
|
||||
InputDevices.GetDeviceAtXRNode(XRNode.RightHand)
|
||||
.TryGetFeatureValue(PXR_Usages.controllerStatus, out RightState);
|
||||
if (RightState)
|
||||
{
|
||||
InputDevices.GetDeviceAtXRNode(XRNode.RightHand)
|
||||
.TryGetFeatureValue(CommonUsages.triggerButton, out mRightTriggerPressTemp);
|
||||
if (mRightTriggerPressTemp)
|
||||
{
|
||||
currentRayInteractor = xrRightRayInteractor;
|
||||
}
|
||||
}
|
||||
else if (LeftState)
|
||||
{
|
||||
InputDevices.GetDeviceAtXRNode(XRNode.LeftHand)
|
||||
.TryGetFeatureValue(CommonUsages.triggerButton, out mLeftTriggerPressTemp);
|
||||
if (mLeftTriggerPressTemp)
|
||||
{
|
||||
currentRayInteractor = xrLeftRayInteractor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mKeyEvent != KEYEVENT_DEFAULT)
|
||||
{
|
||||
DispatchMessageToAndroid(mKeyEvent, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
mKeyEvent = KEYEVENT_DOWN;
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
mKeyEvent = KEYEVENT_UP;
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
mKeyEvent = KEYEVENT_DOWN;
|
||||
}
|
||||
|
||||
public void OnInitializePotentialDrag(PointerEventData eventData)
|
||||
{
|
||||
eventData.useDragThreshold = false;
|
||||
}
|
||||
|
||||
private void DispatchMessageToAndroid(int actionType, PointerEventData eventData)
|
||||
{
|
||||
#if XRI_240
|
||||
Vector3 eventPoint = mDisplay.transform.InverseTransformPoint(currentRayInteractor.rayEndPoint);
|
||||
if (Application.platform == RuntimePlatform.Android)
|
||||
{
|
||||
InstrumentationInput(eventPoint, actionType);
|
||||
}
|
||||
else
|
||||
{
|
||||
float x = (eventPoint.x + mDisplayTran.sizeDelta.x / 2) / mDisplayTran.sizeDelta.x;
|
||||
float y = (mDisplayTran.sizeDelta.y / 2 - eventPoint.y) / mDisplayTran.sizeDelta.y;
|
||||
mKeyEvent = KEYEVENT_DEFAULT;
|
||||
Debug.Log(actionType + "--->" + x + ", " + y + ", " + eventPoint.x + ", " + eventPoint.y);
|
||||
}
|
||||
#else
|
||||
showLog("com.unity.xr.interaction.toolkit Version needs to be greater than 2.3.x");
|
||||
// Debug.LogError("com.unity.xr.interaction.toolkit Version needs to be greater than 2.3.x");
|
||||
#endif
|
||||
}
|
||||
|
||||
private bool mIsUp = true;
|
||||
private float mLastX, mLastY;
|
||||
|
||||
private void InstrumentationInput(Vector3 eventPoint, int actionType)
|
||||
{
|
||||
|
||||
float eventX = eventPoint.x;
|
||||
float eventY = eventPoint.y;
|
||||
float x = (eventX + mDisplayTran.sizeDelta.x / 2) / mDisplayTran.sizeDelta.x;
|
||||
float y = (mDisplayTran.sizeDelta.y / 2 - eventY) / mDisplayTran.sizeDelta.y;
|
||||
|
||||
if (mIsUp && (eventX == 0.0f || eventY == 0.0f || x > 0.99f || x < 0.01f || y > 0.99f || y < 0.01f))
|
||||
{
|
||||
//处理在屏幕外操作的问题
|
||||
showLog("input--->out of the screen---1");
|
||||
mKeyEvent = KEYEVENT_DEFAULT;
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionType == KEYEVENT_DOWN)
|
||||
{
|
||||
if (mIsUp)
|
||||
{
|
||||
mIsUp = false;
|
||||
virtualDisplayController.InjectEvent(VirtualDisplayDemo.ACTION_DOWN,x,y);
|
||||
showLog("down--->" + x + ", " + y + ", " + eventX + ", " + eventY);
|
||||
}
|
||||
|
||||
if (!mIsUp)
|
||||
{
|
||||
if (eventX == 0.0f || eventY == 0.0f || x > 0.99f || x < 0.01f || y > 0.99f || y < 0.01f)
|
||||
{
|
||||
//处理划出屏幕,还未抬起的问题
|
||||
showLog("input--->out of the screen---2");
|
||||
mIsUp = true;
|
||||
mKeyEvent = KEYEVENT_DEFAULT;
|
||||
virtualDisplayController.InjectEvent(VirtualDisplayDemo.ACTION_UP,x,y);
|
||||
showLog("up--->" + mLastX + ", " + mLastY + ", " + eventX + ", " + eventY);
|
||||
}
|
||||
else
|
||||
{
|
||||
virtualDisplayController.InjectEvent(VirtualDisplayDemo.ACTION_MOVE,x,y);
|
||||
showLog("move--->" + x + ", " + y + ", " + eventX + ", " + eventY);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (actionType == KEYEVENT_UP)
|
||||
{
|
||||
mIsUp = true;
|
||||
mKeyEvent = KEYEVENT_DEFAULT;
|
||||
virtualDisplayController.InjectEvent(VirtualDisplayDemo.ACTION_UP,x,y);
|
||||
showLog("up--->" + x + ", " + y + ", " + eventPoint.x + ", " + eventPoint.y);
|
||||
}
|
||||
|
||||
mLastX = x;
|
||||
mLastY = y;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff6164edb8163214a94140877bd556c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0a26202f0fdfe449a11cf4685646f86
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user