private 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 = leap_hand.IsLeft? left_model : right_model;
// 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.SetController(this);
// Set scaling based on reference hand.
float hand_scale = leap_hand.PalmWidth / MODEL_PALM_WIDTH;
new_hand.transform.localScale = hand_scale * transform.localScale;
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);
// Set scaling based on reference hand.
float hand_scale = leap_hand.PalmWidth / MODEL_PALM_WIDTH;
hand_model.transform.localScale = hand_scale * transform.localScale;
hand_model.UpdateHand();
}
}
}
// Destroy all hands with defunct IDs.
for (int i = 0; i < ids_to_check.Count; ++i)
{
Destroy(all_hands[ids_to_check[i]].gameObject);
all_hands.Remove(ids_to_check[i]);
}
}