using System.Collections.Generic;
using UnityEngine;
namespace Passer.Humanoid {
using Passer.Tracking;
using Tracking;
///
/// A %Humanoid tracker
///
public class HumanoidTracker : Tracker {
///
/// The humanoid for this tracker
///
public HumanoidControl humanoid;
#region Manage
///
/// Check the status of the tracker
///
/// The humanoid for which the tracker needs to be checked
public virtual void CheckTracker(HumanoidControl humanoid) {
if (this.humanoid == null)
this.humanoid = humanoid;
}
///
/// Function delegate for retrieving the tracker
///
/// The root transform to start the searching of the tracker
/// The default local position of the tracker
/// The default local rotation of the tracker
/// The tracker component found or created
/// The default position/rotation is relative to the humanoid's real world.
public delegate TrackerComponent TrackerGetter(Transform transform, Vector3 localPosition, Quaternion localRotation);
///
/// Function to check the status of a specific tracker
///
/// The humanoid for which the tracker needs to be checked
/// Function delegate to retrieve the tracker
/// The default position/rotation for the tracker when created will be zero
public void CheckTracker(HumanoidControl humanoid, TrackerGetter getTracker) {
CheckTracker(humanoid, getTracker, Vector3.zero, Quaternion.identity);
}
///
/// Function to check the status of a specific tracker
///
/// The humanoid for which the tracker needs to be checked
/// Function delegate to retrieve the tracker
/// The default local position of the tracker
/// The default local rotation of the tracker
public void CheckTracker(HumanoidControl humanoid, TrackerGetter getTracker, Vector3 localPosition, Quaternion localRotation) {
if (this.humanoid == null)
this.humanoid = humanoid;
if (this.humanoid == null)
return;
if (enabled) {
if (trackerComponent == null) {
Transform realWorld = this.humanoid.realWorld;
//Vector3 position = realWorld.TransformPoint(localPosition);
//Quaternion rotation = realWorld.rotation * localRotation;
trackerComponent = getTracker(realWorld, localPosition, localRotation);
}
if (trackerComponent == null)
return;
}
else {
#if UNITY_EDITOR
if (!Application.isPlaying) {
if (trackerComponent != null)
UnityEngine.Object.DestroyImmediate(trackerComponent.gameObject, true);
}
#endif
trackerComponent = null;
}
}
#endregion Manage
#region Device
#if hFACE
public virtual Vector3 GetBonePosition(uint actorId, FacialBone boneId) { return Vector3.zero; }
public virtual Quaternion GetBoneRotation(uint actorId, FacialBone boneId) { return Quaternion.identity; }
public virtual float GetBoneConfidence(uint actorId, FacialBone boneId) { return 0; }
#endif
#endregion
///
/// Get the sensor for the head
///
/// Will return null when this sensor is not present
public virtual HeadSensor headSensor {
get { return null; }
}
///
/// Get the sensor for the left hand
///
/// Will return null when this sensor is not present
public virtual ArmSensor leftHandSensor {
get { return null; }
}
///
/// Get the sensor for the right hand
///
/// Will return null when this sensor is not present
public virtual ArmSensor rightHandSensor {
get { return null; }
}
///
/// Get the sensor for the hips
///
/// Will return null when this sensor is not present
public virtual TorsoSensor hipsSensor {
get { return null; }
}
///
/// Get the sensor for the left foot
///
/// Will return null when this sensor is not present
public virtual LegSensor leftFootSensor {
get { return null; }
}
///
/// Get the sensor for the right foot
///
/// Will return null when this sensor is not present
public virtual LegSensor rightFootSensor {
get { return null; }
}
private HumanoidSensor[] _sensors = new HumanoidSensor[0];
///
/// The sensors for this tracker
///
public virtual HumanoidSensor[] sensors {
get { return _sensors; }
}
#region Init
/// Start the tracker
public virtual void StartTracker(HumanoidControl _humanoid) {
base.StartTracker();
humanoid = _humanoid;
}
#endregion Init
}
public abstract class SubTracker : MonoBehaviour {
public HumanoidTracker tracker;
public int subTrackerId = -1;
public abstract bool IsPresent();
public abstract void UpdateTracker(bool showRealObjects);
}
}