// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) VRMADA, All rights reserved. // // -------------------------------------------------------------------------------------------------------------------- using System; using System.Collections.Generic; using UnityEngine; namespace UltimateXR.Avatar.Rig { /// /// Stores bone references of an Avatar's finger. /// [Serializable] public class UxrAvatarFinger { #region Inspector Properties/Serialized Fields [SerializeField] private Transform _metacarpal; [SerializeField] private Transform _proximal; [SerializeField] private Transform _intermediate; [SerializeField] private Transform _distal; #endregion #region Public Types & Data /// /// Gets a sequence of all the non-null transforms in the finger. /// public IEnumerable Transforms { get { if (Metacarpal != null) { yield return Metacarpal; } if (Proximal != null) { yield return Proximal; } if (Intermediate != null) { yield return Intermediate; } if (Distal != null) { yield return Distal; } } } /// /// Gets or sets the metacarpal bone transform. Metacarpal bones are optional. /// public Transform Metacarpal { get => _metacarpal; set => _metacarpal = value; } /// /// Gets or sets the proximal bone transform. /// public Transform Proximal { get => _proximal; set => _proximal = value; } /// /// Gets or sets the intermediate bone transform. /// public Transform Intermediate { get => _intermediate; set => _intermediate = value; } /// /// Gets or sets the distal bone transform. /// public Transform Distal { get => _distal; set => _distal = value; } #endregion #region Public Methods /// /// Checks if the finger has the required bone references. The only optional bone is the metacarpal bone, which may be /// null. /// /// Whether the finger has all the required bone data. public bool HasData() { return Proximal != null && Intermediate != null && Distal != null; } /// /// Sets up the finger bones using a list starting from the metacarpal (if there are 4 elements) or the proximal (if /// there are 3). /// /// Finger bone list. It may be either 4 or 3 bones, depending if the metacarpal bone is included. public void SetupFingerBones(List bones) { if (Metacarpal == null && bones.Count == 4) { Metacarpal = bones[0]; } if (Proximal == null) { Proximal = bones[bones.Count == 4 ? 1 : 0]; } if (Intermediate == null) { Intermediate = bones[bones.Count == 4 ? 2 : 1]; } if (Distal == null) { Distal = bones[bones.Count == 4 ? 3 : 2]; } } #endregion } }