Exemple #1
0
        public static void GenerateFilesInfoFile()
        {
            if (!Directory.Exists(Path.Combine(Application.dataPath, "Resources")))
            {
                Directory.CreateDirectory(Path.Combine(Application.dataPath, "Resources"));
            }

            var FilePath = Path.Combine(Application.dataPath, "Resources", FilesInfoFileName);
            var FileList = PathHelper.GetFileList(Application.streamingAssetsPath, (Path) => PathHelper.GetFileExt(Path) != ".meta");

            if (File.Exists(FilePath))
            {
                File.Delete(FilePath);
            }

            using (var OutStream = new StreamWriter(FilePath, false, Encoding.ASCII))
            {
                foreach (var File in FileList)
                {
                    var RelativePath = File.Substring(Application.streamingAssetsPath.Length + 1);
                    OutStream.WriteLine(RelativePath);
                }

                OutStream.Close();
            }

            LLogger.LWarning($"Generate FilesInfo Succeed -> {FilePath}");
        }
Exemple #2
0
        public static bool CacheStreamingAssets(Action <int, int, int> Callback)
        {
            var Files = Resources.Load <TextAsset>(PathHelper.GetFileNameWithoutExt(FilesInfoFileName));

            if (Files == null || string.IsNullOrWhiteSpace(Files.text))
            {
                LLogger.LWarning("version.txt is empty");
                return(false);
            }

            var FileList     = Files.text.Split(new char[] { '\r', '\n' });
            var FileListTrim = new List <string>();

            foreach (var FileName in FileList)
            {
                if (string.IsNullOrWhiteSpace(FileName))
                {
                    continue;
                }

                FileListTrim.Add(FileName);
            }

            TaskManager.AddTask(CacheStreamingAssets(FileListTrim.ToArray(), Callback));
            return(true);
        }
Exemple #3
0
        public T[,] ReadArray2 <T>(string Key, T[,] Default) where T : IArchiveInfo, new()
        {
            if (!CacheList_.ContainsKey(Key))
            {
                return(Default);
            }

            if (CacheList_[Key] is object[,] ArrayObj)
            {
                var Width       = ArrayObj.GetLength(0);
                var Height      = ArrayObj.GetLength(1);
                var OutputArray = new T[Width, Height];
                for (var X = 0; X < Width; ++X)
                {
                    for (var Y = 0; Y < Height; ++Y)
                    {
                        OutputArray[X, Y] = (T)ArrayObj[X, Y];
                    }
                }
                return(OutputArray);
            }

            LLogger.LWarning($"archive type error : {Key} - {typeof(T)}");
            return(Default);
        }
Exemple #4
0
 public static void DeleteStreamingAssets()
 {
     Directory.Delete(Application.streamingAssetsPath, true);
     Directory.CreateDirectory(Application.streamingAssetsPath);
     AssetDatabase.Refresh();
     LLogger.LWarning("StreamingAssets Remove");
 }
Exemple #5
0
        public T[] ReadSubArray <T>(string Key, T[] Default) where T : IArchiveInfo, new()
        {
            if (!CacheList_.ContainsKey(Key))
            {
                return(Default);
            }

            if (CacheList_[Key] is object[] ArrayObj)
            {
                var Len         = Default?.Length ?? ArrayObj.Length;
                var OutputArray = new T[Len];
                for (var Index = 0; Index < Len; ++Index)
                {
                    if (Index < ArrayObj.Length)
                    {
                        OutputArray[Index] = (T)ArrayObj[Index];
                    }
                    else
                    {
                        OutputArray[Index] = Default[Index];
                    }
                }

                return(OutputArray);
            }

            LLogger.LWarning($"archive type error : {Key} - {typeof(T)}");
            return(Default);
        }
Exemple #6
0
        private static void BindNode(BaseUI UI)
        {
            var FieldList = UI.GetType().GetFields(CustomFlags);

            foreach (var Field in FieldList)
            {
                if (Field.FieldType != TransformType)
                {
                    continue;
                }

                var Attr = Field.GetCustomAttribute <LiteUINodeAttribute>(false);
                if (Attr != null)
                {
                    var NodeValue = UI.FindChild(Attr.Path);
                    if (NodeValue == null)
                    {
                        LLogger.LWarning($"can't bind node : {Attr.Path}");
                        continue;
                    }

                    Field.SetValue(UI, NodeValue);
                }
            }
        }
Exemple #7
0
        private static void BindEvent(BaseUI UI)
        {
            var MethodList = UI.GetType().GetMethods(CustomFlags);

            foreach (var Method in MethodList)
            {
                var Attr = Method.GetCustomAttribute <LiteUIEventAttribute>(false);
                if (Attr != null)
                {
                    try
                    {
                        if (Method.GetParameters().Length == 0)
                        {
                            UI.AddEventToChild(Attr.Path, Delegate.CreateDelegate(typeof(UnityAction), UI, Method) as UnityAction, Attr.EventType);
                        }
                        else
                        {
                            UI.AddEventToChild(Attr.Path, Delegate.CreateDelegate(typeof(Action <EventSystemData>), UI, Method) as UnityAction, Attr.EventType);
                        }
                    }
                    catch (Exception Ex)
                    {
                        LLogger.LWarning(Ex.Message);
                        LLogger.LWarning($"can't bind component : {Attr.Path}");
                    }
                }
            }
        }
Exemple #8
0
        private static void BindComponent(BaseUI UI)
        {
            var FieldList = UI.GetType().GetFields(CustomFlags);

            foreach (var Field in FieldList)
            {
                if (!Field.FieldType.IsSubclassOf(ComponentType))
                {
                    continue;
                }

                var Attr = Field.GetCustomAttribute <LiteUIComponentAttribute>(false);
                if (Attr != null)
                {
                    var ComponentValue = UI.GetComponent(Attr.Path, Field.FieldType);
                    if (ComponentValue == null)
                    {
                        LLogger.LWarning($"can't bind component : {Attr.Path}");
                        continue;
                    }

                    Field.SetValue(UI, ComponentValue);
                }
            }
        }
Exemple #9
0
            public override IEnumerator LoadAsync()
            {
                if (IsLoad)
                {
                    yield break;
                }

                IsLoad   = false;
                Request_ = CreateBundleRequestAsync(AssetPath);
                yield return(Request_);

                if (Request_ == null || !Request_.isDone)
                {
                    LLogger.LWarning($"Load AssetBundle : {AssetPath} Failed");
                }
                else
                {
                    RefCount_ = 0;
                    IsLoad    = true;
                    Bundle_   = Request_.assetBundle;
                    OnLoad();
                    Request_ = null;
                }

                yield break;
            }
Exemple #10
0
        /// <summary>
        /// only support (Boolean, Int32, BigInteger, String)
        /// </summary>
        public T[] ReadArray <T>(string Key, T[] Default)
        {
            if (!CacheList_.ContainsKey(Key))
            {
                return(Default);
            }

            if (CacheList_[Key] is T[] Value)
            {
                if (Default != null && Value.Length < Default.Length)
                {
                    var NewValue = new T[Default.Length];

                    for (var Index = 0; Index < NewValue.Length; ++Index)
                    {
                        if (Index < Value.Length)
                        {
                            NewValue[Index] = Value[Index];
                        }
                        else
                        {
                            NewValue[Index] = Default[Index];
                        }
                    }

                    return(NewValue);
                }

                return(Value);
            }

            LLogger.LWarning($"archive type error : {Key} - {typeof(T)}");
            return(Default);
        }
Exemple #11
0
        void Update()
        {
            try
            {
                LiteManager.Tick(Time.deltaTime);
            }
            catch (System.Exception Ex)
            {
                LLogger.LError($"{Ex.Message}\n{Ex.StackTrace}");
            }

#if UNITY_EDITOR
            if (Input.GetKeyDown(KeyCode.F1))
            {
                LiteManager.TimeScale = 0.5f;
                LLogger.LWarning($"TimeScale = {LiteManager.TimeScale}");
            }
            else if (Input.GetKeyDown(KeyCode.F2))
            {
                LiteManager.TimeScale = 1.0f;
                LLogger.LWarning($"TimeScale = {LiteManager.TimeScale}");
            }
            else if (Input.GetKeyDown(KeyCode.F3))
            {
                LiteManager.TimeScale = 5.0f;
                LLogger.LWarning($"TimeScale = {LiteManager.TimeScale}");
            }
            else if (Input.GetKeyDown(KeyCode.PageUp))
            {
                LiteManager.TimeScale--;
                LLogger.LWarning($"TimeScale = {LiteManager.TimeScale}");
            }
            else if (Input.GetKeyDown(KeyCode.PageDown))
            {
                LiteManager.TimeScale++;
                LLogger.LWarning($"TimeScale = {LiteManager.TimeScale}");
            }

            if (Input.GetKeyDown(KeyCode.F5))
            {
                LiteManager.Restart();
            }
            else if (Input.GetKeyDown(KeyCode.F6))
            {
                LiteManager.Shutdown();
            }
            else if (Input.GetKeyDown(KeyCode.F9))
            {
                EnableGizmos_ = !EnableGizmos_;
            }
            else if (Input.GetKeyDown(KeyCode.F12))
            {
                OnApplicationPause(!LiteManager.IsPause);
            }
#endif
        }
Exemple #12
0
        public void WriteSub <T>(string Key, T Value) where T : IArchiveInfo, new()
        {
            if (CacheList_.ContainsKey(Key))
            {
                LLogger.LWarning($"archive repeat key : {Key}");
                CacheList_[Key] = Value;
                return;
            }

            CacheList_.Add(Key, Value);
        }
Exemple #13
0
            public override void Check()
            {
                if (OnEvent != null)
                {
                    var CallbackList = OnEvent.GetInvocationList();

                    foreach (var Callback in CallbackList)
                    {
                        LLogger.LWarning($"{Callback.Method.ReflectedType.Name} : {Callback.Method.Name} UnRegister");
                    }
                }
            }
Exemple #14
0
        public static bool CreateDirectory(string DirectoryPath)
        {
            DirectoryPath = UnifyPath(DirectoryPath);
            if (!Directory.Exists(DirectoryPath))
            {
                if (!Directory.CreateDirectory(DirectoryPath).Exists)
                {
                    LLogger.LWarning($"can't create directory : {DirectoryPath}");
                    return(false);
                }
            }

            return(true);
        }
Exemple #15
0
        /// <summary>
        /// support type see : ArchiveDataType
        /// </summary>
        public T Read <T>(string Key, T Default)
        {
            if (!CacheList_.ContainsKey(Key))
            {
                return(Default);
            }

            if (CacheList_[Key] is T TValue)
            {
                return(TValue);
            }

            LLogger.LWarning($"archive type error : {Key} - {typeof(T)}");
            return(Default);
        }
Exemple #16
0
        public T ReadSub <T>(string Key) where T : IArchiveInfo, new()
        {
            if (!CacheList_.ContainsKey(Key))
            {
                return(new T());
            }

            if (CacheList_[Key] is T Info)
            {
                return(Info);
            }

            LLogger.LWarning($"archive type error : {Key} - {typeof(T)}");
            return(new T());
        }
Exemple #17
0
        /// <summary>
        /// only support (Int32, BigInteger)
        /// </summary>
        public void WriteArray2 <T>(string Key, T[,] Value)
        {
            if (Value == null)
            {
                return;
            }

            if (CacheList_.ContainsKey(Key))
            {
                LLogger.LWarning($"archive repeat key : {Key}");
                CacheList_[Key] = Value;
                return;
            }

            CacheList_.Add(Key, Value);
        }
Exemple #18
0
        public T CreateAssetSync <T>(AssetUri Uri) where T : UnityEngine.Object
        {
            var AssetType = GetAssetTypeWithName <T>(Uri.AssetPath);

            T Asset = null;

            var AssetName = Uri.AssetName;

            if (AssetType == AssetCacheType.Asset)
            {
                AssetName = $"{AssetName}_{typeof(T).Name.ToLower()}";
            }

            BaseAssetCache Cache = null;

            if (!AssetCacheList_.ContainsKey(Uri.AssetPath))
            {
                Cache = LoadAssetSync <UnityEngine.Object>(AssetType, Uri.AssetPath);
            }
            else
            {
                Cache = AssetCacheList_[Uri.AssetPath];
                if (!Cache.IsLoad)
                {
                    Cache.ForeCompleteAsync();
                }
            }

            if (Cache != null)
            {
                Asset = Cache.CreateAsset(AssetName) as T;

                if (Asset != null)
                {
                    if (!AssetPathCacheList_.ContainsKey(Asset.GetInstanceID()))
                    {
                        AssetPathCacheList_.Add(Asset.GetInstanceID(), Uri.AssetPath);
                    }
                }
                else
                {
                    LLogger.LWarning($"Can't Create Asset : {Uri}");
                }
            }

            return(Asset);
        }
Exemple #19
0
        private static uint PlayAudio(AudioType Type, Transform Parent, AssetUri Uri, bool IsLoop = false, float Volume = 1.0f)
        {
            if (Uri == null)
            {
                return(0);
            }

            var Entity = new AudioEntity(Type);

            AudioList_.Add(Entity.SerialID, Entity);

            AssetManager.CreateAssetAsync <AudioClip>(Uri, (Clip) =>
            {
                if (Clip == null)
                {
                    LLogger.LWarning($"can't play audio : {Uri}");
                    RemoveList_.Add(Entity);
                    return;
                }

                Entity.LoadAudio(Parent, Clip, IsLoop, Volume, false);

                switch (Type)
                {
                case AudioType.Sound:
                    if (MuteSound)
                    {
                        Entity.Mute(MuteSound);
                    }
                    break;

                case AudioType.Music:
                    if (MuteMusic)
                    {
                        Entity.Mute(MuteMusic);
                    }
                    break;

                default:
                    break;
                }

                Entity.Play();
            });

            return(Entity.SerialID);
        }
Exemple #20
0
            public override void LoadSync()
            {
                IsLoad = false;
                var Request = CreateInternalRequestSync(AssetPath);

                if (Request == null)
                {
                    LLogger.LWarning($"Load AssetInternal : {AssetPath} Failed");
                }
                else
                {
                    RefCount_ = 0;
                    IsLoad    = true;
                    Bundle    = Request;
                    OnLoad();
                }
            }
Exemple #21
0
            protected override void OnLoad()
            {
                IsLoad = false;
                var FullPath = GetInternalAssetPath();

                if (!File.Exists(FullPath))
                {
                    LLogger.LWarning($"Load AssetInternal : {FullPath} Failed");
                }
                else
                {
                    RefCount_ = 0;
                    IsLoad    = true;
                    Buffer    = File.ReadAllBytes(FullPath);
                    Asset_    = new AssetInternalTextAsset(Buffer);
                }
            }
Exemple #22
0
            public override void LoadSync()
            {
                IsLoad = false;
                var Request = CreateBundleRequestSync(AssetPath);

                if (!Request)
                {
                    LLogger.LWarning($"Load AssetBundle : {AssetPath} Failed");
                }
                else
                {
                    RefCount_ = 0;
                    IsLoad    = true;
                    Bundle_   = Request;
                    OnLoad();
                }
            }
Exemple #23
0
        public void UseSkill(SkillArgs Args)
        {
            if (Args == null || Args.Skill == null)
            {
                LLogger.LWarning("Npc UseSkill, Args or Args.Skill is null");
                return;
            }

            if (!CanUseSkill(Args.Skill.SkillID))
            {
                return;
            }

            var Evt = new NpcSkillEvent(Master, Args.Skill.SkillID, Args);

            EventManager.Send(Evt);
        }
Exemple #24
0
        public static void ReplaceSprite(SpriteRenderer Master, AssetUri Uri)
        {
            if (Master == null || Uri == null)
            {
                return;
            }

            AssetManager.CreateAssetAsync <Sprite>(Uri, (Spr) =>
            {
                if (Spr == null)
                {
                    LLogger.LWarning($"can't load {Uri}");
                    return;
                }

                Master.sprite = Spr;
            });
        }
Exemple #25
0
            public override void LoadSync()
            {
                IsLoad = false;
                var Bundle = Request_ != null ? Request_.assetBundle : CreateBundleRequestSync(AssetPath);

                if (!Bundle)
                {
                    LLogger.LWarning($"Load AssetBundle : {AssetPath} Failed");
                }
                else
                {
                    RefCount_ = 0;
                    IsLoad    = true;
                    Bundle_   = Bundle;
                    OnLoad();
                    Request_ = null;
                }
            }
Exemple #26
0
        public static NpcSkill AddNpcSkill(SkillDescriptor Desc, BaseNpc Master)
        {
            if (Desc == null || Master == null)
            {
                return(null);
            }

            if (Desc.Type == SkillType.Passive)
            {
                LLogger.LWarning($"need not passive desc, current is {Desc.Type}");
                return(null);
            }

            var Entity = new NpcSkill(Desc, Master);

            AddSkill(Entity);
            return(Entity);
        }
Exemple #27
0
            protected override void OnLoad()
            {
                var AssetList = Bundle_.LoadAllAssets <UnityEngine.GameObject>();

                if (AssetList != null)
                {
                    foreach (var Asset in AssetList)
                    {
                        var Name = Asset.name.ToLower();
                        if (AssetList_.ContainsKey(Name))
                        {
                            LLogger.LWarning($"Repeat Asset : {Name}");
                            continue;
                        }
                        AssetList_.Add(Name, Asset);
                    }
                }
            }
Exemple #28
0
            protected override void OnLoad()
            {
                var AssetList = Bundle_.LoadAllAssets <T>();

                if (AssetList != null)
                {
                    foreach (var Asset in AssetList)
                    {
                        var Name = $"{Asset.name.ToLower()}_{Asset.GetType().Name.ToLower()}";
                        if (AssetList_.ContainsKey(Name))
                        {
                            LLogger.LWarning($"Repeat Asset : {Name}");
                            continue;
                        }
                        AssetList_.Add(Name, Asset);
                        AssetInstanceIDList_.Add(Asset.GetInstanceID());
                    }
                }
            }
Exemple #29
0
        public static PassiveSkill AddPassiveSkill(SkillDescriptor Desc, BaseNpc Master, float SustainTime)
        {
            if (Desc == null || Master == null)
            {
                return(null);
            }

            if (Desc.Type != SkillType.Passive)
            {
                LLogger.LWarning($"need passive desc, current is {Desc.Type}");
                return(null);
            }

            var Entity = new PassiveSkill(Desc, Master, SustainTime);

            AddSkill(Entity);
            Entity.Use(new SkillArgs(Entity));
            return(Entity);
        }
Exemple #30
0
        /// <summary>
        /// only support (Int32, BigInteger)
        /// </summary>
        public T[,] ReadArray2 <T>(string Key, T[,] Default)
        {
            if (!CacheList_.ContainsKey(Key))
            {
                return(Default);
            }

            if (CacheList_[Key] is T[,] Value)
            {
                var Len1    = Value.GetLength(0);
                var Len2    = Value.GetLength(1);
                var NewLen1 = Default?.GetLength(0) ?? Len1;
                var NewLen2 = Default?.GetLength(1) ?? Len2;

                if (Len1 < NewLen1 || Len2 < NewLen2)
                {
                    var NewValue = new T[NewLen1, NewLen2];

                    for (var X = 0; X < NewLen1; ++X)
                    {
                        for (var Y = 0; Y < NewLen2; ++Y)
                        {
                            if (X < Len1 && Y < Len2)
                            {
                                NewValue[X, Y] = Value[X, Y];
                            }
                            else
                            {
                                NewValue[X, Y] = Default[X, Y];
                            }
                        }
                    }

                    return(NewValue);
                }

                return(Value);
            }

            LLogger.LWarning($"archive type error : {Key} - {typeof(T)}");
            return(Default);
        }