void Preload(AkWwiseTreeViewItem parent, TreeViewState treeState)
    {
        if (parent == null)
        {
            return;
        }

        if (!CheckIfFullyLoaded(parent))
        {
            AkWaapiUtilities.GetResultListDelegate <WwiseObjectInfoJsonObject> callback = (List <WwiseObjectInfoJsonObject> items) =>
            {
                UpdateParentWithLoadedChildren(parent.objectGuid, AkWaapiUtilities.ParseObjectInfo(items));
            };
            AkWaapiUtilities.GetChildren(parent.objectGuid, waapiWwiseObjectOptions, callback);
        }

        //Preload one level of hidden items.
        if (IsExpanded(treeState, parent.id) || (parent.parent != null && IsExpanded(treeState, parent.parent.id)) ||
            parent.id == ProjectRoot.id)
        {
            foreach (AkWwiseTreeViewItem childItem in parent.children)
            {
                Preload(childItem, treeState);
            }
        }
    }
    public void AddItemWithAncestors(List <WwiseObjectInfo> infoItems, bool selectAfterCreated = false)
    {
        var parent = ProjectRoot;

        //Items obtained from the WAAPI call are sorted by path so we can simply iterate over them
        foreach (var infoItem in infoItems)
        {
            var newItem = Find(infoItem.objectGUID);
            if (newItem == null)
            {
                newItem = new AkWwiseTreeViewItem(infoItem, GenerateUniqueID(), parent.depth + 1);
                Data.Add(newItem);
                parent.AddWwiseItemChild(newItem);
            }

            if (!CheckIfFullyLoaded(parent))
            {
                System.Guid guid = new System.Guid(parent.objectGuid.ToString());
                AkWaapiUtilities.GetResultListDelegate <WwiseObjectInfoJsonObject> callback = (List <WwiseObjectInfoJsonObject> items) =>
                {
                    UpdateParentWithLoadedChildren(guid, AkWaapiUtilities.ParseObjectInfo(items));
                };
                AkWaapiUtilities.GetChildren(parent.objectGuid, waapiWwiseObjectOptions, callback);
            }
            parent = newItem;
        }

        if (selectAfterCreated)
        {
            treeviewCommandQueue.Enqueue(new TreeViewCommand(() => Expand(parent.objectGuid, true)));
        }
    }
    void OnWaapiChildAdded(string json)
    {
        var added = AkWaapiUtilities.ParseChildAddedOrRemoved(json);

        if (added.childInfo.type == WwiseObjectType.None)
        {
            return;
        }

        var parent = Find(added.parentInfo.objectGUID);

        // New object created, but parent is not loaded yet, so we can ignore it
        if (parent == null)
        {
            return;
        }

        var child = Find(added.childInfo.objectGUID);

        if (child == null)
        {
            child = new AkWwiseTreeViewItem(added.childInfo, GenerateUniqueID(), parent.depth + 1);
        }
        else
        {
            child.numChildren = added.childInfo.childrenCount;
            child.displayName = added.childInfo.name;
        }

        parent.AddWwiseItemChild(child);
        Data.Add(child);
        parent.numChildren = added.parentInfo.childrenCount;
        child.depth        = parent.depth + 1;

        if (!CheckIfFullyLoaded(parent))
        {
            AkWaapiUtilities.GetResultListDelegate <WwiseObjectInfoJsonObject> callback = (List <WwiseObjectInfoJsonObject> items) =>
            {
                UpdateParentWithLoadedChildren(parent.objectGuid, AkWaapiUtilities.ParseObjectInfo(items));
            };
            AkWaapiUtilities.GetChildren(parent.objectGuid, waapiWwiseObjectOptions, callback);
        }

        if (!CheckIfFullyLoaded(child))
        {
            AkWaapiUtilities.GetResultListDelegate <WwiseObjectInfoJsonObject> callback = (List <WwiseObjectInfoJsonObject> items) =>
            {
                UpdateParentWithLoadedChildren(child.objectGuid, AkWaapiUtilities.ParseObjectInfo(items));
            };
            AkWaapiUtilities.GetChildren(child.objectGuid, waapiWwiseObjectOptions, callback);
        }
        ScheduleRebuild();
    }