Exemple #1
0
        public static Bullet Create(Tank tank)
        {
            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();

            Game.Scene.GetComponent <ResourcesComponent>().LoadBundle($"Unit.unity3d");
            GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");

            Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle($"Unit.unity3d");
            GameObject prefab = bundleGameObject.Get <GameObject>("Bullet");

            BulletComponent bulletComponent = tank.GetComponent <BulletComponent>();


            Bullet bullet = ComponentFactory.CreateWithId <Bullet, Tank>(IdGenerater.GenerateId(), tank);



            bullet.GameObject = resourcesComponent.NewObj(PrefabType.Bullet, prefab);

            GameObject parent = tank.GameObject.FindChildObjectByPath("bullets");

            bullet.GameObject.transform.SetParent(parent.transform, false);

            bulletComponent.Add(bullet);

            BulletCollision bulletCollision = bullet.GameObject.AddComponent <BulletCollision>();

            // 子弹添加飞行
            bulletCollision.BulletFly = bullet.AddComponent <BulletFlyComponent>();


            return(bullet);
        }
Exemple #2
0
        private async ETVoid HeartBeat30ms()
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                await timerComponent.WaitAsync(30, CancellationTokenSource.Token);

                if (m_tank.Died)
                {
                    continue;
                }


                C2B_TankFrameInfo tankInfo = new C2B_TankFrameInfo();

                tankInfo.TankFrameInfo = new TankFrameInfo();


                tankInfo.TankFrameInfo.TankId = m_tank.Id;

                int m_coefficient = Tank.m_coefficient;

                tankInfo.TankFrameInfo.PX = Convert.ToInt32(m_tank.Position.x * m_coefficient);
                tankInfo.TankFrameInfo.PY = Convert.ToInt32(this.m_tank.Position.y * m_coefficient);
                tankInfo.TankFrameInfo.PZ = Convert.ToInt32(m_tank.Position.z * m_coefficient);

                tankInfo.TankFrameInfo.RX = Convert.ToInt32(m_tank.GameObject.transform.eulerAngles.x * m_coefficient);
                tankInfo.TankFrameInfo.RY = Convert.ToInt32(m_tank.GameObject.transform.eulerAngles.y * m_coefficient);
                tankInfo.TankFrameInfo.RZ = Convert.ToInt32(m_tank.GameObject.transform.eulerAngles.z * m_coefficient);

                TurretComponent turretComponent = m_tank.GetComponent <TurretComponent>();


                tankInfo.TankFrameInfo.TurretRY = Convert.ToInt32(turretComponent.RotTarget * m_coefficient);
                tankInfo.TankFrameInfo.GunRX    = Convert.ToInt32(turretComponent.RollTarget * m_coefficient);

                //Log.Warning("发送成功");

                SessionComponent.Instance.Session.Send(tankInfo);
            }
        }
Exemple #3
0
        public void Run(long battleId, long tankId, NumericType changeType)
        {
            try
            {
                Tank tank = Game.Scene.GetComponent <BattleComponent>().Get(battleId).Get(tankId);
                if (tank == null)
                {
                    return;
                }

                NumericComponent numericComponent = tank.GetComponent <NumericComponent>();

                if (numericComponent == null)
                {
                    Log.Error($"未添加NumericComponent组件");
                    return;
                }

                int nowHp = numericComponent[NumericType.Hp];

                if (nowHp <= 0)
                {
                    tank.Died = true;



                    if (tank.Battle.BigMode == BigModel.Time)
                    {
                        tank.Battle.TimeResetTank(tank).NoAwait();
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }