/// <summary> /// 注册事件 /// </summary> /// <param name="notifyID"> 消息ID </param> /// <param name="action"> 回调函数callback </param> /// <param name="inQueue"> 是否是Update队列中执行 </param> public static void Regist(string notifyID, Action <object> action, bool inQueue) { var serchDict = inQueue ? _queueEventMap : _eventMap; List <Action <object> > findList = null; //引用 回调集合 if (serchDict.TryGetValue(notifyID, out findList)) // 已注册消息。判断是否有相同的回调 { //已有相同的回调 if (findList.Contains(action)) { MyDebug.LogErrorFormat("{0}已存在同样时间注册{1},本次注册取消", notifyID, action); } else { findList.Add(action); //添加该回调 } } else //该消息还没有注册过回调函数 { findList = new List <Action <object> >(); findList.Add(action); serchDict.Add(notifyID, findList); //添加对应事件 } }
public void Init() { if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) { _rootPath = Application.dataPath + "/../" + RootFolderName; _buildInPackageRoot = string.Format("file://{0}/{1}", Application.streamingAssetsPath, ResUtility.GetPlatformPath); } else if (Application.platform == RuntimePlatform.Android) { _rootPath = Application.persistentDataPath + "/" + RootFolderName; _buildInPackageRoot = string.Format("{0}/{1}", Application.streamingAssetsPath, ResUtility.GetPlatformPath); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { _rootPath = Application.persistentDataPath + "/" + RootFolderName; string.Format("{0}/{1}", Application.streamingAssetsPath, ResUtility.GetPlatformPath); } else { MyDebug.LogErrorFormat("_rootPath set error ! set to {0}!", Application.dataPath); _rootPath = Application.dataPath; } _assetPath = string.Format("{0}/{1}", _rootPath, FrameworkDefaultSetting.BinFolderName); _logFolderPath = string.Format("{0}/{1}", _assetPath, "log"); _curLogFilePath = string.Format("{0}/outLog_{1}.txt", _logFolderPath, DateTime.Now.ToString("yy_MM_dd_hh_mm_ss")); }
//"jar:file://" + IEnumerator GetLocalFilesInfos() { string resourceDataPath = string.Empty; if (Application.platform == RuntimePlatform.Android) { resourceDataPath = "jar:file://" + ResUtility.GetPlatformResourcesPath; WWW www = new WWW(resourceDataPath + "files.txt"); yield return(www); if (www.isDone) { if (www.error == null) { InitLoaclFilesInfo(true, www.text); } else { MyDebug.LogErrorFormat("GetLocalFilesInfos Is Called.But WWW.text Is Null. 【resourceDataPath】:{0}", resourceDataPath); yield break; } } } else { InitLoaclFilesInfo(false, resourceDataPath + "files.txt"); yield break; } }
public override void BeforeEnter(object p) { if (!Owner.ResMgr.Init()) { MyDebug.LogErrorFormat("ResourceManager.Init failed!"); return; } }
public void Release() { if (--references < 0) { MyDebug.LogErrorFormat("references < 0"); } MyDebug.LogErrorFormat("【Bundle】:{0},【Release】:{1}", name, references); }
protected override void OnLoad() { _request = WWW.LoadFromCacheOrDownload(path, version); if (_request == null) { error = path + "LoadFromCacheOrDownload is Failed"; MyDebug.LogErrorFormat("LoadFromCacheOrDownload is Failed. path:{0}", path); } }
protected override void OnLoad() { _request = AssetBundle.LoadFromFileAsync(path); if (_request == null) { error = path + "LoadFromFileAsync is falied. path"; MyDebug.LogErrorFormat("LoadFromFileAsync is falied. path:{0}", path); } }
protected virtual void OnLoad() { _assetBundle = AssetBundle.LoadFromFile(path); if (_assetBundle == null) { error = path + "LoadFromFile is falied. path"; MyDebug.LogErrorFormat("LoadFromFile failed . path: {0}", path); } }
public T GetItem(int index) { if (index >= _curIndex) { MyDebug.LogErrorFormat("ArrayIndexOutOfBoundsException index is {0} CurCount is {1}", index, _curIndex); return(default(T)); } return(_bufferArray[index]); }
/// <summary> /// 添加状态 /// </summary> /// <param name="state"></param> /// <returns></returns> public int Add(StateBase <T> state) { if (_states.ContainsKey(state.id)) { MyDebug.LogErrorFormat("alread contins state:" + state.id.ToString()); } else { _states.Add(state.id, state); } return(_states.Count); }
private static bool LoadEachPatterns() { bool isError = true; //在程序编译阶段,编译器会自动将using语句生成为try-finally语句,并在finally块中调用对象的Dispose方法,来清理资源。所以,using语句等效于try-finally语句 patterns.Clear(); var pkgPattern = AssetDatabase.LoadAssetAtPath <PackagePattern>(BuildDefaultPath.GetBuildPattrenAssetPath()); if (pkgPattern != null) { pkgPattern.MappingPackageData(); var data = pkgPattern.GetCacheAssetDataInfos(); var e = data.GetEnumerator(); while (e.MoveNext()) { if (e.Current.Value.assetFolderName != null) { if (e.Current.Value.BuildType == BuildType.None) { MyDebug.LogErrorFormat("LoadEachPatterns is Called,But BuildType == None! 【assetName】:{0}", e.Current.Value.assetFolderName); isError = false; continue; } var type = typeof(BaseBuild).Assembly.GetType("MyAssetBundleEditor." + Enum.GetName(typeof(BuildType), e.Current.Value.BuildType)); //反射得到对应对象 if (type != null) { //实例化 var pattern = Activator.CreateInstance(type) as BaseBuild; pattern.searchPath = e.Current.Value.searchPath; pattern.searchPattern = e.Current.Value.searchPattern; pattern.bundleName = e.Current.Value.bundleName; pattern.option = e.Current.Value.searchOption; pattern.assetFolderName = e.Current.Value.assetFolderName; patterns.Add(pattern); } else { Debug.LogError(string.Format("BuildType is Have.But MyAssetBundleEditor.{0} is null!!!!", e.Current.Value.BuildType)); } } else { Debug.LogErrorFormat("LoadEachPatterns is Called.But assetName == null {0}", e.Current.Key); } } } return(isError); }
//索引器 public T this[int index] { get { return(GetItem(index)); } set { if (index < 0 || index > -Count) { MyDebug.LogErrorFormat("set ArrayBufferStruct Called but index is invaild!{0} Count is {1}", index, Count); return; } _bufferArray[index] = value; } }
/// <summary> /// 卸载 /// </summary> public void UnLoad() { if (asset != null) { MyDebug.LogErrorFormat("卸载资源:{0}", asset.name); if (asset.GetType() != typeof(GameObject)) { Resources.UnloadAsset(asset); //释放指定已经没有引用的Asset. 注意:只能卸载从磁盘加载的文件 } asset = null; } OnUnload(); //更新资源与Bundle之间的引用关系 assetName = null; }
static MyBundle LoadInternal(string assetBundleName, bool isLoadingAssetBundleManifest, bool asyncRequest) { if (!isLoadingAssetBundleManifest) { if (manifest == null) { MyDebug.LogErrorFormat("Please initialize AssetBundleManifest by calling Bundles.Initialize()"); return(null); } } var url = GetDataPath() + assetBundleName; MyBundle bundle = null; if (!bundles.TryGetValue(assetBundleName, out bundle)) { var hash = isLoadingAssetBundleManifest ? new Hash128(1, 0, 0, 0) : manifest.GetAssetBundleHash(assetBundleName); if (bundle == null) { if (url.StartsWith("file://")) { bundle = new MyBundleWWW(url, hash); //启动WWW下载 } else { if (asyncRequest) //是否开启异步 { bundle = new MyBundleAsync(url, hash); } else { bundle = new MyBundle(url, hash); //同步下载 } } bundle.name = assetBundleName; bundles.Add(assetBundleName, bundle); bundle.Load(); //开始下载 if (!isLoadingAssetBundleManifest) //Bundle下载完成之后 加载对应依赖 { LoadDependencies(bundle, assetBundleName, asyncRequest); } } } bundle.Retain(); return(bundle); }
/// <summary> /// 删除指定状态 /// </summary> /// <param name="id"></param> /// <returns></returns> public int Remove(int id) { StateBase <T> state; if (_states.TryGetValue(id, out state)) { _states.Remove(id); } else { MyDebug.LogErrorFormat("not exist state:" + id.ToString()); } return(_states.Count); }
public Object LoadAsset(string assetName, System.Type assetType) { if (string.IsNullOrEmpty(assetName)) { MyDebug.LogErrorFormat("资源加载失败。MyBundle LoadAsset Is Called . But 【assetName】 is Null"); return(null); } try { return(assetBundle.LoadAsset(assetName, assetType)); } catch (Exception e) { MyDebug.LogErrorFormat("MyBundle LoadAsset Is Called .But Have Error:{0},", e); return(null); } }
/// <summary> /// 添加事件队列依次执行回调 /// </summary> /// <param name="action"> callback </param> /// <param name="parmeter"> 参数 </param> public static void QueueOnMainThread(Action <object> action, object parmeter) { if (Current == null) { return; } lock (Current._actions) { if (Current._actions.Count >= Current._actions.MaxSize) //该消息的绑定的回调数量大于总数量 { MyDebug.LogErrorFormat( "QueueOnMainThread called but Current._actions.Count{0} >= Current._actions.MaxSize{1} !", Current._actions.Count, Current._actions.MaxSize); return; } //添加当前消息的回调 Current._actions.Add(new QueueCallItem() { Action = action, Parameter = parmeter }); } }
/// <summary> /// 初始化必要AssetBulde /// </summary> /// <returns></returns> static bool InitializeBundle() { //资源目录 string relativePath = Path.Combine(ResUtility.AssetBundlesOutputPath, ResUtility.GetPlatformPath); var url = #if UNITY_EDITOR relativePath + "/"; #else ResUtility.GetDataPathByPlatform; #endif if (MyBundles.Initialize(url)) //初始化Bundles信息 { var bundle = MyBundles.Load(RuntimeResPath.GetManifestAssetPathExceptSuffix); //卸载配置文件 if (bundle != null) { InitManifest(bundle); bundle.Release(); MyDebug.Log("manifest Load Is Complete!"); } return(true); } MyDebug.LogErrorFormat("bundle manifest not exist.!"); return(false); }
/// <summary> /// 发送消息 /// </summary> /// <param name="notifyID"> 消息ID </param> /// <param name="obj"> 消息参数 </param> public static void SendNotify(string notifyID, object obj) { bool bCall = false; List <Action <object> > findList = null; if (_eventMap.TryGetValue(notifyID, out findList)) //若在立即执行集合中找到该消息。那么立即执行该消息 { for (int i = 0; i < findList.Count; i++) { DoActionImd(findList[i], obj); bCall = true; } } if (_queueEventMap.TryGetValue(notifyID, out findList)) //若需要在Update中通过队列执行 { for (int i = 0; i < findList.Count; i++) { if (ENBALE_THREAD) //开启多线程。启用队列处理 { bCall = true; DoActionInQueue(findList[i], obj); //一个消息。多个回调 } else { bCall = true; DoActionImd(findList[i], obj); } } } if (!bCall) { MyDebug.LogErrorFormat("Dispatch called SendNotify is successd! but not found this callBack"); } }
/// <summary> /// 初始化本地文件信息 /// </summary> public bool InitLoaclFilesInfo(bool isText, string filesInfos = null) { localFileInfosDic.Clear(); if (!Directory.Exists(RuntimeResPath.GetLocalDataPath)) { Directory.CreateDirectory(RuntimeResPath.GetLocalDataPath); } string fileTextPath = string.Empty; if (!isText) { if (filesInfos == null) { fileTextPath = RuntimeResPath.GetLocalDataPath + "files.txt"; } else { fileTextPath = filesInfos; } } if (isText || File.Exists(fileTextPath)) { string filesText = string.Empty; if (isText) { filesText = filesInfos; } else { filesText = ResUtility.ReadFile(fileTextPath); } string[] filesInfo = filesText.Split('\n'); if (filesInfo.Length <= 0) { MyDebug.LogErrorFormat(" files.txt 文件为空.请注意!:{0}", fileTextPath); return(false); } else { for (int i = 0; i < filesInfo.Length; i++) { if (string.IsNullOrEmpty(filesInfo[i])) { continue; } string[] infos = filesInfo[i].Split('|'); string file = infos[0]; string filemd5 = infos[1]; if (!localFileInfosDic.ContainsKey(file)) { localFileInfosDic.Add(file, filemd5); } else { MyDebug.LogErrorFormat("文件重复!!!!!请检查 file:{0}", file); } string localFile = (RuntimeResPath.GetLocalDataPath + file).Trim(); string dir = Path.GetDirectoryName(localFile); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } } isInitLocalFile = true; return(true); } } else { MyDebug.LogErrorFormat(" files.txt 文件不存在.请检查!:{0}", fileTextPath); return(false); } }
internal void UnLoad() { MyDebug.LogErrorFormat("正在卸载Bundle【Path】:{0}", path); OnUnLoad(); }
public void Retain() { references++; MyDebug.LogErrorFormat("【Bundle】:{0},【Retain】:{1}", name, references); }