52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
namespace CreatureControl {
|
|
|
|
/// <summary>
|
|
/// A leg of a creature
|
|
/// </summary>
|
|
[System.Serializable]
|
|
public class Leg {
|
|
/// <summary>
|
|
/// The upper leg or thigh bone
|
|
/// </summary>
|
|
public Transform femur;
|
|
/// <summary>
|
|
/// The lower leg or shank bone
|
|
/// </summary>
|
|
public Transform tibia;
|
|
/// <summary>
|
|
/// The foot bone
|
|
/// </summary>
|
|
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;
|
|
|
|
|
|
/// <summary>
|
|
/// Check if all bones of the legs have been configured
|
|
/// </summary>
|
|
/// <returns>True when all bones are configured</returns>
|
|
public bool isConfigured => femur != null && tibia != null && tarsus != null;
|
|
}
|
|
|
|
} |