UpdateTool() public méthode

public UpdateTool ( ) : void
Résultat void
Exemple #1
0
    /**
     * Updates tools based on tracking data in the specified Leap ToolList object.
     * Active ToolModel instances are updated if the tool they represent is still
     * present in the Leap ToolList; otherwise, the ToolModel is removed. If new
     * Leap Tool objects are present in the Leap ToolList, new ToolModels are
     * created and added to the HandController tool list.
     * @param all_tools The dictionary containing the ToolModels to update.
     * @param leap_tools The list of tools from the a Leap Frame instance.
     * @param model The ToolModel instance to use for new tools.
     */
    protected void UpdateToolModels(Dictionary <int, ToolModel> all_tools,
                                    ToolList leap_tools, ToolModel model)
    {
        List <int> ids_to_check = new List <int>(all_tools.Keys);

        // Go through all the active tools and update them.
        int num_tools = leap_tools.Count;

        for (int h = 0; h < num_tools; ++h)
        {
            Tool leap_tool = leap_tools[h];

            // Only create or update if the tool is enabled.
            if (model)
            {
                ids_to_check.Remove(leap_tool.Id);

                // Create the tool and initialized it if it doesn't exist yet.
                if (!all_tools.ContainsKey(leap_tool.Id))
                {
                    ToolModel new_tool = CreateTool(model);
                    new_tool.SetController(this);
                    new_tool.SetLeapTool(leap_tool);
                    new_tool.InitTool();
                    all_tools[leap_tool.Id] = new_tool;
                }

                // Make sure we update the Leap Tool reference.
                ToolModel tool_model = all_tools[leap_tool.Id];
                tool_model.SetLeapTool(leap_tool);
                tool_model.MirrorZAxis(mirrorZAxis);

                // Set scaling.
                tool_model.transform.localScale = transform.lossyScale;

                tool_model.UpdateTool();
            }
        }

        // Destroy all tools with defunct IDs.
        for (int i = 0; i < ids_to_check.Count; ++i)
        {
            Destroy(all_tools[ids_to_check[i]].gameObject);
            all_tools.Remove(ids_to_check[i]);
        }
    }