public void LoadConfig(string filename, Action <string, object, object[]> callback, params object[] args)
        {
            if (callback == null)
            {
                return;
            }

            #if UNITY_EDITOR
            if (AssetManagerSetting.EditorSimulateConfig)
            {
                TextAsset textAsset = UnityEditor.AssetDatabase.LoadAssetAtPath <TextAsset>(AssetManagerSetting.EditorGetConfigPath(filename));
                if (textAsset != null)
                {
                    callback(filename, textAsset.text, args);
                }
                else
                {
                    callback(filename, null, args);
                }
            }
            else
            #endif
            {
                TextAsset textAsset = (TextAsset)configAssetBundle.LoadAsset(AssetManagerSetting.GetConfigAssetName(filename));
                if (textAsset != null)
                {
                    callback(filename, textAsset.text, args);
                }
                else
                {
                    callback(filename, null, args);
                }
            }
        }
        public static void GeneratorUpdateList(Version appVer)
        {
            string path = AssetManagerSetting.EditorUpdateAssetListPath;

            Debug.Log(path);
            PathUtil.CheckPath(path);


            if (appVer == null)
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                File.Copy(AssetManagerSetting.EditorFileCsvForStreaming, path);
                return;
            }
            Debug.Log(appVer);
            AssetFileList app  = AssetFileList.Read(AssetManagerSetting.EditorGetVersionFileListPath(appVer.ToString()));
            AssetFileList curr = AssetFileList.Read(AssetManagerSetting.EditorFileCsvForStreaming);

            AssetFileList diff = AssetFileList.DiffAssetFileList(app, curr);

            diff.Save(path);
        }
        public static void CopyStreamFilesCsvToVersion(Version version)
        {
            string path = AssetManagerSetting.EditorGetVersionFileListPath(version.ToString());

            PathUtil.CheckPath(path);
            File.Copy(AssetManagerSetting.EditorFileCsvForStreaming, path);
        }
Ejemplo n.º 4
0
        public static AssetBundleInfoList GeneratorAssetBundleInfo()
        {
            AssetBundleInfoList infoList = new AssetBundleInfoList();

            List <string> list = new List <string>();

            PathUtil.RecursiveFile(resourceRoot, list, exts);

            for (int i = 0; i < list.Count; i++)
            {
                string        path     = list[i];
                AssetImporter importer = AssetImporter.GetAtPath(path);

                if (string.IsNullOrEmpty(importer.assetBundleName))
                {
                    Debug.LogWarningFormat("MResource资源没有设置AssetBundleName  path={0}", path);
                    continue;
                }

                AssetBundleInfo item = new AssetBundleInfo();
                item.path            = path;
                item.assetBundleName = importer.assetBundleName;
                item.assetName       = PathUtil.ChangeExtension(Path.GetFileName(path), string.Empty);



                string ext = Path.GetExtension(path).ToLower();
                if (ext == ".prefab")
                {
                    item.objType = AssetManagerSetting.ObjType_GameObject;
                }
                else if (imageExts.IndexOf(ext) != -1)
                {
                    TextureImporter textureImporter = TextureImporter.GetAtPath(path) as TextureImporter;
                    if (textureImporter.textureType == TextureImporterType.Sprite)
                    {
                        item.objType = AssetManagerSetting.ObjType_Sprite;
                    }
                }


                infoList.Add(item);
            }

            EditorUtility.ClearProgressBar();
            infoList.Save(AssetManagerSetting.EditorGetAbsoluteStreamPath(AssetManagerSetting.AssetBundleListName));
            AssetDatabase.Refresh();

            return(infoList);
        }
Ejemplo n.º 5
0
        //path;md5;objType;assetName;assetBundleName
        private void ParseInfoStreaming(string p)
        {
            string path, objType, assetName, assetBundleName;
            string filename;

            using (StringReader stringReader = new StringReader(p))
            {
                while (stringReader.Peek() >= 0)
                {
                    string line = stringReader.ReadLine();
                    if (!string.IsNullOrEmpty(line))
                    {
                        string[] seg    = line.Split(';');
                        int      length = seg.Length;
                        path            = seg[0];
                        objType         = length > 2 ? seg[2] : string.Empty;
                        assetBundleName = length > 3 ? seg[3] : string.Empty;
                        assetName       = length > 4 ? seg[4] : string.Empty;


                        filename = path.Replace(AssetManagerSetting.AssetbundleExt, string.Empty);
                        filename = filename.Replace("{0}/", "").ToLower();

                        path = AssetManagerSetting.GetPlatformPath(path);


                        AssetInfo assetInfo;
                        if (!assetInfoDict.TryGetValue(filename, out assetInfo))
                        {
                            assetInfo      = new AssetInfo();
                            assetInfo.name = filename;
                            assetInfoDict.Add(filename, assetInfo);
                        }

                        assetInfo.path     = path;
                        assetInfo.loadType = AssetLoadType.AssetBundle;
                        assetInfo.objType  = AssetManagerSetting.GetObjType(objType);

                        assetInfo.assetName       = assetName;
                        assetInfo.assetBundleName = assetBundleName;

                        assetInfo.isConfig = AssetManagerSetting.IsConfigFile(filename);
                    }
                }
            }
        }
        public static void CopyUpdateAsset(string serverRoot)
        {
            PathUtil.CheckPath(serverRoot, false);
            string updateAssetListPath = null;

            if (File.Exists(AssetManagerSetting.EditorUpdateAssetListPath))
            {
                updateAssetListPath = AssetManagerSetting.EditorUpdateAssetListPath;
            }
            else if (File.Exists(AssetManagerSetting.EditorFileCsvForStreaming))
            {
                updateAssetListPath = AssetManagerSetting.EditorFileCsvForStreaming;
            }

            if (!string.IsNullOrEmpty(updateAssetListPath))
            {
                AssetFileList assetFileList = AssetFileList.Read(updateAssetListPath);
                assetFileList.Add(new AssetFile("{0}/" + AssetManagerSetting.UpdateAssetListName, ""));

                int count = assetFileList.list.Count;
                for (int i = 0; i < count; i++)
                {
                    AssetFile item     = assetFileList.list[i];
                    string    path     = AssetManagerSetting.GetPlatformPath(item.path);
                    string    fromPath = AssetManagerSetting.EditorRootStream + "/" + path;
                    string    toPath   = serverRoot + "/" + path;

                    PathUtil.CheckPath(toPath);
                    File.Copy(fromPath, toPath, true);

                    if (i % 10 == 0)
                    {
                        UnityEditor.EditorUtility.DisplayProgressBar("拷贝目录", path, 1f * i / count);
                    }
                }
            }
            else
            {
                CopyAlleAsset(serverRoot);
            }

            UnityEditor.EditorUtility.ClearProgressBar();
        }
Ejemplo n.º 7
0
        // path;objType
        private void ParseInfoResources(string p)
        {
            string path, objType;
            string filename;


            using (StringReader stringReader = new StringReader(p))
            {
                while (stringReader.Peek() >= 0)
                {
                    string line = stringReader.ReadLine();

                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }


                    string[] seg = line.Split(';');
                    path    = seg[0];
                    objType = seg.Length > 1 ? seg[1] : string.Empty;

                    filename = path;
                    filename = filename.ToLower();



                    AssetInfo assetInfo;
                    if (!assetInfoDict.TryGetValue(filename, out assetInfo))
                    {
                        assetInfo      = new AssetInfo();
                        assetInfo.name = filename;
                        assetInfoDict.Add(filename, assetInfo);
                    }

                    assetInfo.path     = path;
                    assetInfo.loadType = AssetLoadType.Resources;
                    assetInfo.objType  = AssetManagerSetting.GetObjType(objType);

                    assetInfo.isConfig = AssetManagerSetting.IsConfigFile(filename);
                }
            }
        }
Ejemplo n.º 8
0
        /** 获取服务器版本号 */
        IEnumerator ReadServerVersionInfo()
        {
            string url = AssetManagerSetting.GetServerVersionInfoURL(GameConst.WebUrl);
            WWW    www = new WWW(url);

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.LogErrorFormat("获取服务器版本号出错 url={0}, www.error={1}", url, www.error);
                www.Dispose();
                www = null;

                yield break;
            }

            Debug.Log(www.text);

            serverVersionInfo = JsonUtility.FromJson <VersionInfo>(www.text);
        }
Ejemplo n.º 9
0
        /** 检测是否已经创建了WWW,没有就创建WWW */
        protected bool LoadAssetBundleInternal(string assetBundleName, bool isLoadingAssetBundleManifest)
        {
            // Already loaded.
            LoadedAssetBundle bundle = null;

            m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
            if (bundle != null)
            {
                bundle.m_ReferencedCount++;
                return(true);
            }

            // @TODO: Do we need to consider the referenced count of WWWs?
            // In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync().
            // But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs.
            if (m_DownloadingWWWs.ContainsKey(assetBundleName))
            {
                return(true);
            }

            WWW    download = null;
            string url      = AssetManagerSetting.GetAbsoluteAssetBundleURL(assetBundleName);

            // For manifest assetbundle, always download it as we don't have hash for it.
            if (isLoadingAssetBundleManifest)
            {
                download = new WWW(url);
            }
            else
            {
                download = WWW.LoadFromCacheOrDownload(url, assetBundleManifest.GetAssetBundleHash(assetBundleName), 0);
            }

            m_DownloadingWWWs.Add(assetBundleName, download);

            return(false);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="filename">文件名.</param>
        /// <param name="callback">回调函数(文件名, 资源, 回调参数).</param>
        /// <param name="arg">回调参数.</param>
        /// <param name="type">资源类型.</param>
        public void Load(string filename, Action <string, object, object[]> callback, object[] callbackArgs, Type type)
        {
            if (AssetManagerSetting.IsConfigFile(filename))
            {
                LoadConfig(filename, callback, callbackArgs);
                return;
            }


            string    filenameLower = filename.ToLower();
            AssetInfo fileInfo;

            if (!assetInfoDict.TryGetValue(filenameLower, out fileInfo))
            {
//                Debug.LogError("[AssetMananger]资源配置不存在或者加载出错 name="+filenameLower + "   assetInfo=" + fileInfo );
                if (callback != null && fileInfo == null)
                {
                    LoadResourceAsync(filename, type, callback, callbackArgs);
                }
                return;
            }

            if (fileInfo.objType != null && (type == null || type == tmpObjType))
            {
                type = fileInfo.objType;
            }


            if (fileInfo.loadType == AssetLoadType.AssetBundle)
            {
                LoadAssetAsync(fileInfo.assetBundleName, fileInfo.assetName, type, callback, callbackArgs);
            }
            else
            {
                LoadResourceAsync(fileInfo.path, type, callback, callbackArgs);
            }
        }
Ejemplo n.º 11
0
        IEnumerator UpdateResource(string rootUrl)
        {
            // rootUrl = "http://www.ihaiu.com/StreamingAssets/"
            OnUpdateEnter();

            //获取服务器端的file.csv

            OnState("获取服务器端的file.csv");
            string updateAssetListUrl = AssetManagerSetting.GetServerFilesCsvURL(rootUrl);

            Debug.Log("UpdateAssetList URL: " + updateAssetListUrl);
            WWW www = new WWW(updateAssetListUrl);

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.LogErrorFormat("更新资源读取资源列表失败 updateAssetListUrl={0}, www.error={1}", updateAssetListUrl, www.error);
                www.Dispose();
                www = null;
                yield break;
            }

            AssetFileList updateAssetList = AssetFileList.Deserialize(www.text);

            www.Dispose();
            www = null;
            //Debug.Log("count: " + files.Length + " text: " + filesText);


            OnState("读取" + AssetManagerSetting.AssetFileListPath);
            if (assetList == null)
            {
                assetList = AssetFileList.Read(AssetManagerSetting.AssetFileListPath);
            }

            List <AssetFile> diffs = AssetFileList.Diff(assetList, updateAssetList);


            string path;
            //更新
            int count = diffs.Count;

            for (int i = 0; i < count; i++)
            {
                AssetFile item = diffs[i];
                path = AssetManagerSetting.GetPlatformPath(item.path);

                OnState("更新" + path);
                OnUpdateProgress((float)(i + 1) / (float)count);

                string url = rootUrl + path;
                www = new WWW(url);

                yield return(www);

                if (!string.IsNullOrEmpty(www.error))
                {
                    OnUpdateFailed(url);

                    www.Dispose();
                    www = null;
                    continue;
                }

                string localPath = AssetManagerSetting.RootPathPersistent + path;
                PathUtil.CheckPath(localPath, true);
                File.WriteAllBytes(localPath, www.bytes);

                www.Dispose();
                www = null;

                assetList.Add(item);

                AssetManagerSetting.persistentAssetFileList.Add(path, item.md5);
            }
            yield return(new WaitForEndOfFrame());


            assetList.Save(AssetManagerSetting.AssetFileListPath);
            AssetManagerSetting.persistentAssetFileList.Save(AssetManagerSetting.PersistentAssetFileListPath);


            // 更新完成
            OnUpdateEnd();
        }
Ejemplo n.º 12
0
        public static void Lua()
        {
            string luaRoot   = AssetManagerSetting.EditorRootLua;
            string bytesRoot = AssetManagerSetting.EditorRootLuaBytes;

            if (!Directory.Exists(luaRoot))
            {
                Debug.Log("目录不存在" + luaRoot);
                return;
            }

            List <string> luaList = new List <string>();

            RecursiveLua(luaRoot, luaList);



            if (Directory.Exists(bytesRoot))
            {
                PathUtil.DeleteDirectory(bytesRoot);
            }
            Directory.CreateDirectory(bytesRoot);

            for (int i = 0; i < luaList.Count; i++)
            {
                string ext = Path.GetExtension(luaList[i]);
                if (ext.Equals(".lua"))
                {
                    string sourcePath = luaList[i];
                    string destPath   = PathUtil.ChangeExtension(sourcePath.Replace(luaRoot, bytesRoot), AssetManagerSetting.BytesExt);

                    PathUtil.CheckPath(destPath, true);
                    File.Copy(sourcePath, destPath, true);
                }
            }


            AssetDatabase.Refresh();

            List <string> luaBytesList = new List <string>();

            RecursiveLuaBytes(bytesRoot, luaBytesList);

            string assetBundleName = AssetManagerSetting.LuaAssetBundleName;

            AssetBundleBuild[] builds = new AssetBundleBuild[1];
            builds[0].assetBundleName = assetBundleName;
            builds[0].assetNames      = luaBytesList.ToArray();
            Debug.Log("luaBytesList.Count=" + luaBytesList.Count);

            string outPath = bytesRoot;

            PathUtil.CheckPath(outPath, false);
            BuildPipeline.BuildAssetBundles(outPath, builds, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
            AssetDatabase.Refresh();

            string inAssetBundlePath = bytesRoot + "/" + assetBundleName;
            string outBytesPath      = AssetManagerSetting.EditorGetAbsolutePlatformPath(assetBundleName);

            byte[] bytes = File.ReadAllBytes(inAssetBundlePath);

            bytes = EncryptBytes(bytes, SKey);

            PathUtil.CheckPath(outBytesPath, true);
            File.WriteAllBytes(outBytesPath, bytes);

            AssetDatabase.Refresh();

            if (Directory.Exists(bytesRoot))
            {
                PathUtil.DeleteDirectory(bytesRoot);
            }
        }