Exemple #1
0
        private static IEnumerable <DataNode> DataNodes(FolderHolder folderHolder)
        {
            foreach (var dataNodePair in folderHolder.DataNodes)
            {
                yield return(dataNodePair.Value);
            }

            foreach (var folderHolderPair in folderHolder.FolderHolders)
            {
                foreach (var dataNode in DataNodes(folderHolderPair.Value))
                {
                    yield return(dataNode);
                }
            }
        }
Exemple #2
0
        public static async Task InitAsync(Action <float>?onProgress, Action?onComplete)
        {
            var loadHandler = Addressables.LoadResourceLocationsAsync(SODatabaseSettings.Label);

#pragma warning disable 4014
            Task.Run(async() =>
            {
                while (!loadHandler.IsDone)
                {
                    CallAction(() => { onProgress?.Invoke(loadHandler.PercentComplete); });
                    await Task.Delay(50);
                }

                CallAction(() => { onProgress?.Invoke(loadHandler.PercentComplete); });
            });
#pragma warning restore 4014
            var resourceLocations = await loadHandler.Task;

            var loadTasks = resourceLocations.ToDictionary(resourceLocation => resourceLocation.PrimaryKey.Substring(SODatabaseSettings.Path.Length), resourceLocation => Addressables.LoadAssetAsync <DataNode>(resourceLocation).Task);
            await Task.WhenAll(loadTasks.Values);

            root = new FolderHolder();
            foreach (var loadTask in loadTasks)
            {
                //SODatabase/Example1Folder/Example1.asset
                var pathElements = loadTask.Key.Split('/');
                var curFolder    = root;
                for (var i = 0; i < pathElements.Length - 1; i++)
                {
                    if (!curFolder.FolderHolders.ContainsKey(pathElements[i]))
                    {
                        curFolder.FolderHolders.Add(pathElements[i], new FolderHolder());
                    }

                    curFolder = curFolder.FolderHolders[pathElements[i]];
                }

                var dataNodeName = pathElements[pathElements.Length - 1];
                dataNodeName = dataNodeName.Substring(0, dataNodeName.IndexOf(".asset", StringComparison.Ordinal));
                curFolder.DataNodes.Add(dataNodeName, loadTask.Value.Result);
            }

            CallAction(onComplete);
        }