public override void SelectItem(System.Guid itemGuid)
    {
        if (TreeView == null)
        {
            return;
        }

        if (TreeView.m_storedSearchString != string.Empty)
        {
            return;
        }

        if (!TreeView.ExpandItem(itemGuid, true))
        {
            var item = Find(itemGuid);
            treeviewCommandQueue.Enqueue(new TreeViewCommand(() => Expand(itemGuid, true)));

            if (item == null)
            {
                AkWaapiUtilities.GetResultListDelegate <WwiseObjectInfoJsonObject> callback = (List <WwiseObjectInfoJsonObject> items) =>
                {
                    AddItemWithAncestors(AkWaapiUtilities.ParseObjectInfo(items));
                };
                AkWaapiUtilities.GetWwiseObjectAndAncestors(itemGuid, waapiWwiseObjectOptions, callback);
            }
        }
    }
    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();
    }
    public override void FetchData()
    {
        Data.Clear();
        m_MaxID     = 0;
        ProjectRoot = CreateProjectRootItem();

        foreach (var type in FolderNames.Keys)
        {
            AkWaapiUtilities.GetResultListDelegate <WwiseObjectInfoJsonObject> callback = (List <WwiseObjectInfoJsonObject> items) =>
            {
                AddBaseFolder(AkWaapiUtilities.ParseObjectInfo(items), type);
            };
            AkWaapiUtilities.GetWwiseObjectAndDescendants(FolderNames[type], waapiWwiseObjectOptions, 2, callback);
        }
        Changed();
    }
    private void FireSearch(object sender, System.Timers.ElapsedEventArgs e)
    {
        if (SearchRoot == null)
        {
            SearchRoot = new AkWwiseTreeViewItem(ProjectRoot);
        }

        SearchRoot.children.Clear();
        SearchItems = new List <AkWwiseTreeViewItem>(new[] { SearchRoot });
        TreeUtility.TreeToList(SearchRoot, SearchItems);
        AkWaapiUtilities.GetResultListDelegate <WwiseObjectInfoJsonObject> callback = (List <WwiseObjectInfoJsonObject> items) =>
        {
            AddSearchResults(AkWaapiUtilities.ParseObjectInfo(items));
        };
        AkWaapiUtilities.Search(searchString, searchObjectTypeFilter, waapiWwiseObjectOptions, callback);
    }
 public void LoadComponentDataDelayed()
 {
     //Delay call until data has been fetched
     if (!wwiseObjectFolders.ContainsKey(componentObjectType))
     {
         UnityEditor.EditorApplication.delayCall += LoadComponentDataDelayed;
     }
     else
     {
         AkWaapiUtilities.GetResultListDelegate <WwiseObjectInfoJsonObject> callback = (List <WwiseObjectInfoJsonObject> items) =>
         {
             AddItems(AkWaapiUtilities.ParseObjectInfo(items));
         };
         AkWaapiUtilities.GetWwiseObjectAndDescendants(wwiseObjectFolders[componentObjectType].objectGuid,
                                                       waapiWwiseObjectOptions, -1, callback);
     }
 }
    public void AddSearchResults(IEnumerable <WwiseObjectInfo> matchList)
    {
        try
        {
            foreach (var info in matchList)
            {
                if (!FilterPath(info.path))
                {
                    continue;
                }

                var match = Find(SearchItems, info.objectGUID);
                if (match != null)
                {
                    continue;
                }

                var matchItem = Find(info.objectGUID);
                if (matchItem == null)
                {
                    AkWaapiUtilities.GetResultListDelegate <WwiseObjectInfoJsonObject> callback = (List <WwiseObjectInfoJsonObject> items) =>
                    {
                        AddItemWithAncestorsToSearch(AkWaapiUtilities.ParseObjectInfo(items));
                    };
                    AkWaapiUtilities.GetWwiseObjectAndAncestors(info.objectGUID, waapiWwiseObjectOptions, callback);
                    continue;
                }

                AddItemToSearch(matchItem);
                treeviewCommandQueue.Enqueue(new TreeViewCommand(() => Expand(matchItem.objectGuid, false)));
            }
        }
        catch (System.Exception e)
        {
            UnityEngine.Debug.LogError("Search died");
            UnityEngine.Debug.LogError(e.Message);
        }
    }