Code improvement

This commit is contained in:
Pascal Serrarens 2022-06-10 17:56:04 +02:00
parent 2bcf3e5c10
commit 704559e150
2 changed files with 31 additions and 46 deletions

View File

@ -41,37 +41,42 @@ namespace Passer.Humanoid {
return null;
}
/// <summary>
/// Checks if a sensorComponent is present and will create one if it does not exist
/// </summary>
/// <param name="_handTarget">The HandTarget to which the sensor is assigned</param>
public virtual void CheckSensor(HandTarget _handTarget) {
if (handTarget == null)
target = _handTarget;
}
public virtual void CheckSensor(HandTarget handTarget, HumanoidTracker tracker) {
if (this.handTarget == null)
this.target = handTarget;
if (this.handTarget == null)
return;
// public virtual void CheckSensor(HandTarget handTarget, HumanoidTracker tracker) {
// if (this.handTarget == null)
// this.target = handTarget;
// if (this.handTarget == null)
// return;
//if (this.tracker == null)
// this.tracker = tracker;
// //if (this.tracker == null)
// // this.tracker = tracker;
if (enabled && tracker.enabled) {
if (handSkeleton == null) {
handSkeleton = FindHandSkeleton(handTarget.isLeft);
if (handSkeleton == null)
handSkeleton = CreateHandSkeleton(handTarget.isLeft, handTarget.showRealObjects);
}
}
else {
#if UNITY_EDITOR
if (!Application.isPlaying) {
if (handSkeleton != null)
Object.DestroyImmediate(handSkeleton.gameObject, true);
}
#endif
handSkeleton = null;
}
}
// if (enabled && tracker.enabled) {
// if (handSkeleton == null) {
// handSkeleton = FindHandSkeleton(handTarget.isLeft);
// if (handSkeleton == null)
// handSkeleton = CreateHandSkeleton(handTarget.isLeft, handTarget.showRealObjects);
// }
// }
// else {
//#if UNITY_EDITOR
// if (!Application.isPlaying) {
// if (handSkeleton != null)
// Object.DestroyImmediate(handSkeleton.gameObject, true);
// }
//#endif
// handSkeleton = null;
// }
// }
#endregion

View File

@ -9,28 +9,7 @@ namespace Passer.Humanoid {
public override string name => "Unity XR";
public override HumanoidTracker tracker => humanoid.unityXR;
// public override SensorComponent GetSensorComponent() {
// if (sensorComponent != null)
// return sensorComponent;
// Vector3 position = handTarget.transform.TransformPoint(handTarget.isLeft ? -0.1F : 0.1F, -0.05F, 0.04F);
// Quaternion localRotation = handTarget.isLeft ? Quaternion.Euler(180, 90, 90) : Quaternion.Euler(180, -90, -90);
// Quaternion rotation = handTarget.transform.rotation * localRotation;
//#if hSTEAMVR
// if (UnityXRDevice.xrDevice == UnityXRDevice.XRDeviceType.OpenVR) {
// SteamVR steamVR = unityXR.trackerComponent as SteamVR;
// controller = steamVR.GetController(handTarget.isLeft, position, rotation);
// }
// else
//#endif
// {
// UnityXR unityXRcomponent = unityXR.trackerComponent as UnityXR;
// controller = unityXRcomponent.GetController(handTarget.isLeft, position, rotation);
// }
// return controller as SensorComponent;
// }
protected UnityXR unityXR => tracker.trackerComponent as UnityXR;
protected UnityXR unityXR => humanoid.unityXR.trackerComponent as UnityXR;
#region Manage
@ -48,6 +27,7 @@ namespace Passer.Humanoid {
Vector3 position = handTarget.transform.TransformPoint(handTarget.isLeft ? -0.1F : 0.1F, -0.05F, 0.04F);
Quaternion localRotation = handTarget.isLeft ? Quaternion.Euler(180, 90, 90) : Quaternion.Euler(180, -90, -90);
Quaternion rotation = handTarget.transform.rotation * localRotation;
// This is depreciated, use solution like Leap or Vive Tracker
sensorComponent = unityXR.GetController(handTarget.isLeft, position, rotation);
}