/// <summary> /// Adds a finger in run-time. /// </summary> public void AddFinger(Transform bone1, Transform bone2, Transform bone3, Transform tip, Transform target = null) { Finger finger = new Finger(); finger.bone1 = bone1; finger.bone2 = bone2; finger.bone3 = bone3; finger.tip = tip; finger.target = target; Array.Resize(ref fingers, fingers.Length + 1); fingers[fingers.Length - 1] = finger; initiated = false; finger.Initiate(transform, fingers.Length - 1); if (fingers[fingers.Length - 1].initiated) initiated = true; }
/// <summary> /// Removes a finger in runtime. /// </summary> public void RemoveFinger(int index) { if (index < 0f || index >= fingers.Length) { Warning.Log("RemoveFinger index out of bounds.", transform); return; } if (fingers.Length == 1) { fingers = new Finger[0]; return; } Finger[] newFingers = new Finger[fingers.Length - 1]; int added = 0; for (int i = 0; i < fingers.Length; i++) { if (i != index) { newFingers[added] = fingers[i]; added ++; } } fingers = newFingers; }
public void AutoDetect() { fingers = new Finger[0]; for (int i = 0; i < transform.childCount; i++) { Transform[] potentialFinger = new Transform[0]; AddChildrenRecursive(transform.GetChild(i), ref potentialFinger); if (potentialFinger.Length == 3 || potentialFinger.Length == 4) { Finger finger = new Finger(); finger.bone1 = potentialFinger[0]; finger.bone2 = potentialFinger[1]; if (potentialFinger.Length == 3) { finger.tip = potentialFinger[2]; } else { finger.bone3 = potentialFinger[2]; finger.tip = potentialFinger[3]; } finger.weight = 1f; Array.Resize(ref fingers, fingers.Length + 1); fingers[fingers.Length - 1] = finger; } } }