IEnumerator InitSetting() { var assetLoader = CStaticAssetLoader.Load("GameSetting" + CCosmosEngine.GetConfig("AssetBundleExt"), null); while (!assetLoader.IsFinished) { yield return(null); } CGameSettingFiles gameSetting = (CGameSettingFiles)assetLoader.TheAsset; for (int i = 0; i < gameSetting.SettingFiles.Length; ++i) { GameSettings.Add(gameSetting.SettingFiles[i], gameSetting.SettingContents[i]); } CDebug.Log("{0} setting files loaded.", GameSettings.Count); Object.Destroy(gameSetting); assetLoader.Release(); LoadFinished = true; }
public CUILoadState LoadWindow(string name, bool openWhenFinish, params object[] args) { if (UIWindows.ContainsKey(name)) { CBase.LogError("[LoadWindow]多次重复LoadWindow: {0}", name); } CBase.Assert(!UIWindows.ContainsKey(name)); string path = string.Format("UI/{0}_UI{1}", name, CCosmosEngine.GetConfig("AssetBundleExt")); CUILoadState openState = new CUILoadState(name); openState.IsStaticUI = true; openState.OpenArgs = args; openState.OpenWhenFinish = openWhenFinish; CResourceManager.Instance.StartCoroutine(LoadUIAssetBundle(path, name, openState)); UIWindows.Add(name, openState); return(openState); }
private void DoLoadTab <T>(string tabPath) where T : CBaseInfo { #if GAME_CLIENT //using (CTabReader tabFile = CTabReader.LoadFromString(tabPath, CSettingManager.Instance.LoadSetting(tabPath))) using (CTabFile tabFile = CTabFile.LoadFromString(CSettingManager.Instance.LoadSetting(tabPath))) #else // Editor Only string p1 = System.IO.Path.GetFullPath("Assets/" + CCosmosEngine.GetConfig("ProductRelPath") + "/") + tabPath; using (CTabFile tabFile = CTabFile.LoadFromString(System.IO.File.ReadAllText(p1))) #endif { int rowStart = 1; Dictionary <string, CBaseInfo> dict = new Dictionary <string, CBaseInfo>(); for (int i = rowStart; i < tabFile.GetHeight(); i++) { // 先读取ID, 获取是否之前已经读取过配置, // 如果已经读取过,那么获取原配置对象,并重新赋值 (因为游戏中其它地方已经存在它的引用了,直接替换内存泄露) string id = tabFile.GetString(i, "Id"); // 获取ID是否存在, 如果已经存在,那么替换其属性,不new一个 CBaseInfo existOne; if (dict.TryGetValue(id, out existOne)) { CBaseInfo existT = existOne; CBaseInfo.LoadFromTab(typeof(T), ref existT, tabFile, i); // 修改原对象,不new (existT as CBaseInfo).Parse(); } else { T pInfo = CBaseInfo.LoadFromTab(typeof(T), tabFile, i) as T; pInfo.Parse(); dict[pInfo.Id] = pInfo; // 不存在,直接new } } SettingInfos[typeof(T)] = dict; } }
static void ParseArgs(ref BuildOptions opt, ref string outputpath) { string[] args = System.Environment.GetCommandLineArgs(); string productPath = Path.Combine(Application.dataPath, CCosmosEngine.GetConfig("ProductRelPath")); if (!Directory.Exists(productPath)) { Directory.CreateDirectory(productPath); } if (args.Length >= 2) { CommandArgs commandArg = CommandLine.Parse(args); //List<string> lparams = commandArg.Params; Dictionary <string, string> argPairs = commandArg.ArgPairs; foreach (KeyValuePair <string, string> item in argPairs) { switch (item.Key) { case "BundleVersion": PlayerSettings.bundleVersion = item.Value; break; case "AndroidVersionCode": PlayerSettings.Android.bundleVersionCode = System.Int32.Parse(item.Value); break; case "AndroidKeyStoreName": PlayerSettings.Android.keystoreName = item.Value; break; case "AndroidKeyStorePass": PlayerSettings.Android.keystorePass = item.Value; break; case "AndroidkeyAliasName": PlayerSettings.Android.keyaliasName = item.Value; break; case "AndroidKeyAliasPass": PlayerSettings.Android.keyaliasPass = item.Value; break; case "BuildOptions": { opt = BuildOptions.None; string[] opts = item.Value.Split('|'); foreach (string o in opts) { opt = opt | (BuildOptions)System.Enum.Parse(typeof(BuildOptions), o); } } break; case "Outputpath": outputpath = item.Value; break; } UnityEngine.Debug.Log(item.Key + " : " + item.Value); } } }
/// <summary> /// return full path or build /// </summary> /// <param name="outputpath"></param> /// <param name="tag"></param> /// <param name="opt"></param> /// <returns></returns> static string PerformBuild(string outputpath, BuildTarget tag, BuildOptions opt) { EditorUserBuildSettings.SwitchActiveBuildTarget(tag); ParseArgs(ref opt, ref outputpath); string fullPath = System.IO.Path.Combine(Application.dataPath, System.IO.Path.Combine(CCosmosEngine.GetConfig("ProductRelPath"), outputpath)); string fullDir = System.IO.Path.GetDirectoryName(fullPath); if (!Directory.Exists(fullDir)) { Directory.CreateDirectory(fullDir); } CDebug.Log("Build Client {0} to: {1}", tag, fullPath); BuildPipeline.BuildPlayer(GetScenePaths(), fullPath, tag, opt); return(fullPath); }
/// <summary> /// Initialize the path of AssetBundles store place ( Maybe in PersitentDataPath or StreamingAssetsPath ) /// </summary> /// <returns></returns> public static void InitResourcePath() { string productPath = Path.Combine(Application.dataPath, CCosmosEngine.GetConfig("ProductRelPath")); string assetBundlePath = Path.Combine(Application.dataPath, CCosmosEngine.GetConfig("AssetBundleRelPath")); string resourceDirName = Path.GetFileName(CCosmosEngine.GetConfig("AssetBundleRelPath")); BuildPlatformName = GetBuildPlatformName(); string fileProtocol = GetFileProtocol(); DocumentResourcesPathWithOutFileStart = string.Format("{0}/{1}/{2}/", GetAppDataPath(), resourceDirName, GetBuildPlatformName()); // 各平台通用 DocumentResourcesPath = fileProtocol + DocumentResourcesPathWithOutFileStart; switch (Application.platform) { case RuntimePlatform.WindowsEditor: case RuntimePlatform.OSXEditor: { ApplicationPath = string.Format("{0}{1}/", fileProtocol, productPath); ResourcesPath = fileProtocol + assetBundlePath + "/" + BuildPlatformName + "/"; ResourcesPathWithOutFileProtocol = assetBundlePath + "/" + BuildPlatformName + "/"; } break; case RuntimePlatform.WindowsPlayer: case RuntimePlatform.OSXPlayer: { string path = Application.dataPath.Replace('\\', '/'); path = path.Substring(0, path.LastIndexOf('/') + 1); ApplicationPath = string.Format("{0}{1}/", fileProtocol, path); ResourcesPath = string.Format("{0}{1}{2}/{3}", fileProtocol, path, resourceDirName, GetBuildPlatformName()); ResourcesPathWithOutFileProtocol = string.Format("{0}{1}/{2}/", path, resourceDirName, GetBuildPlatformName()); } break; case RuntimePlatform.Android: { ApplicationPath = string.Concat("jar:", fileProtocol, Application.dataPath, "!/assets/"); ResourcesPath = string.Concat(ApplicationPath, GetBuildPlatformName(), "/"); ResourcesPathWithOutFileProtocol = string.Concat(Application.dataPath, "!/assets/", GetBuildPlatformName() + "/"); // 注意,StramingAsset在Android平台中,是在壓縮的apk里,不做文件檢查 } break; case RuntimePlatform.IPhonePlayer: { ApplicationPath = System.Uri.EscapeUriString(fileProtocol + Application.streamingAssetsPath + "/"); // MacOSX下,带空格的文件夹,空格字符需要转义成%20 ResourcesPath = string.Format("{0}{1}/", ApplicationPath, GetBuildPlatformName()); // only iPhone need to Escape the f*****g Url!!! other platform works without it!!! Keng Die! ResourcesPathWithOutFileProtocol = Application.streamingAssetsPath + "/" + GetBuildPlatformName() + "/"; } break; default: { CBase.Assert(false); } break; } if (Debug.isDebugBuild) { CBase.Log("ResourceManager ApplicationPath: {0}", ApplicationPath); CBase.Log("ResourceManager ResourcesPath: {0}", ResourcesPath); CBase.Log("ResourceManager DocumentResourcesPath: {0}", DocumentResourcesPath); CBase.Log("================================================================================"); } }
IEnumerator _Init(string path, string assetName) { IsLoadAssetBundle = CCosmosEngine.GetConfig("IsLoadAssetBundle").ToInt32() != 0; AssetInBundleName = assetName; UnityEngine.Object getAsset = null; if (!IsLoadAssetBundle) { string extension = System.IO.Path.GetExtension(path); path = path.Substring(0, path.Length - extension.Length); // remove extensions getAsset = Resources.Load <UnityEngine.Object>(path); if (getAsset == null) { CDebug.LogError("Asset is NULL(from Resources Folder): {0}", path); } OnFinish(getAsset); } else { var bundleLoader = CAssetBundleLoader.Load(path); while (!bundleLoader.IsFinished) { if (IsReadyDisposed) // 中途释放 { bundleLoader.Release(); OnFinish(null); yield break; } Progress = bundleLoader.Progress; yield return(null); } var assetBundle = bundleLoader.Bundle; System.DateTime beginTime = System.DateTime.Now; if (AssetInBundleName == null) { // 经过AddWatch调试,.mainAsset这个getter第一次执行时特别久,要做序列化 //AssetBundleRequest request = assetBundle.LoadAsync("", typeof(Object));// mainAsset //while (!request.isDone) //{ // yield return null; //} try { CDebug.Assert(getAsset = assetBundle.mainAsset); } catch { CDebug.LogError("[OnAssetBundleLoaded:mainAsset]{0}", path); } } else { // TODO: 未测试过这几行!~~ AssetBundleRequest request = assetBundle.LoadAsync(AssetInBundleName, typeof(Object)); while (!request.isDone) { yield return(null); } getAsset = request.asset; } CResourceModule.LogLoadTime("AssetFileBridge", path, beginTime); if (getAsset == null) { CDebug.LogError("Asset is NULL: {0}", path); } bundleLoader.Release(); // 释放Bundle(WebStream) } if (Application.isEditor) { if (getAsset != null) { CResourceLoadObjectDebugger.Create(getAsset.GetType().Name, Url, getAsset as UnityEngine.Object); } } if (getAsset != null) { // 更名~ 注明来源asset bundle 带有类型 getAsset.name = string.Format("{0}~{1}", getAsset, Url); } OnFinish(getAsset); }
public static System.Func <string, string> CustomGetResourcesPath; // 自定义资源路径。。。 /// <summary> /// 统一在字符串后加上.box, 取决于配置的AssetBundle后缀 /// </summary> /// <param name="path"></param> /// <param name="formats"></param> /// <returns></returns> public static string GetAssetBundlePath(string path, params object[] formats) { return(string.Format(path + CCosmosEngine.GetConfig("AssetBundleExt"), formats)); }
public static string GetBuildRelPath(string uiName) { return(string.Format("UI/{0}_UI{1}", uiName, CCosmosEngine.GetConfig("AssetBundleExt"))); }
public bool BuildPkg(string file) { //if (!CBuildTools.CheckNeedBuild(file)) //{ // return false; //} AudioClip audioClip = AssetDatabase.LoadAssetAtPath(file, typeof(AudioClip)) as AudioClip; if (audioClip != null) { string subDirName = Path.GetFileName(Path.GetDirectoryName(file)); string exportFile = string.Format("Audio/{0}/{1}_Audio{2}", subDirName, Path.GetFileNameWithoutExtension(file), CCosmosEngine.GetConfig("AssetBundleExt")); CBuildTools.BuildAssetBundle(audioClip, exportFile); //CBuildTools.MarkBuildVersion(file); } return(true); }