protected void UpdateHandModels(Dictionary <int, HandModel> all_hands, HandList leap_hands, HandModel left_model, HandModel right_model) { List <int> ids_to_check = new List <int>(all_hands.Keys); // Go through all the active hands and update them. int num_hands = leap_hands.Count; for (int h = 0; h < num_hands; ++h) { Hand leap_hand = leap_hands[h]; HandModel model = (mirrorZAxis != leap_hand.IsLeft) ? left_model : right_model; // If we've mirrored since this hand was updated, destroy it. if (all_hands.ContainsKey(leap_hand.Id) && all_hands[leap_hand.Id].IsMirrored() != mirrorZAxis) { DestroyHand(all_hands[leap_hand.Id]); all_hands.Remove(leap_hand.Id); } // Only create or update if the hand is enabled. if (model != null) { ids_to_check.Remove(leap_hand.Id); // Create the hand and initialized it if it doesn't exist yet. if (!all_hands.ContainsKey(leap_hand.Id)) { HandModel new_hand = CreateHand(model); new_hand.SetLeapHand(leap_hand); new_hand.MirrorZAxis(mirrorZAxis); new_hand.SetController(this); // Set scaling based on reference hand. float hand_scale = MM_TO_M * leap_hand.PalmWidth / new_hand.handModelPalmWidth; new_hand.transform.localScale = hand_scale * transform.lossyScale; new_hand.InitHand(); new_hand.UpdateHand(); all_hands[leap_hand.Id] = new_hand; } else { // Make sure we update the Leap Hand reference. HandModel hand_model = all_hands[leap_hand.Id]; hand_model.SetLeapHand(leap_hand); hand_model.MirrorZAxis(mirrorZAxis); // Set scaling based on reference hand. float hand_scale = MM_TO_M * leap_hand.PalmWidth / hand_model.handModelPalmWidth; hand_model.transform.localScale = hand_scale * transform.lossyScale; hand_model.UpdateHand(); } } } // Destroy all hands with defunct IDs. for (int i = 0; i < ids_to_check.Count; ++i) { DestroyHand(all_hands[ids_to_check[i]]); all_hands.Remove(ids_to_check[i]); } }