Inheritance: UnityEngine.MonoBehaviour
Exemple #1
0
        public bool Update(int msc)
        {
            Init init = new Init(objects, mapWidth, mapHeight);

            timer += msc;

            objects.Player.Update(timer);
            // Create new apple
            if (objects.Apples.Count < 5 && random.Next(300) > 250)
            {
                init.InitApple();
            }
            // Create new enemy
            if (objects.Enemies.Count < 5 && random.Next(300) > 250)
            {
                init.InitEnemies();
            }
            // Random change enemy's direction
            foreach (var enemy in objects.Enemies)
            {
                if (random.Next(300) > 295)
                {
                    ChangeEnemyDirection(new Init(objects, mapWidth, mapHeight).RandomDirection(), enemy);
                }
                enemy.Update(timer);
            }

            Move();

            // Check Collisions
            if (collisions.CheckCollisions(objects, mapWidth, mapHeight, ref score))
            {
                GameOver();
                return(gameOver);
            }

            return(gameOver);
        }
Exemple #2
0
        private async void Start()
        {
            try
            {
                if (Application.unityVersion != "2017.1.0p5")
                {
                    Log.Error("请使用Unity2017.1.0p5版本");
                }

                DontDestroyOnLoad(gameObject);
                Instance = this;


                Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly);

                Game.Scene.AddComponent <GlobalConfigComponent>();
                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <NetOuterComponent>();
                Game.Scene.AddComponent <ResourcesComponent>();
                Game.Scene.AddComponent <BehaviorTreeComponent>();
                Game.Scene.AddComponent <PlayerComponent>();
                Game.Scene.AddComponent <UnitComponent>();
                Game.Scene.AddComponent <ClientFrameComponent>();
                Game.Scene.AddComponent <UIComponent>();


                // 下载ab包
                await BundleHelper.DownloadBundle();

                // 加载配置
                Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d");
                Game.Scene.AddComponent <ConfigComponent>();
                Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d");

                Game.Scene.AddComponent <MessageDispatherComponent>();
#if ILRuntime
                Log.Debug("run in ilruntime mode");

                this.AppDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
                Game.Scene.GetComponent <ResourcesComponent>().LoadBundle($"code.unity3d");
                Game.EventSystem.LoadHotfixDll();
                Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle($"code.unity3d");
                ILHelper.InitILRuntime();

                this.start             = new ILStaticMethod("Hotfix.Init", "Start", 0);
                this.update            = new ILStaticMethod("Hotfix.Init", "Update", 0);
                this.lateUpdate        = new ILStaticMethod("Hotfix.Init", "LateUpdate", 0);
                this.onApplicationQuit = new ILStaticMethod("Hotfix.Init", "OnApplicationQuit", 0);
#else
                Log.Debug("run in mono mode");
                Game.Scene.GetComponent <ResourcesComponent>().LoadBundle($"code.unity3d");
                Game.EventSystem.LoadHotfixDll();
                Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle($"code.unity3d");
                Type hotfixInit = Game.EventSystem.HotfixAssembly.GetType("Hotfix.Init");
                this.start             = new MonoStaticMethod(hotfixInit, "Start");
                this.update            = new MonoStaticMethod(hotfixInit, "Update");
                this.lateUpdate        = new MonoStaticMethod(hotfixInit, "LateUpdate");
                this.onApplicationQuit = new MonoStaticMethod(hotfixInit, "OnApplicationQuit");
#endif

                // 进入热更新层
                this.start.Run();

                Game.EventSystem.Run(EventIdType.InitSceneStart);
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
        }
Exemple #3
0
 private void OnApplicationQuit()
 {
     Instance = null;
     Game.Close();
     this.onApplicationQuit?.Run();
 }
Exemple #4
0
 private void OnApplicationQuit()
 {
     Instance = null;
     Game.Close();
     this.HotfixOnApplicationQuit?.Invoke();
 }