示例#1
0
        private void LoadAssetCacheDependenciesAsync <T>(BaseAssetCache Cache, LiteAction <bool> Callback = null) where T : UnityEngine.Object
        {
            var LoadCompletedCount = 0;
            var Dependencies       = Cache.GetAllDependencies();

            if (Dependencies == null || Dependencies.Length == 0)
            {
                Callback?.Invoke(true);
                return;
            }

            foreach (var Dependency in Dependencies)
            {
                var AssetPath = Dependency;
                var AssetType = GetAssetTypeWithName <T>(AssetPath);
                LoadAssetAsync <T>(AssetType, AssetPath, (IsLoaded) =>
                {
                    if (!IsLoaded)
                    {
                        Callback?.Invoke(false);
                        return;
                    }

                    Cache.AddDependencyCache(AssetCacheList_[AssetPath]);
                    LoadCompletedCount++;

                    if (LoadCompletedCount >= Dependencies.Length)
                    {
                        Callback?.Invoke(true);
                    }
                });
            }
        }
示例#2
0
        private static IEnumerator CacheStreamingAssets(string[] FileList, LiteAction <int, int, int> Callback)
        {
            var Index      = 0;
            var DoneCount  = 0;
            var ErrorCount = 0;

            while (Index < FileList.Length)
            {
                yield return(CopyFileFromStreamingAssetsPathToPersistentDataPath(FileList[Index], (Suc) =>
                {
                    Index++;

                    if (Suc)
                    {
                        DoneCount++;
                    }
                    else
                    {
                        ErrorCount++;
                    }

                    Callback?.Invoke(ErrorCount, DoneCount, FileList.Length);
                }));
            }

            Callback?.Invoke(ErrorCount, DoneCount, FileList.Length);
        }
示例#3
0
        public void CreatePrefabAsync(AssetUri Uri, LiteAction <UnityEngine.GameObject> Callback = null)
        {
            LoadAssetAsync <UnityEngine.GameObject>(AssetCacheType.Prefab, Uri.AssetPath, (IsLoaded) =>
            {
                if (!IsLoaded)
                {
                    Callback?.Invoke(null);
                    return;
                }

                Callback?.Invoke(CreatePrefabSync(Uri));
            });
        }
示例#4
0
        public void CreateDataAsync(AssetUri Uri, LiteAction <byte[]> Callback = null)
        {
            LoadAssetAsync <UnityEngine.TextAsset>(AssetCacheType.Data, Uri.AssetPath, (IsLoaded) =>
            {
                if (!IsLoaded)
                {
                    Callback?.Invoke(null);
                    return;
                }

                Callback?.Invoke(CreateDataSync(Uri));
            });
        }
示例#5
0
        public void CreateAssetAsync <T>(AssetUri Uri, LiteAction <T> Callback = null) where T : UnityEngine.Object
        {
            var AssetType = GetAssetTypeWithName <T>(Uri.AssetPath);

            LoadAssetAsync <T>(AssetType, Uri.AssetPath, (IsLoaded) =>
            {
                if (!IsLoaded)
                {
                    Callback?.Invoke(null);
                    return;
                }

                Callback?.Invoke(CreateAssetSync <T>(Uri));
            });
        }
示例#6
0
        protected virtual void LoadAssetAsync <T>(AssetCacheType AssetType, string AssetPath, LiteAction <bool> Callback = null) where T : UnityEngine.Object
        {
            AssetPath = AssetPath.ToLower();
            if (AssetCacheExisted(AssetPath))
            {
                Callback?.Invoke(true);
                return;
            }

            if (!AssetLoadCallbackList_.ContainsKey(AssetPath))
            {
                AssetLoadCallbackList_.Add(AssetPath, new List <LiteAction <bool> > {
                    Callback
                });

                LoadAssetCacheCompletedAsync <T>(AssetType, AssetPath, (IsLoaded) =>
                {
                    foreach (var LoadCallback in AssetLoadCallbackList_[AssetPath])
                    {
                        LoadCallback?.Invoke(IsLoaded);
                    }

                    AssetLoadCallbackList_.Remove(AssetPath);
                });
            }
            else
            {
                AssetLoadCallbackList_[AssetPath].Add(Callback);
            }
        }
示例#7
0
        public static void PlaySkeletonSfxAsync(Transform Parent, AssetUri Uri, Vector2 Position, LiteAction <SkeletonSfx> Callback, bool IsLoop = false, string AnimationName = "", LiteAction Finished = null)
        {
            if (Parent == null || Uri == null)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(AnimationName))
            {
                AnimationName = Uri.AssetName;
            }

            AssetManager.CreatePrefabAsync(Uri, (Obj) =>
            {
                var Sfx = new SkeletonSfx(Uri.AssetName, Obj.transform);
                SfxList_.Add(Sfx);
                Sfx.SetParent(Parent, false);
                Sfx.Play(AnimationName, IsLoop, Finished);
                Sfx.Position = Position;

                var order = UnityHelper.GetSortingOrderUpper(Parent);
                UnityHelper.AddSortingOrder(Obj, order + 1);

                Callback?.Invoke(Sfx);
            });
        }
示例#8
0
 public void Foreach(LiteAction <T> TickFunc)
 {
     Flush();
     InEach_++;
     foreach (var Item in Values_)
     {
         TickFunc?.Invoke(Item);
     }
     InEach_--;
 }
示例#9
0
        public static void AddClickEventToChild(Transform Parent, string ChildPath, LiteAction <EventSystemData> Callback, AssetUri AudioUri)
        {
            void OnClick(EventSystemData Data)
            {
                AudioManager.PlaySound(AudioUri);
                Callback?.Invoke(Data);
            }

            AddEventToChild(Parent, ChildPath, OnClick);
        }
示例#10
0
        protected override void LoadAssetAsync <T>(AssetCacheType AssetType, string AssetPath, LiteAction <bool> Callback = null)
        {
            AssetPath = AssetPath.ToLower();
            if (!AssetBundlePathList_.Contains(AssetPath))
            {
                Callback?.Invoke(false);
                return;
            }

            base.LoadAssetAsync <T>(AssetType, AssetPath, Callback);
        }
示例#11
0
        private void InternalUpdateItem(ItemEntity Entity, int Index)
        {
            if (Entity.Index == Index)
            {
                return;
            }

            Entity.Index = Index;
            Entity.ObjRectTrans.anchoredPosition = InternalGetItemPosition(Index);
            OnUpdateItem_?.Invoke(Index, Entity.Item);
        }
示例#12
0
        private static IEnumerator CopyFileFromStreamingAssetsPathToPersistentDataPath(string AssetBundlePath, LiteAction <bool> Callback)
        {
            var Uri = new Uri(Path.Combine(Application.streamingAssetsPath, AssetBundlePath));

            using (var Request = new UnityWebRequest(Uri, "GET", (DownloadHandler) new DownloadHandlerBuffer(), (UploadHandler)null))
            {
                yield return(Request.SendWebRequest());

                if (Request.isNetworkError || Request.isHttpError)
                {
                    LLogger.LWarning(Request.error);
                    Callback?.Invoke(false);
                }
                else
                {
                    if (Request.downloadHandler?.data == null)
                    {
                        LLogger.LWarning($"AssetBundle Data Is Null : {AssetBundlePath}");
                        Callback?.Invoke(false);
                    }
                    else
                    {
                        try
                        {
                            var TargetPath    = Path.Combine(Application.persistentDataPath, AssetBundlePath);
                            var DirectoryPath = PathHelper.GetDirectory(TargetPath);
                            PathHelper.CreateDirectory(DirectoryPath);
                            File.WriteAllBytes(TargetPath, Request.downloadHandler.data);
                            Callback?.Invoke(true);
                        }
                        catch (LiteException Ex)
                        {
                            LLogger.LWarning(Ex.Message);
                            Callback?.Invoke(false);
                        }
                    }
                }
            }
        }
示例#13
0
        private void LoadAssetCacheCompletedAsync <T>(AssetCacheType AssetType, string AssetPath, LiteAction <bool> Callback = null) where T : UnityEngine.Object
        {
            var Cache = CreateAssetCache <T>(AssetType, AssetPath);

            if (Cache == null)
            {
                Callback?.Invoke(false);
                return;
            }

            AssetCacheList_.Add(AssetPath, Cache);
            LoadAssetCacheDependenciesAsync <UnityEngine.Object>(Cache, (IsLoaded) =>
            {
                if (!IsLoaded)
                {
                    Callback?.Invoke(false);
                    return;
                }

                TaskManager.AddTask(LoadAssetCacheAsync <T>(Cache), () => { Callback?.Invoke(true); });
            });
        }
示例#14
0
        public override void Tick(float DeltaTime)
        {
            if (!IsAlive)
            {
                return;
            }

            Time_  += DeltaTime;
            IsAlive = !IsEnd();
            if (!IsAlive)
            {
                Finished_?.Invoke();
            }
        }
示例#15
0
        public void ItemDone()
        {
            DoneCount_++;

            if (DoneCount_ >= ItemList_.Count)
            {
                IsEnd = true;
                Callback_?.Invoke();
                return;
            }

            if (!IsParallel_)
            {
                ItemList_[DoneCount_].Execute();
            }
        }
示例#16
0
        public static void LoadAsync(AssetUri Uri, LiteAction <bool> Callback)
        {
            if (!DataList_.ContainsKey(Uri.AssetName))
            {
                AssetManager.CreateDataAsync(Uri, Buffer =>
                {
                    var Data      = new DataTable(Uri.AssetName);
                    var Succeeded = Data.Parse(Buffer);

                    if (Succeeded)
                    {
                        DataList_.Add(Uri.AssetName, Data);
                    }

                    Callback?.Invoke(Succeeded);
                });
            }
        }
示例#17
0
        public void Tick(float DeltaTime)
        {
            if (!IsMoving_)
            {
                return;
            }

            CurrentTime_ += DeltaTime;

            var T = CurrentTime_ / MoveTime_;

            Master_.localPosition = Vector3.Lerp(BeginPos_, EndPos_, Mathf.Clamp01(T));

            if (T >= 1.0f)
            {
                Stop();
                FinishCallback_?.Invoke();
            }
        }
示例#18
0
        public void MoveTo(Vector3 TargetPos, float MoveTime, bool Force, LiteAction Finished)
        {
            if (IsMoving_ && !Force)
            {
                return;
            }

            if ((new Vector3(EndPos_.x, EndPos_.y) - TargetPos).magnitude < 0.00001f)
            {
                Finished?.Invoke();
                return;
            }

            IsMoving_       = true;
            BeginPos_       = Master_.localPosition;
            EndPos_         = new Vector3(TargetPos.x, TargetPos.y, BeginPos_.z);
            MoveTime_       = Mathf.Clamp(MoveTime, 0.016f, float.MaxValue);
            CurrentTime_    = 0;
            FinishCallback_ = Finished;
        }
示例#19
0
        public IEnumerator Execute()
        {
            while (!IsEnd)
            {
                if (IsPause)
                {
                    yield return(null);
                }
                else if (TaskEntity_ != null && TaskEntity_.MoveNext())
                {
                    yield return(TaskEntity_.Current);
                }
                else
                {
                    IsEnd = true;
                }
            }

            Callback_?.Invoke();
        }
示例#20
0
        public static void PlayParticleSfxAsync(Transform Parent, AssetUri Uri, Vector2 Position, LiteAction <ParticleSfx> Callback, bool IsLoop = false, LiteAction Finished = null)
        {
            if (Parent == null || Uri == null)
            {
                return;
            }

            AssetManager.CreatePrefabAsync(Uri, (Obj) =>
            {
                var Sfx = new ParticleSfx(Uri.AssetName, Obj.transform);
                SfxList_.Add(Sfx);
                Sfx.SetParent(Parent, false);
                Sfx.Play(string.Empty, IsLoop, Finished);
                Sfx.Position = Position;

                var order = UnityHelper.GetSortingOrderUpper(Parent);
                UnityHelper.AddSortingOrder(Obj, order + 1);

                Callback?.Invoke(Sfx);
            });
        }
示例#21
0
        public override void Play(string AnimationName, bool IsLoop = false, LiteAction Finished = null)
        {
            if (Animation_.Skeleton.Data.FindAnimation(AnimationName) == null)
            {
                LLogger.LError($"can't play animation '{AnimationName}'");
                return;
            }

            Animation_.AnimationState.SetAnimation(0, AnimationName, IsLoop);

            if (Finished == null)
            {
                Animation_.AnimationState.Complete = null;
            }
            else
            {
                Animation_.AnimationState.Complete = (Track) =>
                {
                    Finished.Invoke();
                    Animation_.AnimationState.Complete = null;
                };
            }
        }
示例#22
0
 private void TriggerDispose(T Cache)
 {
     DisposeFunc_?.Invoke(Cache);
 }
示例#23
0
 private void TriggerRecycle(T Cache)
 {
     RecycleFunc_?.Invoke(Cache);
 }
示例#24
0
 private void TriggerSpawn(T Cache)
 {
     SpawnFunc_?.Invoke(Cache);
 }
示例#25
0
 public void Invoke()
 {
     Func_?.Invoke(Param_);
 }
示例#26
0
 public override void Enter()
 {
     Callback_?.Invoke();
 }
示例#27
0
 public override void Execute()
 {
     NewFunc_?.Invoke(this, Param_);
 }
示例#28
0
 public virtual void Execute()
 {
     Func_?.Invoke(this);
 }