Exemple #1
0
        public static List <Object> GetDirSubAssetsList(string dirAssetsPath, bool isRecursive = true, string suffix = "", bool isLoadAll = false)
        {
            string        dirABSPath        = ABSPath2AssetsPath(dirAssetsPath);
            List <string> assetsABSPathList = EditorFileUtils.GetDirSubFilePathList(dirABSPath, isRecursive, suffix);
            List <Object> resultObjectList  = new List <Object>();

            for (int i = 0; i < assetsABSPathList.Count; ++i)
            {
                if (isLoadAll)
                {
                    Object[] objs = AssetDatabase.LoadAllAssetsAtPath(ABSPath2AssetsPath(assetsABSPathList[i]));
                    resultObjectList.AddRange(objs);
                }
                else
                {
                    Object obj = AssetDatabase.LoadAssetAtPath <Object>(ABSPath2AssetsPath(assetsABSPathList[i]));
                    resultObjectList.Add(obj);
                }
            }

            return(resultObjectList);
        }
        private ABState VisitorFolder(string absPath, IFolderVisitor visitor)
        {
            if (visitor == null)
            {
                return(ABState.NONE);
            }

            ABState state = new ABState();

            var dirs = Directory.GetDirectories(absPath);

            if (dirs.Length > 0)
            {
                for (int i = 0; i < dirs.Length; ++i)
                {
                    ABState subState = VisitorFolder(dirs[i], visitor);

                    if (subState.hasMixed)
                    {
                        state.hasMixed = true;
                    }

                    if (subState.isLost)
                    {
                        state.isLost = true;
                    }
                }
            }

            var files = Directory.GetFiles(absPath);

            if (files.Length > 0)
            {
                for (int i = 0; i < files.Length; ++i)
                {
                    if (!AssetFileFilter.IsAsset(files[i]))
                    {
                        continue;
                    }

                    AssetImporter ai = AssetImporter.GetAtPath(EditorUtils.ABSPath2AssetsPath(files[i]));
                    if (ai != null)
                    {
                        if (!string.IsNullOrEmpty(ai.assetBundleName))
                        {
                            //Log.i("Files:" + files[i] + " ---> " + ai.assetBundleName);
                            string assetPath  = EditorFileUtils.RemoveFileExtend(ai.assetPath).ToLower();
                            string bundleName = EditorFileUtils.RemoveFileExtend(ai.assetBundleName);
                            if (assetPath.EndsWith(bundleName))
                            {
                                //Log.i("File Flag:" + assetPath);
                                state.flag |= ABStateDefine.FILE;
                                visitor.OnAssetVisitorResult(ai, ABStateDefine.FILE);
                            }
                            else
                            {
                                //Log.i("##Folder Flag:" + assetPath);
                                state.flag |= ABStateDefine.FOLDER;
                                visitor.OnAssetVisitorResult(ai, ABStateDefine.FOLDER);
                            }
                        }
                        else
                        {
                            state.isLost = true;
                            visitor.OnAssetVisitorResult(ai, ABStateDefine.LOST);
                        }
                    }
                }
            }

            if (state.isMixedFlag)
            {
                state.hasMixed = true;
            }
            visitor.OnFolderVisitorResult(absPath, state);
            return(state);
        }