Example #1
0
        private IEnumerator CreateCacheRunnerForward()
        {
            while (true)
            {
                progress = 0 + (mCreateIndexForward * 1.0f / mCreateAllFiles.Count * 1.0f / 2f);

                if (mCreateIndexForward < mCreateAllFiles.Count)
                {
                    string file       = mCreateAllFiles[mCreateIndexForward++];
                    string assetsPath = "Assets" + Path.GetFullPath(file).Replace(Path.GetFullPath(Application.dataPath), "").Replace('\\', '/');
                    string guid       = AssetDatabase.AssetPathToGUID(assetsPath);

                    //正向存储
                    if (referencesForward.ContainsKey(guid) == false)
                    {
                        referencesForward.Add(guid, new List <string>());
                        string[] dependencies = AssetDatabase.GetDependencies(assetsPath);
                        if (dependencies != null && dependencies.Length > 0)
                        {
                            foreach (var dependencie in dependencies)
                            {
                                string dependencieGUID = AssetDatabase.AssetPathToGUID(dependencie);
                                if (referencesForward[guid].Contains(dependencieGUID) == false && dependencieGUID != guid)
                                {
                                    referencesForward[guid].Add(dependencieGUID);
                                }
                            }
                        }
                    }

                    //逆向存储
                    if (referencesReverse.ContainsKey(guid) == false)
                    {
                        referencesReverse.Add(guid, new List <string>());
                    }

                    yield return(0);
                }
                else
                {
                    break;
                }
            }

            mCreateCompleteForward++;
            if (mCreateCompleteForward == coroutineCount)
            {
                List <string> forwardKeys = new List <string>();
                foreach (var refForward in referencesForward)
                {
                    forwardKeys.Add(refForward.Key);
                }
                for (int i = 0; i < coroutineCount; i++)
                {
                    EditorCoroutineRunner.StartEditorCoroutine(CreateCacheRunnerReverse(forwardKeys));
                }
            }
        }
Example #2
0
        private bool CreateCache()
        {
            if (mCreateAllFiles != null)
            {
                return(false);
            }

            mCreateAllFiles        = new List <string>(Directory.GetFiles(Application.dataPath, "*.*", SearchOption.AllDirectories));
            mCreateIndexForward    = 0;
            mCreateCompleteForward = 0;
            mCreateIndexReverse    = 0;
            mCreateCompleteReverse = 0;

            for (int i = 0; i < coroutineCount; i++)
            {
                EditorCoroutineRunner.StartEditorCoroutine(CreateCacheRunnerForward());
            }

            return(true);
        }