public void Start() { if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.OSXEditor) { currentPath.localPath = currentPath.localPath.Replace("file://", ""); } if (File.Exists(currentPath.localPath)) { HFLog.L(currentTaskName + "文件存在 删除!" + currentPath.localPath); File.Delete(currentPath.localPath); } request = new HTTPRequest(new Uri(currentPath.webUrl), OnRequest); request.OnProgress = OnUploadProgress; request.Timeout = new TimeSpan(0, 0, 20); request.ConnectTimeout = new TimeSpan(0, 0, 20); request.UseStreaming = true; request.StreamFragmentSize = 1 * 256 * 256; request.DisableCache = true; request.Send(); /* * using (WebClient client = new WebClient()) * { * client.DownloadProgressChanged += WebClientDownloadProgressChanged; * client.DownloadFileCompleted += WebClientDownloadCompleted; * client.DownloadFileAsync(new Uri(currentPath.webUrl), currentPath.localPath); * } */ }
private void Update() { try { for (int i = 0; i < removeTimerList.Count; i++) { currentTimerList.Remove(removeTimerList[i]); } removeTimerList.Clear(); for (int i = 0; i < addTimerList.Count; i++) { currentTimerList.Add(addTimerList[i]); } addTimerList.Clear(); for (int i = 0; i < currentTimerList.Count; i++) { Timer timer = currentTimerList[i]; timer.Update(Time.deltaTime); if (timer.isComplete) { removeTimerList.Add(timer); if (timer.complete != null) { timer.complete(timer); } } } } catch (Exception e) { HFLog.C(e); } }
/// <summary> /// 初始化方法 一般只执行一次 /// </summary> /// <param name="path"></param> public void InitWithRootPath(string resourceRootPath, string resourceSpareRootPath, string mainfestName) { HFLog.C("正式资源地址" + resourceRootPath); HFLog.C("备用资源地址" + resourceSpareRootPath); Caching.ClearCache(); if (!Directory.Exists(resourceRootPath)) { Directory.CreateDirectory(resourceRootPath); } if (!string.IsNullOrEmpty(resourceRootPath) && !string.IsNullOrEmpty(resourceSpareRootPath)) { if (!string.Equals(resourceRootPath.Substring(resourceRootPath.Length - 1), @"/")) { resourceRootPath = resourceRootPath + @"/"; } if (!string.Equals(resourceSpareRootPath.Substring(resourceSpareRootPath.Length - 1), @"/")) { resourceSpareRootPath = resourceSpareRootPath + @"/"; } ResourceRootPath = resourceRootPath; ResourceSpareRootPath = resourceSpareRootPath; MainfestName = mainfestName; RefreshAssetBundleManifest(); } #if UNITY_EDITOR InitEditor(); #endif }
public async virtual UniTask OnEnter(object args = null) { //await new UniTaskVoid(); await UniTask.Yield(); HFLog.C("------------------------" + this.GetType().Name + "进入" + "------------------------"); }
public void Start() { if (GameEnvironment.Instance.config.Platform == GamePlatform.Editor || GameEnvironment.Instance.config.Platform == GamePlatform.Windows || GameEnvironment.Instance.config.Platform == GamePlatform.Mac) { path.diskPath = path.diskPath.Replace("file://", ""); } if (File.Exists(path.diskPath)) { File.Delete(path.diskPath); } if (!Directory.Exists(path.dirPath)) { Directory.CreateDirectory(path.dirPath); } fileStream = new FileStream(path.diskPath, FileMode.Append); HFLog.L(name + " 开始下载 "); HFLog.L(name + " path.url " + path.url); HFLog.L(name + " path.diskPath " + path.diskPath); request = new HTTPRequest(new Uri(path.url), OnRequest); request.OnProgress = OnUploadProgress; request.Timeout = new TimeSpan(0, 0, 20); request.ConnectTimeout = new TimeSpan(0, 0, 20); request.UseStreaming = true; request.StreamFragmentSize = 1 * 256 * 256; request.DisableCache = true; request.Send(); }
private void StartDownLoadTask(string taskName, WebUrlLocalPath paths, Action <string> simpleTaskFinish) { HFLog.L(taskName + "被创建了"); this.currentTaskName = taskName; this.currentPath = paths; this.simpleTaskFinish = simpleTaskFinish; Start(); }
/// <summary> /// 创建自定义读写文件基础文件夹 /// </summary> public void CreateCustomDirectory() { HFLog.C("自定义读写根目录 " + PathManager.Instance.PersistentDataCustomPath); if (!Directory.Exists(PathManager.Instance.PersistentDataCustomPath)) { Directory.CreateDirectory(PathManager.Instance.PersistentDataCustomPath); } }
private void TaskComplete() { finishCount++; if (finishCount >= taskCount) { HFLog.C("所有下载任务完成"); complete(); } Start(); }
public void UnloadAssetBundle(AssetPackage bundle, bool unloadAllLoadedObjects = true) { if (GameEnvironment.Instance.config.LoadAssetPathType != LoadAssetPathType.Editor) { HFLog.L("卸载Assetbundle " + bundle.name); bundle.unloading = true; ReleaseAssetBundle(bundle.name); allAssetBundleDic.Remove(bundle.name); bundle.Unload(unloadAllLoadedObjects); } }
public static void RemoveEntity <T>(T entity) where T : Entity { if (Instance.refrencesDic.ContainsKey(entity.instanceId)) { Instance.refrencesDic.Remove(entity.instanceId); Instance.refrencesList.Remove(entity); } else { HFLog.E(typeof(T).Name + entity.instanceId + "引用移除失败"); } }
private static void CacheEntity <T>(T entity) where T : Entity { if (!Instance.refrencesDic.ContainsKey(entity.instanceId)) { Instance.refrencesDic.Add(entity.instanceId, entity); Instance.refrencesList.Add(entity); } else { HFLog.E(typeof(T).Name + entity.instanceId + "引用重复添加"); } }
private void SceneLoaded(Scene s, LoadSceneMode m) { //保证全局只有一个EventSystem GameObject[] temp = s.GetRootGameObjects(); for (int i = temp.Length - 1; i > 0; i--) { if (temp[i].name == "EventSystem") { HFLog.C("跳转场景 发现多余的EventSystem 删除"); GameObject.Destroy(temp[i]); } } }
private void Dispatch() { for (int i = notifyList.Count - 1; i >= 0; i--) { DataObserver <T> o = notifyList[i]; if (o.observer.IsDisposed) { HFLog.C("observer 被销毁 从属性观察列表移除"); o.Clear(); notifyList.RemoveAt(i); } else { o.notify(value); } } }
public void ExchangeEquipmentAndMergeUI(SkeletonGraphic skeletonAnimation, List <EquipmentItem> infos) { for (int i = 0; i < infos.Count; i++) { EquipmentItem info = infos[i]; string regionName = info.equipmentImageName; string defaultSkinName = info.defaultSkinName; string spineEquipmentType = info.spineEquipmentTypeName; AssetBundlePackage assetbundle = HFResourceManager.Instance.LoadAssetBundleFromFile(info.equipmentAssetbundleName); AtlasAsset atlasAsset = assetbundle.LoadAssetWithCache <AtlasAsset>(info.equipmentAtlasAssetName); float scale = skeletonAnimation.skeletonDataAsset.scale; Atlas atlas = atlasAsset.GetAtlas(); AtlasRegion region = atlas.FindRegion(regionName); Slot slot = skeletonAnimation.Skeleton.FindSlot(info.slotName); Attachment originalAttachment = slot.Attachment; if (region == null) { HFLog.C("没有找到图集里的 : 图片 " + regionName); slot.Attachment = null; } else if (originalAttachment != null) { slot.Attachment = originalAttachment.GetRemappedClone(region, true, true, 1); } else { var newRegionAttachment = region.ToRegionAttachment(region.name, scale); slot.Attachment = newRegionAttachment; } slot.Skeleton.Skin.SetAttachment(slot.Data.Index, info.slotPlaceholderName, slot.Attachment); } Skin repackedSkin = new Skin(RepackConst); repackedSkin.Append(skeletonAnimation.Skeleton.Data.DefaultSkin); // Include the "default" skin. (everything outside of skin placeholders) repackedSkin.Append(skeletonAnimation.Skeleton.Skin); // Include your new custom skin. Texture2D runtimeAtlas = null; Material runtimeMaterial = null; repackedSkin = repackedSkin.GetRepackedSkin(RepackConst, skeletonAnimation.SkeletonDataAsset.atlasAssets[0].materials[0], out runtimeMaterial, out runtimeAtlas); // Pack all the items in the skin. skeletonAnimation.Skeleton.SetSkin(repackedSkin); // Assign the repacked skin to your Skeleton. skeletonAnimation.Skeleton.SetSlotsToSetupPose(); // Use the pose from setup pose. skeletonAnimation.Update(0); // Use the pose in the currently active animation. skeletonAnimation.OverrideTexture = runtimeAtlas; }
/// <summary> /// 销毁BaseElement 重载方法 /// </summary> public virtual void Destroy() { if (IsDisposed) { HFLog.E("Entity 重复销毁 Id " + instanceId); return; } for (int i = components.Count - 1; i >= 0; i--) { Component Component = components[i]; components.RemoveAt(i); Component.OnDestroy(); } for (int i = childs.Count - 1; i >= 0; i--) { Entity child = childs[i]; childs.RemoveAt(i); child.Destroy(); } binder.Clear(); parent = null; foreach (var item in messageTypeSet) { NotificationCenter.Instance.RemoveObserver(this, item); } messageTypeSet.Clear(); IsNeedUpdate = false; IsNeedFixedUpdate = false; IsNeedLateUpdate = false; DestoryGameObject(); GameFactory.RemoveEntity(this); instanceId = 0; }
public void Refresh(List <T> dataList, Func <K> Create, Action <T, K> ViewRefresh) { if (dataList == null) { HFLog.E("dataList = null"); return; } if (dataList.Count > 20) { HFLog.C("视图层数量大于20 适用复用滚动列表实现"); } this.dataList = dataList; if (dataList.Count < viewList.Count) { for (int i = dataList.Count; i < viewList.Count; i++) { viewList[i].IsActive = false; } } for (int i = 0; i < dataList.Count; i++) { T data = dataList[i]; K k = null; if (i < viewList.Count) { k = viewList[i]; k.IsActive = true; } else { //生成Item列表并显示数据 k = Create(); viewList.Add(k); } ViewRefresh(data, k); } }
private void DownLoadFile(WebUrlLocalPath path) { StartDownLoadTask("Task" + currentTaskIndex, path, delegate(string taskName) { HFLog.L("单个下载完成"); if (currentTaskIndex < taskCount - 1) { if (progress != null) { progress((currentTaskIndex + 1.0f) / taskCount); } currentTaskIndex++; DownLoadFile(allTaskPath[currentTaskIndex]); } else { progress(1); DownLoadManager.Instance.currentDownLoadCount--; HFLog.L("所有下载队列下载完成"); } }); }
public void Send(NotificationMessage msg) { try { List <ObserverDelegate> list; if (messagePool.TryGetValue(msg.Key, out list)) { for (int i = 0; i < list.Count; i++) { ObserverDelegate o = list[i]; if (o.receiver != null && o.handler != null) { o.handler(msg); } } } } catch (Exception e) { HFLog.E(e); throw; } }
/// <summary> /// 转移到某个状态 /// </summary> /// <param name="stateName"></param> public async UniTaskVoid ChangeState <T>(object enterParams = null, object exitParams = null) where T : FSMState, new() { if (!locked) { locked = true; string key = typeof(T).Name; if (currentState != null) { await currentState.Exit(exitParams); } if (!stateDic.TryGetValue(key, out currentState)) { currentState = AddState <T>(); } await currentState.Enter(enterParams); locked = false; } else { HFLog.E("重复转换状态 " + typeof(T).Name); } }
/// <summary> /// 添加一个观察者 /// </summary> /// <param name="receiver"></param> /// <param name="msgID"></param> /// <param name="callback"></param> public void AddObserver(object receiver, ushort moduleId, int msgId, Action <NotificationMessage> callback) { if (receiver == null) { HFLog.E(" moduleID = " + moduleId + " msgID = " + msgId + " receiver 不能为空"); return; } if (callback == null) { HFLog.E(" moduleID = " + moduleId + " msgID = " + msgId + " callback 不能为空"); return; } ObserverDelegate o = new ObserverDelegate(receiver, moduleId, msgId, callback); List <ObserverDelegate> list; if (!messagePool.TryGetValue(o.Key, out list)) { list = new List <ObserverDelegate>(); messagePool.Add(o.Key, list); } list.Add(o); }
private void UniTaskCatchException(Exception e) { HFLog.E(e); }
/// <summary> /// 清理对应管理器 /// </summary> /// <returns></returns> public virtual void ClearManager() { HFLog.C("步骤4 清理对应管理器"); }
/// <summary> /// 卸载场景 /// </summary> /// <returns></returns> public virtual void UnloadResources() { AssetManager.Instance.UnloadUnusedAssetBundle(false, true); HFLog.C("步骤5 卸载场景"); }
/// <summary> /// 清理UI /// </summary> /// <returns></returns> public virtual void CloseUI() { HFLog.C("步骤3 清理UI"); }
/// <summary> /// 加载场景 /// </summary> /// <returns></returns> public virtual async UniTask LoadResources() { await UniTask.Yield(); HFLog.C("步骤6 加载场景"); }
/// <summary> /// 关闭loading /// </summary> /// <returns></returns> public virtual void CloseLoading() { HFLog.C("步骤10 关闭loading"); }
/// <summary> /// 打开loading /// </summary> /// <param name="p"></param> /// <returns></returns> public virtual async UniTask OpenLoading(object args) { await UniTask.Yield(); HFLog.C("步骤1 打开loading"); }
private void TaskError(string error) { HFLog.C(error); currentTask.Start(); }
private void CatchException(object sender, UnhandledExceptionEventArgs e) { HFLog.E("未捕获异常 " + e.ExceptionObject); }
/// <summary> /// 发送离开网络消息 /// </summary> /// <returns></returns> public virtual async UniTask SendExitRequest() { await UniTask.Yield(); HFLog.C("步骤2 发送离开网络消息"); }