コード例 #1
0
        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);
             * }
             */
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        /// <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
        }
コード例 #4
0
ファイル: FSMState.cs プロジェクト: hyg821/HFFramework
        public async virtual UniTask OnEnter(object args = null)
        {
            //await new UniTaskVoid();
            await UniTask.Yield();

            HFLog.C("------------------------" + this.GetType().Name + "进入" + "------------------------");
        }
コード例 #5
0
        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();
        }
コード例 #6
0
 private void StartDownLoadTask(string taskName, WebUrlLocalPath paths, Action <string> simpleTaskFinish)
 {
     HFLog.L(taskName + "被创建了");
     this.currentTaskName  = taskName;
     this.currentPath      = paths;
     this.simpleTaskFinish = simpleTaskFinish;
     Start();
 }
コード例 #7
0
ファイル: GameUtils.cs プロジェクト: hyg821/HFFramework
 /// <summary>
 ///  创建自定义读写文件基础文件夹
 /// </summary>
 public void CreateCustomDirectory()
 {
     HFLog.C("自定义读写根目录 " + PathManager.Instance.PersistentDataCustomPath);
     if (!Directory.Exists(PathManager.Instance.PersistentDataCustomPath))
     {
         Directory.CreateDirectory(PathManager.Instance.PersistentDataCustomPath);
     }
 }
コード例 #8
0
 private void TaskComplete()
 {
     finishCount++;
     if (finishCount >= taskCount)
     {
         HFLog.C("所有下载任务完成");
         complete();
     }
     Start();
 }
コード例 #9
0
 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);
     }
 }
コード例 #10
0
 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 + "引用移除失败");
     }
 }
コード例 #11
0
 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 + "引用重复添加");
     }
 }
コード例 #12
0
 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]);
         }
     }
 }
コード例 #13
0
 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);
         }
     }
 }
コード例 #14
0
        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;
        }
コード例 #15
0
ファイル: Entity.cs プロジェクト: hyg821/HFFramework
        /// <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;
        }
コード例 #16
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);
            }
        }
コード例 #17
0
 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("所有下载队列下载完成");
         }
     });
 }
コード例 #18
0
 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;
     }
 }
コード例 #19
0
ファイル: FSM.cs プロジェクト: hyg821/HFFramework
        /// <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);
            }
        }
コード例 #20
0
        /// <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);
        }
コード例 #21
0
ファイル: GameEnvironment.cs プロジェクト: hyg821/HFFramework
 private void UniTaskCatchException(Exception e)
 {
     HFLog.E(e);
 }
コード例 #22
0
 /// <summary>
 ///  清理对应管理器
 /// </summary>
 /// <returns></returns>
 public virtual void ClearManager()
 {
     HFLog.C("步骤4 清理对应管理器");
 }
コード例 #23
0
 /// <summary>
 ///  卸载场景
 /// </summary>
 /// <returns></returns>
 public virtual void UnloadResources()
 {
     AssetManager.Instance.UnloadUnusedAssetBundle(false, true);
     HFLog.C("步骤5 卸载场景");
 }
コード例 #24
0
 /// <summary>
 ///  清理UI
 /// </summary>
 /// <returns></returns>
 public virtual void CloseUI()
 {
     HFLog.C("步骤3 清理UI");
 }
コード例 #25
0
        /// <summary>
        ///  加载场景
        /// </summary>
        /// <returns></returns>
        public virtual async UniTask LoadResources()
        {
            await UniTask.Yield();

            HFLog.C("步骤6 加载场景");
        }
コード例 #26
0
 /// <summary>
 ///  关闭loading
 /// </summary>
 /// <returns></returns>
 public virtual void CloseLoading()
 {
     HFLog.C("步骤10  关闭loading");
 }
コード例 #27
0
        /// <summary>
        ///  打开loading
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public virtual async UniTask OpenLoading(object args)
        {
            await UniTask.Yield();

            HFLog.C("步骤1 打开loading");
        }
コード例 #28
0
 private void TaskError(string error)
 {
     HFLog.C(error);
     currentTask.Start();
 }
コード例 #29
0
ファイル: GameEnvironment.cs プロジェクト: hyg821/HFFramework
 private void CatchException(object sender, UnhandledExceptionEventArgs e)
 {
     HFLog.E("未捕获异常 " + e.ExceptionObject);
 }
コード例 #30
0
        /// <summary>
        /// 发送离开网络消息
        /// </summary>
        /// <returns></returns>
        public virtual async UniTask SendExitRequest()
        {
            await UniTask.Yield();

            HFLog.C("步骤2 发送离开网络消息");
        }