Beispiel #1
0
 public void InitStart()
 {
     PreInit.StartLoadLua();
     InitLuaPath();
     InitLuaBundle();
     PreInit.InitLuaFinish();
     this.lua.Start();    //启动LUAVM
     this.StartMain();
     this.StartLooper();
 }
Beispiel #2
0
        /// <summary>
        /// 资源初始化结束
        /// </summary>
        public void OnResourceInited()
        {
            PreInit.StartLoadRes();
#if ASYNC_MODE
            ResManager.Initialize(AppConst.AssetDir, delegate() {
                Debug.Log("Initialize OK!!!");
                this.OnInitialize();
            });
#else
            ResManager.Initialize();
            this.OnInitialize();
#endif
        }
Beispiel #3
0
        /// <summary>
        /// 释放资源
        /// </summary>
        public void CheckExtractResource()
        {
            PreInit.CheckExtRes();
            bool isExists = Directory.Exists(Util.DataPath) &&
                            Directory.Exists(Util.DataPath + "lua/") && File.Exists(Util.DataPath + "files.txt");

            if (isExists || AppConst.DebugMode)
            {
                PreInit.ExtResFinish();
                StartCoroutine(OnUpdateLuaResource());
                return;                          //文件已经解压过了,自己可添加检查文件列表逻辑
            }
            StartCoroutine(OnExtractResource()); //启动释放协成
        }
Beispiel #4
0
    void Awake()
    {
        if (EnableDebug)
        {
            PreInit  += () => Debug.Log("Pre-Initliazing...");
            Init     += () => Debug.Log("Initliazing...");
            PostInit += () => Debug.Log("Post-Initliazing...");
        }

        if (PreInit != null)
        {
            PreInit.Invoke();
        }
    }
Beispiel #5
0
        void OnInitialize()
        {
            PreInit.LoadResFinish();
            LuaManager.InitStart();
            LuaManager.DoFile("Logic/Game");         //加载游戏
            LuaManager.DoFile("Logic/Network");      //加载网络
            NetManager.OnInit();                     //初始化网络
            //Util.CallMethod("Game", "OnInitOK");     //初始化完成

            initialize = true;

            //类对象池测试
            var classObjPool = ObjPoolManager.CreatePool <TestObjectClass>(OnPoolGetElement, OnPoolPushElement);
            //方法1
            //objPool.Release(new TestObjectClass("abcd", 100, 200f));
            //var testObj1 = objPool.Get();

            //方法2
//            ObjPoolManager.Release<TestObjectClass>(new TestObjectClass("abcd", 100, 200f));
//            var testObj1 = ObjPoolManager.Get<TestObjectClass>();
//
//            Debugger.Log("TestObjectClass--->>>" + testObj1.ToString());
//
//            //游戏对象池测试
//            var prefab = Resources.Load("TestGameObjectPrefab", typeof(GameObject)) as GameObject;
//            var gameObjPool = ObjPoolManager.CreatePool("TestGameObject", 5, 10, prefab);
//
//            var gameObj = Instantiate(prefab) as GameObject;
//            gameObj.name = "TestGameObject_01";
//            gameObj.transform.localScale = Vector3.one;
//            gameObj.transform.localPosition = Vector3.zero;
//
//            ObjPoolManager.Release("TestGameObject", gameObj);
//            var backObj = ObjPoolManager.Get("TestGameObject");
//            backObj.transform.SetParent(null);
//
//            Debug.Log("TestGameObject--->>>" + backObj);
        }
Beispiel #6
0
 public void PreInit(PreInit preaInit)
 {
 }
Beispiel #7
0
 void Start()
 {
     PreInit.GameStartInit();
     AppFacade.Instance.StartUp();   //启动游戏
 }
Beispiel #8
0
        /// <summary>
        /// 将lua数据释放到可读写目录
        /// </summary>
        /// <returns></returns>
        IEnumerator OnExtractResource()
        {
            string dataPath = Util.DataPath;         //数据目录
            string resPath  = Util.AppContentPath(); //游戏包资源目录

            if (Directory.Exists(dataPath))
            {
                Directory.Delete(dataPath, true);
            }
            Directory.CreateDirectory(dataPath);

            string infile  = resPath + "files.txt";
            string outfile = dataPath + "files.txt";

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

            string message = "正在解包文件:>files.txt";

            Debug.Log(infile);
            Debug.Log(outfile);
            PreInit.ReleaseLuaRes();
            if (Application.platform == RuntimePlatform.Android)
            {
                WWW www = new WWW(infile);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(outfile, www.bytes);
                }
                yield return(0);
            }
            else
            {
                File.Copy(infile, outfile, true);
            }
            yield return(new WaitForEndOfFrame());

            //释放所有文件到数据目录
            string[] files = File.ReadAllLines(outfile);
            foreach (var file in files)
            {
                string[] fs = file.Split('|');
                infile  = resPath + fs[0]; //
                outfile = dataPath + fs[0];

                message = "正在解包文件:>" + fs[0];
                Debug.Log("正在解包文件:>" + infile);
                facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);

                string dir = Path.GetDirectoryName(outfile);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                if (Application.platform == RuntimePlatform.Android)
                {
                    WWW www = new WWW(infile);
                    yield return(www);

                    if (www.isDone)
                    {
                        File.WriteAllBytes(outfile, www.bytes);
                    }
                    yield return(0);
                }
                else
                {
                    if (File.Exists(outfile))
                    {
                        File.Delete(outfile);
                    }
                    File.Copy(infile, outfile, true);
                }
                yield return(new WaitForEndOfFrame());
            }


            string resInFile  = resPath + "resIndex.txt";
            string resOutFile = dataPath + "resIndex.txt";

            PreInit.ReleaseGameRes();
            if (File.Exists(resOutFile))
            {
                File.Delete(resOutFile);
            }
            if (Application.platform == RuntimePlatform.Android)
            {
                WWW www = new WWW(resInFile);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(resOutFile, www.bytes);
                }
                yield return(0);
            }
            else
            {
                File.Copy(resInFile, resOutFile, true);
            }

            string inApkInfo  = resPath + "versionInfo.xml";
            string outApkInfo = dataPath + "versionInfo.xml";

            if (File.Exists(outApkInfo))
            {
                File.Delete(outApkInfo);
            }
            if (Application.platform == RuntimePlatform.Android)
            {
                WWW www = new WWW(inApkInfo);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(outApkInfo, www.bytes);
                }
                yield return(0);
            }
            else
            {
                File.Copy(inApkInfo, outApkInfo, true);
            }

            //释放所有文件到数据目录
            string[] resFiles = File.ReadAllLines(resOutFile);
            foreach (var file in resFiles)
            {
                string[] fs = file.Split('|');
                resInFile  = resPath + "Android/" + fs[0]; //
                resOutFile = dataPath + "Android/" + fs[0];

                message = "正在解包文件:>" + fs[0];
                Debug.Log("正在解包文件:>" + resInFile);
                facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);
                string tarDir = Path.GetDirectoryName(resOutFile);
                if (!Directory.Exists(tarDir))
                {
                    Directory.CreateDirectory(tarDir);
                }

                if (Application.platform == RuntimePlatform.Android)
                {
                    WWW www = new WWW(resInFile);
                    yield return(www);

                    if (www.isDone)
                    {
                        File.WriteAllBytes(resOutFile, www.bytes);
                    }
                    yield return(0);
                }
                else
                {
                    if (File.Exists(resOutFile))
                    {
                        File.Delete(resOutFile);
                    }
                    File.Copy(resInFile, resOutFile, true);
                }
                yield return(new WaitForEndOfFrame());
            }

            yield return(new WaitForEndOfFrame());


            message = "解包完成!!!";
            facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);
            yield return(new WaitForSeconds(0.1f));

            message = string.Empty;
            PreInit.ExtResFinish();
            //释放完成,开始启动更新资源
            StartCoroutine(OnUpdateLuaResource());
        }
Beispiel #9
0
        /// <summary>
        /// 启动更新下载游戏差异资源
        /// </summary>
        IEnumerator OnUpdateGameResource()
        {
            PreInit.StartUpdateGameRes();
            string dataPath = Util.DataPath;  //数据目录
            string url      = AppConst.WebUrl;
            string message  = string.Empty;
            string random   = DateTime.Now.ToString("yyyymmddhhmmss");
            string listUrl  = url + "resIndex.txt?v=" + random;

            Debug.LogWarning("LoadUpdate---->>>" + listUrl);

            WWW www = new WWW(listUrl); yield return(www);

            if (www.error != null)
            {
                OnUpdateFailed(string.Empty);
                yield break;
            }
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            File.WriteAllBytes(dataPath + "resIndex.txt", www.bytes);
            string filesText = www.text;

            string[] files = filesText.Split('\n');
            for (int i = 0; i < files.Length; i++)
            {
                if (string.IsNullOrEmpty(files[i]))
                {
                    continue;
                }
                string[] keyValue  = files[i].Split('|');
                string   f         = keyValue[0];
                string   localfile = (dataPath + gamePlatform + "/" + f).Trim();
                string   path      = Path.GetDirectoryName(localfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string fileUrl   = url + gamePlatform + "/" + f + "?v=" + random;
                bool   canUpdate = !File.Exists(localfile);
                if (!canUpdate)
                {
                    string remoteMd5 = keyValue[1].Trim();
                    string localMd5  = Util.md5file(localfile);
                    canUpdate = !remoteMd5.Equals(localMd5);
                    if (canUpdate)
                    {
                        File.Delete(localfile);
                    }
                }
                if (canUpdate)
                {   //本地缺少文件
                    Debug.Log(fileUrl);
                    message = "downloading>>" + fileUrl;
                    facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);

                    /*
                     * www = new WWW(fileUrl); yield return www;
                     * if (www.error != null) {
                     *  OnUpdateFailed(path);   //
                     *  yield break;
                     * }
                     * File.WriteAllBytes(localfile, www.bytes);
                     */
                    //这里都是资源文件,用线程下载
                    BeginDownload(fileUrl, localfile);
                    while (!(IsDownOK(localfile)))
                    {
                        yield return(new WaitForEndOfFrame());
                    }
                }
            }
            yield return(new WaitForEndOfFrame());

            message = "更新完成!!";
            facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);

            OnResourceInited();
        }
Beispiel #10
0
 void OnLuaUpdateFinish()
 {
     PreInit.UpdateLuaResFinish();
     StartCoroutine(OnUpdateGameResource());
 }