using UnityEngine;
namespace CreatureControl {
///
/// A leg of a creature
///
[System.Serializable]
public class Leg {
///
/// The upper leg or thigh bone
///
public Transform femur;
///
/// The lower leg or shank bone
///
public Transform tibia;
///
/// The foot bone
///
public Transform tarsus;
[SerializeField]
private float _femurLength;
public float femurLength {
get {
if (_femurLength <= 0 && this.femur != null && this.tibia != null)
_femurLength = Vector3.Distance(this.femur.position, this.tibia.position);
return _femurLength;
}
}
// A bit inefficient is this is used a lot...
//public float tibiaLength => Vector3.Distance(this.tibia.position, this.tarsus.position);
private float _tibiaLength;
public float tibiaLength {
get {
if (_tibiaLength <= 0 && this.tibia != null && this.tarsus != null)
_tibiaLength = Vector3.Distance(this.tibia.position, this.tarsus.position);
return _tibiaLength;
}
}
public float length => femurLength + tibiaLength;
public void ResetLengths() {
_femurLength = 0;
_tibiaLength = 0;
}
///
/// Check if all bones of the legs have been configured
///
/// True when all bones are configured
public bool isConfigured => femur != null && tibia != null && tarsus != null;
}
}