Загрузка PICO Unity OpenXR Integration SDK
This commit is contained in:
@ -0,0 +1,105 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2015-2022 PICO Technology Co., Ltd.All rights reserved.
|
||||
|
||||
NOTICE:All information contained herein is, and remains the property of
|
||||
PICO Technology Co., Ltd. The intellectual and technical concepts
|
||||
contained herein are proprietary to PICO Technology Co., Ltd. and may be
|
||||
covered by patents, patents in process, and are protected by trade secret or
|
||||
copyright law. Dissemination of this information or reproduction of this
|
||||
material is strictly forbidden unless prior written permission is obtained from
|
||||
PICO Technology Co., Ltd.
|
||||
*******************************************************************************/
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR;
|
||||
|
||||
namespace Unity.XR.PXR
|
||||
{
|
||||
public class PXR_ControllerAnimator : MonoBehaviour
|
||||
{
|
||||
private Animator controllerAnimator;
|
||||
public Transform primary2DAxisTran;
|
||||
public Transform gripTran;
|
||||
public Transform triggerTran;
|
||||
public bool controllerL=false;
|
||||
private Vector2 axis2D = Vector2.zero;
|
||||
private bool primaryButton;
|
||||
private bool secondaryButton;
|
||||
private bool menuButton;
|
||||
private float grip;
|
||||
private float trigger;
|
||||
private Vector3 originalGrip;
|
||||
private Vector3 originalTrigger;
|
||||
private Vector3 originalJoystick;
|
||||
|
||||
public const string primary = "IsPrimaryDown";
|
||||
public const string secondary = "IsSecondaryDown";
|
||||
public const string media = "IsMediaDown";
|
||||
public const string menu = "IsMenuDown";
|
||||
|
||||
void Start()
|
||||
{
|
||||
controllerAnimator = GetComponent<Animator>();
|
||||
originalGrip = gripTran.localEulerAngles;
|
||||
originalJoystick = primary2DAxisTran.localEulerAngles;
|
||||
originalTrigger = triggerTran.localEulerAngles;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
InputDevices.GetDeviceAtXRNode(controllerL
|
||||
? XRNode.LeftHand
|
||||
: XRNode.RightHand).TryGetFeatureValue(CommonUsages.primary2DAxis, out axis2D);
|
||||
InputDevices.GetDeviceAtXRNode(controllerL
|
||||
? XRNode.LeftHand
|
||||
: XRNode.RightHand).TryGetFeatureValue(CommonUsages.grip, out grip);
|
||||
InputDevices.GetDeviceAtXRNode(controllerL
|
||||
? XRNode.LeftHand
|
||||
: XRNode.RightHand).TryGetFeatureValue(CommonUsages.trigger, out trigger);
|
||||
InputDevices.GetDeviceAtXRNode(controllerL
|
||||
? XRNode.LeftHand
|
||||
: XRNode.RightHand).TryGetFeatureValue(CommonUsages.primaryButton, out primaryButton);
|
||||
InputDevices.GetDeviceAtXRNode(controllerL
|
||||
? XRNode.LeftHand
|
||||
: XRNode.RightHand).TryGetFeatureValue(CommonUsages.secondaryButton, out secondaryButton);
|
||||
InputDevices.GetDeviceAtXRNode(controllerL
|
||||
? XRNode.LeftHand
|
||||
: XRNode.RightHand).TryGetFeatureValue(CommonUsages.menuButton, out menuButton);
|
||||
|
||||
float x = Mathf.Clamp(axis2D.x * 10f, -10f, 10f);
|
||||
float z = Mathf.Clamp(axis2D.y * 10f, -10f, 10f);
|
||||
if (primary2DAxisTran != null)
|
||||
{
|
||||
if (controllerL)
|
||||
{
|
||||
primary2DAxisTran.localEulerAngles = new Vector3(-z, 0, x) + originalJoystick;
|
||||
}
|
||||
else
|
||||
{
|
||||
primary2DAxisTran.localEulerAngles = new Vector3(-z, 0, -x) + originalJoystick;
|
||||
}
|
||||
}
|
||||
|
||||
trigger *= -15;
|
||||
if (triggerTran != null)
|
||||
triggerTran.localEulerAngles = new Vector3(trigger, 0f, 0f) + originalTrigger;
|
||||
grip *= 12;
|
||||
if (gripTran != null)
|
||||
gripTran.localEulerAngles = new Vector3(0f, grip, 0f) + originalGrip;
|
||||
|
||||
if (controllerAnimator != null)
|
||||
{
|
||||
controllerAnimator.SetBool(primary, primaryButton);
|
||||
controllerAnimator.SetBool(secondary, secondaryButton);
|
||||
|
||||
|
||||
if (controllerL)
|
||||
controllerAnimator.SetBool(menu, menuButton);
|
||||
else
|
||||
controllerAnimator.SetBool(media, menuButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0551a3e12ecf0614fa83e84a93d87bb5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
Copyright ? 2015-2022 PICO Technology Co., Ltd.All rights reserved.
|
||||
|
||||
NOTICE:All information contained herein is, and remains the property of
|
||||
PICO Technology Co., Ltd. The intellectual and technical concepts
|
||||
contained herein are proprietary to PICO Technology Co., Ltd. and may be
|
||||
covered by patents, patents in process, and are protected by trade secret or
|
||||
copyright law. Dissemination of this information or reproduction of this
|
||||
material is strictly forbidden unless prior written permission is obtained from
|
||||
PICO Technology Co., Ltd.
|
||||
*******************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR;
|
||||
|
||||
namespace Unity.XR.PXR
|
||||
{
|
||||
public class PXR_ControllerG3Animator : MonoBehaviour
|
||||
{
|
||||
public Transform triggerTran;
|
||||
public Transform menuTran;
|
||||
public Transform touchPadTran;
|
||||
|
||||
|
||||
private bool primaryAxisState = false;
|
||||
private bool menuButtonState;
|
||||
private float trigger;
|
||||
|
||||
private Vector3 menu;
|
||||
private Vector3 originTrigger;
|
||||
private Vector3 touchPadPos;
|
||||
|
||||
|
||||
private InputDevice currentController;
|
||||
private int handness;
|
||||
|
||||
void Start()
|
||||
{
|
||||
menu = menuTran.localPosition;
|
||||
originTrigger = triggerTran.localEulerAngles;
|
||||
touchPadPos = touchPadTran.localPosition;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
InputDevices.GetDeviceAtXRNode(XRNode.RightHand).TryGetFeatureValue(CommonUsages.primary2DAxisClick, out primaryAxisState);
|
||||
InputDevices.GetDeviceAtXRNode(XRNode.RightHand).TryGetFeatureValue(CommonUsages.menuButton, out menuButtonState);
|
||||
InputDevices.GetDeviceAtXRNode(XRNode.RightHand).TryGetFeatureValue(CommonUsages.trigger, out trigger);
|
||||
|
||||
if (triggerTran != null)
|
||||
{
|
||||
trigger *= -9.0f;
|
||||
triggerTran.localEulerAngles = new Vector3(0f, 0f, Mathf.Clamp(trigger, -9f, 0f)) + originTrigger;
|
||||
}
|
||||
|
||||
if (touchPadTran != null)
|
||||
{
|
||||
if (primaryAxisState)
|
||||
touchPadTran.localPosition = touchPadPos + new Vector3(0f, -0.0005f, 0f);
|
||||
else
|
||||
touchPadTran.localPosition = touchPadPos;
|
||||
}
|
||||
|
||||
if (menuButtonState)
|
||||
menuTran.localPosition = new Vector3(0f, -0.00021f, 0f) + menu;
|
||||
else
|
||||
menuTran.localPosition = menu;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4ee62d8e7a57c8458f969922f7a06a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,182 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2015-2022 PICO Technology Co., Ltd.All rights reserved.
|
||||
|
||||
NOTICE:All information contained herein is, and remains the property of
|
||||
PICO Technology Co., Ltd. The intellectual and technical concepts
|
||||
contained herein are proprietary to PICO Technology Co., Ltd. and may be
|
||||
covered by patents, patents in process, and are protected by trade secret or
|
||||
copyright law. Dissemination of this information or reproduction of this
|
||||
material is strictly forbidden unless prior written permission is obtained from
|
||||
PICO Technology Co., Ltd.
|
||||
*******************************************************************************/
|
||||
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using LitJson;
|
||||
using Unity.XR.OpenXR.Features.PICOSupport;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR;
|
||||
|
||||
namespace Unity.XR.PXR
|
||||
{
|
||||
public class PXR_ControllerLoader : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private bool Lefthand;
|
||||
|
||||
public GameObject neo3L;
|
||||
public GameObject neo3R;
|
||||
public GameObject PICO_4L;
|
||||
public GameObject PICO_4R;
|
||||
public GameObject G3;
|
||||
public GameObject PICO_4U_L;
|
||||
public GameObject PICO_4U_R;
|
||||
|
||||
private Texture2D modelTexture2D;
|
||||
|
||||
private int controllerType = -1;
|
||||
|
||||
private JsonData curControllerData = null;
|
||||
private int systemOrLocal = 0;
|
||||
private bool loadModelSuccess = false;
|
||||
private string modelName = "";
|
||||
private string texFormat = "";
|
||||
private string prePath = "";
|
||||
private bool isconnect = false;
|
||||
|
||||
private bool leftControllerState = false;
|
||||
private bool rightControllerState = false;
|
||||
|
||||
private enum ControllerSimulationType
|
||||
{
|
||||
None,
|
||||
Neo3,
|
||||
PICO4,
|
||||
G3,
|
||||
PICO4U
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[SerializeField]
|
||||
private ControllerSimulationType controllerSimulation = ControllerSimulationType.None;
|
||||
#endif
|
||||
|
||||
private InputDevice currentController;
|
||||
void Awake()
|
||||
{
|
||||
|
||||
#if UNITY_EDITOR
|
||||
switch (controllerSimulation)
|
||||
{
|
||||
case ControllerSimulationType.Neo3:
|
||||
{
|
||||
Instantiate(Lefthand ? neo3L : neo3R, transform, false);
|
||||
break;
|
||||
}
|
||||
case ControllerSimulationType.PICO4:
|
||||
{
|
||||
Instantiate(Lefthand ? PICO_4L : PICO_4R, transform, false);
|
||||
break;
|
||||
}
|
||||
case ControllerSimulationType.G3:
|
||||
{
|
||||
Instantiate(G3, transform, false);
|
||||
break;
|
||||
}
|
||||
case ControllerSimulationType.PICO4U:
|
||||
{
|
||||
Instantiate(Lefthand ? PICO_4U_L : PICO_4U_R, transform, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
controllerType = OpenXRExtensions.GetControllerType();
|
||||
InputDevices.GetDeviceAtXRNode(Lefthand
|
||||
? XRNode.LeftHand
|
||||
: XRNode.RightHand).TryGetFeatureValue(CommonUsages.isTracked, out isconnect);
|
||||
if (isconnect)
|
||||
{
|
||||
RefreshController();
|
||||
}
|
||||
|
||||
InvokeRepeating("CheckConnect", 0, 0.5f);
|
||||
}
|
||||
|
||||
void CheckConnect()
|
||||
{
|
||||
InputDevices.GetDeviceAtXRNode(Lefthand
|
||||
? XRNode.LeftHand
|
||||
: XRNode.RightHand).TryGetFeatureValue(CommonUsages.isTracked, out isconnect);
|
||||
if (isconnect)
|
||||
{
|
||||
RefreshController();
|
||||
}
|
||||
else
|
||||
{
|
||||
DestroyLocalController();
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshController()
|
||||
{
|
||||
if (!loadModelSuccess)
|
||||
{
|
||||
LoadControllerFromPrefab(Lefthand);
|
||||
}
|
||||
|
||||
if (loadModelSuccess)
|
||||
{
|
||||
var currentController = transform.Find(modelName);
|
||||
currentController.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void DestroyLocalController()
|
||||
{
|
||||
if (loadModelSuccess)
|
||||
{
|
||||
var currentController = transform.Find(modelName);
|
||||
currentController.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadControllerFromPrefab(bool hand)
|
||||
{
|
||||
GameObject go;
|
||||
switch (controllerType)
|
||||
{
|
||||
case 5:
|
||||
go= Instantiate(hand ? neo3L : neo3R, transform, false);
|
||||
go.name=modelName = (hand ? neo3L : neo3R).name;
|
||||
loadModelSuccess = true;
|
||||
break;
|
||||
case 6:
|
||||
go= Instantiate(hand ? PICO_4L : PICO_4R, transform, false);
|
||||
go.name=modelName = (hand ? PICO_4L : PICO_4R).name;
|
||||
loadModelSuccess = true;
|
||||
break;
|
||||
case 7:
|
||||
go=Instantiate(G3, transform, false);
|
||||
go.name=modelName = G3.name;
|
||||
loadModelSuccess = true;
|
||||
break;
|
||||
case 8:
|
||||
go=Instantiate(hand ? PICO_4U_L : PICO_4U_R, transform, false);
|
||||
go.name=modelName = (hand ? PICO_4U_L : PICO_4U_R).name;
|
||||
loadModelSuccess = true;
|
||||
break;
|
||||
default:
|
||||
loadModelSuccess = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1ba2bcdb414e3b47aca41fdc1a87e64
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,128 @@
|
||||
/*******************************************************************************
|
||||
Copyright ? 2015-2022 PICO Technology Co., Ltd.All rights reserved.
|
||||
|
||||
NOTICE:All information contained herein is, and remains the property of
|
||||
PICO Technology Co., Ltd. The intellectual and technical concepts
|
||||
contained herein are proprietary to PICO Technology Co., Ltd. and may be
|
||||
covered by patents, patents in process, and are protected by trade secret or
|
||||
copyright law. Dissemination of this information or reproduction of this
|
||||
material is strictly forbidden unless prior written permission is obtained from
|
||||
PICO Technology Co., Ltd.
|
||||
*******************************************************************************/
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.XR.PXR;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR;
|
||||
|
||||
public class PXR_ControllerPower : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Texture power1;
|
||||
[SerializeField]
|
||||
private Texture power2;
|
||||
[SerializeField]
|
||||
private Texture power3;
|
||||
[SerializeField]
|
||||
private Texture power4;
|
||||
[SerializeField]
|
||||
private Texture power5;
|
||||
|
||||
private Material powerMaterial;
|
||||
private float interval = 2f;
|
||||
public bool controllerL=false;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake()
|
||||
{
|
||||
if (GetComponent<MeshRenderer>() != null)
|
||||
{
|
||||
powerMaterial = GetComponent<MeshRenderer>().material;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
powerMaterial = GetComponent<SkinnedMeshRenderer>().material;
|
||||
}
|
||||
|
||||
|
||||
// Vector3 a=Vector3.zero;
|
||||
// InputDevices.GetDeviceAtXRNode(XRNode.CenterEye).TryGetFeatureValue(EyeTrackingUsages.gazePosition, out a);
|
||||
}
|
||||
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
RefreshPower();
|
||||
}
|
||||
|
||||
private void RefreshPower()
|
||||
{
|
||||
var curBattery = 0f;
|
||||
if (controllerL)
|
||||
{
|
||||
InputDevices.GetDeviceAtXRNode(XRNode.LeftHand).TryGetFeatureValue(CommonUsages.batteryLevel, out curBattery);
|
||||
}
|
||||
else
|
||||
{
|
||||
InputDevices.GetDeviceAtXRNode(XRNode.RightHand).TryGetFeatureValue(CommonUsages.batteryLevel, out curBattery);
|
||||
}
|
||||
switch ((int)curBattery)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
powerMaterial.SetTexture("_MainTex", power1);
|
||||
powerMaterial.SetTexture("_EmissionMap", power1);
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
powerMaterial.SetTexture("_MainTex", power2);
|
||||
powerMaterial.SetTexture("_EmissionMap", power2);
|
||||
}
|
||||
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
powerMaterial.SetTexture("_MainTex", power3);
|
||||
powerMaterial.SetTexture("_EmissionMap", power3);
|
||||
}
|
||||
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
powerMaterial.SetTexture("_MainTex", power4);
|
||||
powerMaterial.SetTexture("_EmissionMap", power4);
|
||||
}
|
||||
|
||||
break;
|
||||
case 5:
|
||||
{
|
||||
powerMaterial.SetTexture("_MainTex", power5);
|
||||
powerMaterial.SetTexture("_EmissionMap", power5);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
{
|
||||
powerMaterial.SetTexture("_MainTex", power1);
|
||||
powerMaterial.SetTexture("_EmissionMap", power1);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
interval -= Time.deltaTime;
|
||||
if (interval > 0)
|
||||
return;
|
||||
interval = 2f;
|
||||
|
||||
RefreshPower();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7cfc8380945cdad43ae2cacaadf47013
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,304 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR;
|
||||
|
||||
|
||||
namespace Unity.XR.PXR
|
||||
{
|
||||
public class PXR_ControllerWithHandAnimator : MonoBehaviour
|
||||
{
|
||||
public bool controllerL=false;
|
||||
|
||||
private Animator mAnimator;
|
||||
|
||||
|
||||
private readonly float animation_time = 0.05f;
|
||||
private float per_animation_step = 0.1f;
|
||||
|
||||
//trigger;
|
||||
private readonly string trigger_Touch_LayerName = "trigger_touch";
|
||||
private int trigger_Touch_LayerIndex;
|
||||
private readonly string trigger_Value_LayerName = "trigger_press";
|
||||
private int trigger_Value_LayerIndex;
|
||||
private bool trigger_Touch;
|
||||
private float trigger_Value;
|
||||
private float trigger_Touch_Weight = 0f;
|
||||
|
||||
// A/X;
|
||||
private readonly string X_A_Touch_LayerName = "X_A_touch";
|
||||
private int X_A_Touch_LayerIndex;
|
||||
private readonly string X_A_Press_LayerName = "X_A_press";
|
||||
private int X_A_Press_LayerIndex;
|
||||
private bool X_A_Press;
|
||||
private bool X_A_Touch;
|
||||
private float X_A_Touch_Weight = 0f;
|
||||
|
||||
// B/Y;
|
||||
private readonly string Y_B_Touch_LayerName = "Y_B_touch";
|
||||
private int Y_B_Touch_LayerIndex;
|
||||
private readonly string Y_B_Press_LayerName = "Y_B_press";
|
||||
private int Y_B_Press_LayerIndex;
|
||||
private bool Y_B_Press;
|
||||
private bool Y_B_Touch;
|
||||
private float Y_B_Touch_Weight = 0f;
|
||||
|
||||
//Y/B or X/A
|
||||
private readonly string X_A_Y_B_Press_LayerName = "X_A_Y_B_press";
|
||||
private int X_A_Y_B_Press_LayerIndex;
|
||||
|
||||
//Y/B or X/A
|
||||
private readonly string X_A_Y_B_Touch_LayerName = "X_A_Y_B_touch";
|
||||
private int X_A_Y_B_Touch_LayerIndex;
|
||||
private float X_A_Y_B_Touch_Weight = 0f;
|
||||
|
||||
//grip;
|
||||
private readonly string grip_Value_LayerName = "grip_press";
|
||||
private int grip_Value_LayerIndex;
|
||||
private float grip_Value;
|
||||
|
||||
//rocker
|
||||
private readonly string primary2DAxis_Touch_LayerName = "axis_touch";
|
||||
private int primary2DAxis_Touch_LayerIndex;
|
||||
private readonly string primary2DAxis_Vertical = "axis_vertical";
|
||||
private int primary2DAxis_Vertical_Index;
|
||||
private readonly string primary2DAxis_Horizontal = "axis_horizontal";
|
||||
private int primary2DAxis_Horizontal_Index;
|
||||
private Vector2 primary2DAxisVec2;
|
||||
private bool primary2DAxis_Touch;
|
||||
private float primary2DAxis_Touch_Weight = 0f;
|
||||
|
||||
//print screen
|
||||
private readonly string menu_Press_LayerName = "thumbMenu";
|
||||
private int menu_Press_LayerIndex;
|
||||
private bool menu_Press;
|
||||
private float menu_Press_Weight;
|
||||
|
||||
//home
|
||||
private readonly string pico_Press_LayerName = "thumbPico";
|
||||
private int pico_Press_LayerIndex;
|
||||
private bool pico_Press;
|
||||
private float pico_Press_Weight;
|
||||
|
||||
//thumb rest
|
||||
private readonly string thumbstick_Touch_LayerName = "thumbstick_touch";
|
||||
private int thumbstick_Touch_LayerIndex;
|
||||
private bool thumbstick_Touch;
|
||||
private float thumbstick_Touch_Weight;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
per_animation_step = 1.0f / animation_time;
|
||||
mAnimator = GetComponent<Animator>();
|
||||
|
||||
if (mAnimator != null)
|
||||
{
|
||||
trigger_Touch_LayerIndex = mAnimator.GetLayerIndex(trigger_Touch_LayerName);
|
||||
trigger_Value_LayerIndex = mAnimator.GetLayerIndex(trigger_Value_LayerName);
|
||||
grip_Value_LayerIndex = mAnimator.GetLayerIndex(grip_Value_LayerName);
|
||||
|
||||
X_A_Touch_LayerIndex = mAnimator.GetLayerIndex(X_A_Touch_LayerName);
|
||||
X_A_Press_LayerIndex = mAnimator.GetLayerIndex(X_A_Press_LayerName);
|
||||
Y_B_Touch_LayerIndex = mAnimator.GetLayerIndex(Y_B_Touch_LayerName);
|
||||
Y_B_Press_LayerIndex = mAnimator.GetLayerIndex(Y_B_Press_LayerName);
|
||||
X_A_Y_B_Press_LayerIndex = mAnimator.GetLayerIndex(X_A_Y_B_Press_LayerName);
|
||||
X_A_Y_B_Touch_LayerIndex = mAnimator.GetLayerIndex(X_A_Y_B_Touch_LayerName);
|
||||
primary2DAxis_Touch_LayerIndex = mAnimator.GetLayerIndex(primary2DAxis_Touch_LayerName);
|
||||
thumbstick_Touch_LayerIndex = mAnimator.GetLayerIndex(thumbstick_Touch_LayerName);
|
||||
|
||||
primary2DAxis_Vertical_Index = Animator.StringToHash(primary2DAxis_Vertical);
|
||||
primary2DAxis_Horizontal_Index = Animator.StringToHash(primary2DAxis_Horizontal);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Animator is null");
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
InputDevices.GetDeviceAtXRNode(controllerL ? XRNode.LeftHand : XRNode.RightHand).TryGetFeatureValue(CommonUsages.primaryButton, out X_A_Press);
|
||||
InputDevices.GetDeviceAtXRNode(controllerL ? XRNode.LeftHand : XRNode.RightHand).TryGetFeatureValue(CommonUsages.primaryTouch, out X_A_Touch);
|
||||
|
||||
InputDevices.GetDeviceAtXRNode(controllerL ? XRNode.LeftHand : XRNode.RightHand).TryGetFeatureValue(CommonUsages.secondaryButton, out Y_B_Press);
|
||||
InputDevices.GetDeviceAtXRNode(controllerL ? XRNode.LeftHand : XRNode.RightHand).TryGetFeatureValue(CommonUsages.secondaryTouch, out Y_B_Touch);
|
||||
|
||||
InputDevices.GetDeviceAtXRNode(controllerL ? XRNode.LeftHand : XRNode.RightHand).TryGetFeatureValue(CommonUsages.trigger, out trigger_Value);
|
||||
InputDevices.GetDeviceAtXRNode(controllerL ? XRNode.LeftHand : XRNode.RightHand).TryGetFeatureValue(CommonUsages.triggerButton, out trigger_Touch);
|
||||
|
||||
InputDevices.GetDeviceAtXRNode(controllerL ? XRNode.LeftHand : XRNode.RightHand).TryGetFeatureValue(CommonUsages.grip, out grip_Value);
|
||||
|
||||
InputDevices.GetDeviceAtXRNode(controllerL ? XRNode.LeftHand : XRNode.RightHand).TryGetFeatureValue(CommonUsages.primary2DAxis, out primary2DAxisVec2);
|
||||
InputDevices.GetDeviceAtXRNode(controllerL ? XRNode.LeftHand : XRNode.RightHand).TryGetFeatureValue(CommonUsages.primary2DAxisTouch, out primary2DAxis_Touch);
|
||||
if (!primary2DAxis_Touch)
|
||||
{
|
||||
if (primary2DAxisVec2 != Vector2.zero)
|
||||
primary2DAxis_Touch = true;
|
||||
}
|
||||
|
||||
InputDevices.GetDeviceAtXRNode(controllerL ? XRNode.LeftHand : XRNode.RightHand).TryGetFeatureValue(CommonUsages.menuButton, out menu_Press);
|
||||
|
||||
if (Y_B_Touch && primary2DAxisVec2 == Vector2.zero)
|
||||
{
|
||||
if (Y_B_Press)
|
||||
{
|
||||
Y_B_Touch_Weight = 1.0f;
|
||||
mAnimator.SetLayerWeight(Y_B_Touch_LayerIndex, Y_B_Touch_Weight);
|
||||
mAnimator.SetLayerWeight(Y_B_Press_LayerIndex, 1.0f);
|
||||
mAnimator.SetLayerWeight(X_A_Y_B_Press_LayerIndex, X_A_Press ? 1.0f : 0.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (X_A_Touch)
|
||||
{
|
||||
if (X_A_Press)
|
||||
{
|
||||
X_A_Touch_Weight = 1.0f;
|
||||
mAnimator.SetLayerWeight(X_A_Touch_LayerIndex, X_A_Touch_Weight);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (X_A_Y_B_Touch_Weight < 0.9999f)
|
||||
{
|
||||
X_A_Y_B_Touch_Weight = Mathf.Min(mAnimator.GetLayerWeight(X_A_Y_B_Touch_LayerIndex) + Time.deltaTime * per_animation_step, 1.0f);
|
||||
mAnimator.SetLayerWeight(X_A_Y_B_Touch_LayerIndex, X_A_Y_B_Touch_Weight);
|
||||
}
|
||||
}
|
||||
mAnimator.SetLayerWeight(X_A_Press_LayerIndex, X_A_Press ? 1.0f : 0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Y_B_Touch_Weight < 0.9999f)
|
||||
{
|
||||
Y_B_Touch_Weight = Mathf.Min(mAnimator.GetLayerWeight(Y_B_Touch_LayerIndex) + Time.deltaTime * per_animation_step, 1.0f);
|
||||
mAnimator.SetLayerWeight(Y_B_Touch_LayerIndex, Y_B_Touch_Weight);
|
||||
}
|
||||
if (X_A_Y_B_Touch_Weight > 0.0001f)
|
||||
{
|
||||
X_A_Y_B_Touch_Weight = Mathf.Max(mAnimator.GetLayerWeight(X_A_Y_B_Touch_LayerIndex) - Time.deltaTime * per_animation_step, 0.0f);
|
||||
mAnimator.SetLayerWeight(X_A_Y_B_Touch_LayerIndex, X_A_Y_B_Touch_Weight);
|
||||
}
|
||||
|
||||
if (X_A_Touch_Weight > 0.0001f)
|
||||
{
|
||||
X_A_Touch_Weight = Mathf.Max(mAnimator.GetLayerWeight(X_A_Touch_LayerIndex) - Time.deltaTime * per_animation_step, 0.0f);
|
||||
mAnimator.SetLayerWeight(X_A_Touch_LayerIndex, X_A_Touch_Weight);
|
||||
}
|
||||
}
|
||||
mAnimator.SetLayerWeight(Y_B_Press_LayerIndex, 0.0f);
|
||||
mAnimator.SetLayerWeight(X_A_Y_B_Press_LayerIndex, 0.0f);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Y_B_Touch_Weight > 0.0001f)
|
||||
{
|
||||
Y_B_Touch_Weight = Mathf.Max(mAnimator.GetLayerWeight(Y_B_Touch_LayerIndex) - Time.deltaTime * per_animation_step, 0.0f);
|
||||
mAnimator.SetLayerWeight(Y_B_Touch_LayerIndex, Y_B_Touch_Weight);
|
||||
mAnimator.SetLayerWeight(Y_B_Press_LayerIndex, 0.0f);
|
||||
mAnimator.SetLayerWeight(X_A_Y_B_Press_LayerIndex, 0.0f);
|
||||
}
|
||||
if (X_A_Y_B_Touch_Weight > 0.0001f)
|
||||
{
|
||||
X_A_Y_B_Touch_Weight = Mathf.Max(mAnimator.GetLayerWeight(X_A_Y_B_Touch_LayerIndex) - Time.deltaTime * per_animation_step, 0.0f);
|
||||
|
||||
mAnimator.SetLayerWeight(X_A_Y_B_Touch_LayerIndex, X_A_Y_B_Touch_Weight);
|
||||
mAnimator.SetLayerWeight(Y_B_Press_LayerIndex, 0.0f);
|
||||
mAnimator.SetLayerWeight(X_A_Y_B_Press_LayerIndex, 0.0f);
|
||||
}
|
||||
if (X_A_Touch && primary2DAxisVec2 == Vector2.zero)
|
||||
{
|
||||
if (X_A_Press)
|
||||
{
|
||||
X_A_Touch_Weight = 1.0f;
|
||||
mAnimator.SetLayerWeight(X_A_Touch_LayerIndex, X_A_Touch_Weight);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (X_A_Touch_Weight < 0.9999f)
|
||||
{
|
||||
X_A_Touch_Weight = Mathf.Min(mAnimator.GetLayerWeight(X_A_Touch_LayerIndex) + Time.deltaTime * per_animation_step, 1.0f);
|
||||
mAnimator.SetLayerWeight(X_A_Touch_LayerIndex, X_A_Touch_Weight);
|
||||
}
|
||||
}
|
||||
mAnimator.SetLayerWeight(X_A_Press_LayerIndex, X_A_Press ? 1.0f : 0f);
|
||||
mAnimator.SetFloat(primary2DAxis_Vertical_Index, 0f);
|
||||
mAnimator.SetFloat(primary2DAxis_Horizontal_Index, 0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (X_A_Touch_Weight > 0.0001f)
|
||||
{
|
||||
X_A_Touch_Weight = Mathf.Max(mAnimator.GetLayerWeight(X_A_Touch_LayerIndex) - Time.deltaTime * per_animation_step, 0.0f);
|
||||
mAnimator.SetLayerWeight(X_A_Touch_LayerIndex, X_A_Touch_Weight);
|
||||
mAnimator.SetLayerWeight(X_A_Press_LayerIndex, 0f);
|
||||
}
|
||||
if (primary2DAxis_Touch)
|
||||
{
|
||||
if (primary2DAxis_Touch_Weight < 0.9999f)
|
||||
{
|
||||
primary2DAxis_Touch_Weight = Mathf.Min(mAnimator.GetLayerWeight(primary2DAxis_Touch_LayerIndex) + Time.deltaTime * per_animation_step, 1.0f);
|
||||
mAnimator.SetLayerWeight(primary2DAxis_Touch_LayerIndex, primary2DAxis_Touch_Weight);
|
||||
}
|
||||
mAnimator.SetFloat(primary2DAxis_Vertical_Index, primary2DAxisVec2.y);
|
||||
mAnimator.SetFloat(primary2DAxis_Horizontal_Index, primary2DAxisVec2.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (primary2DAxis_Touch_Weight > 0.0001f)
|
||||
{
|
||||
primary2DAxis_Touch_Weight = Mathf.Max(mAnimator.GetLayerWeight(primary2DAxis_Touch_LayerIndex) - Time.deltaTime * per_animation_step, 0.0f);
|
||||
mAnimator.SetLayerWeight(primary2DAxis_Touch_LayerIndex, primary2DAxis_Touch_Weight);
|
||||
|
||||
mAnimator.SetFloat(primary2DAxis_Vertical_Index, 0f);
|
||||
mAnimator.SetFloat(primary2DAxis_Horizontal_Index, 0f);
|
||||
}
|
||||
if (thumbstick_Touch)
|
||||
{
|
||||
if (thumbstick_Touch_Weight < 0.9999f)
|
||||
{
|
||||
thumbstick_Touch_Weight = Mathf.Min(mAnimator.GetLayerWeight(thumbstick_Touch_LayerIndex) + Time.deltaTime * per_animation_step, 1.0f);
|
||||
mAnimator.SetLayerWeight(thumbstick_Touch_LayerIndex, thumbstick_Touch_Weight);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (thumbstick_Touch_Weight > 0.0001f)
|
||||
{
|
||||
thumbstick_Touch_Weight = Mathf.Max(mAnimator.GetLayerWeight(thumbstick_Touch_LayerIndex) - Time.deltaTime * per_animation_step, 0.0f);
|
||||
mAnimator.SetLayerWeight(thumbstick_Touch_LayerIndex, thumbstick_Touch_Weight);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (trigger_Touch)
|
||||
{
|
||||
if (trigger_Touch_Weight < 0.9999f)
|
||||
{
|
||||
trigger_Touch_Weight = Mathf.Min(mAnimator.GetLayerWeight(trigger_Touch_LayerIndex) + Time.deltaTime * per_animation_step, 1.0f);
|
||||
mAnimator.SetLayerWeight(trigger_Touch_LayerIndex, trigger_Touch_Weight);
|
||||
}
|
||||
mAnimator.SetLayerWeight(trigger_Value_LayerIndex, trigger_Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (trigger_Touch_Weight > 0.0001f)
|
||||
{
|
||||
trigger_Touch_Weight = Mathf.Max(mAnimator.GetLayerWeight(trigger_Touch_LayerIndex) - Time.deltaTime * per_animation_step, 0.0f);
|
||||
mAnimator.SetLayerWeight(trigger_Touch_LayerIndex, trigger_Touch_Weight);
|
||||
}
|
||||
}
|
||||
mAnimator.SetLayerWeight(grip_Value_LayerIndex, grip_Value);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad904341cd701b544911a03d77412e1d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user