/// <summary>
        /// 爆炸效果、伤害上传
        /// </summary>
        /// <param name="other"></param>
        /// <param name="boomPos"></param>
        public void OnTriggerEnter(Collider other, Vector3 boomPos)
        {
            // Log.Info("OnTriggerEnter");

            // layer = 9 是自己
            if (other.gameObject != null && other.gameObject.layer == 9)
            {
                return;
            }

            // 创建爆炸效果

            CreateBoomEffect(boomPos);

            Send_C2B_BoomEffect(boomPos);


            if (other.attachedRigidbody != null && other.attachedRigidbody.tag == Tag.Tank)
            {
                // 给坦克造成伤害

                TankComponent tankComponent = Game.Scene.GetComponent <TankComponent>();

                long objInstanceId = other.attachedRigidbody.gameObject.GetInstanceID();

                Tank beAttackTank = tankComponent.Get(objInstanceId);

                // 如果自己阵营,不造成伤害
                //if (beAttackTank.TankCamp == this.Tank.TankCamp)
                //    return;


                // 暂时只计算坦克自己造成的伤害,不计算炮弹造成的伤害
                int damage = this.m_tank.GetComponent <NumericComponent>()[NumericType.Atk];

                // beAttackTank.BeAttacked(this.Tank, damage);

                // 发送炮弹的玩家才向服务器通知
                if (this.m_tank.TankType == TankType.Local)
                {
                    Send_C2B_AttackTank(beAttackTank.Id, damage).NoAwait();
                }
            }

            //this.m_bullet.Dispose();
        }
        public void OnTriggerEnter(Collider other)
        {
            // Log.Info("OnTriggerEnter");

            // layer = 9 是自己
            if (other.gameObject != null && other.gameObject.layer == 9)
            {
                return;
            }


            // 创建爆炸效果

            ExplosionEffectFactory.Create(this.m_bullet.Position);


            if (other.attachedRigidbody != null && other.attachedRigidbody.tag == Tag.Tank)
            {
                // 给坦克造成伤害

                TankComponent tankComponent = Game.Scene.GetComponent <TankComponent>();

                long objInstanceId = other.attachedRigidbody.gameObject.GetInstanceID();

                Tank beAttackTank = tankComponent.Get(objInstanceId);

                // 如果自己阵营,不造成伤害
                //if (beAttackTank.TankCamp == this.Tank.TankCamp)
                //    return;

                int damage = this.m_bullet.AttackPower + this.Tank.GetComponent <NumericComponent>()[NumericType.Atk];

                // beAttackTank.BeAttacked(this.Tank, damage);

                // 发送炮弹的玩家才向服务器通知
                if (this.m_bullet.Tank.TankType == TankType.Local)
                {
                    Send_C2B_AttackTank(beAttackTank.Id, damage).NoAwait();
                }
            }

            this.m_bullet.Dispose();
        }
Exemple #3
0
        public override void Dispose()
        {
            if (this.IsDisposed)
            {
                return;
            }
            base.Dispose();

            foreach (Tank Tank in this.m_idTanks.Values)
            {
                Tank.Dispose();
            }



            this.m_idTanks.Clear();


            Instance = null;
        }
Exemple #4
0
        public static Tank Create(TankInfoFirstEnter firstInfo, Vector3 Pos, Vector3 Rot)
        {
            long id = firstInfo.TankFrameInfo.TankId;

            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();
            //Game.Scene.GetComponent<ResourcesComponent>().LoadBundle($"Unit.unity3d");
            GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset(AssetBundleName.Unit, PrefabName.Unit);
            //Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle($"Unit.unity3d");
            GameObject prefab = bundleGameObject.Get <GameObject>(PrefabName.Tank);

            TankComponent tankComponent = Game.Scene.GetComponent <TankComponent>();

            Tank tank = ComponentFactory.CreateWithId <Tank>(id);

            tank.GameObject = resourcesComponent.NewObj(PrefabType.Tank, prefab);

            tank.GameObject.transform.position = Pos;

            tank.GameObject.transform.eulerAngles = Rot;


            GameObject parent = GameObject.Find($"/Global/Unit");

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

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

            tank.Name = firstInfo.Name;

            tank.TankCamp = firstInfo.TankCamp;

            if (id == 10000 || PlayerComponent.Instance.MyPlayer.TankId == id)
            {
                tank.TankType = TankType.Local;

                tank.AddComponent <TankMoveComponent>();

                tank.AddComponent <CameraComponent>();

                tank.AddComponent <TurretComponent>();

                // 子弹管理组件
                tank.AddComponent <BulletComponent>();

                // 发射子弹的组件
                tank.AddComponent <TankShootComponent>();

                tank.AddComponent <LocalTankComponent>();

                tankComponent.MyTank = tank;

                // 如果是自己设置层级为9,为了让坦克不打中自己

                Utility.ChangeLayer(tank.GameObject, LayerNames.OwnTank);

                tank.GameObject.layer = 9;
            }
            else
            {
                tank.TankType = TankType.Remote;

                tank.AddComponent <RemoteTankComponent>();

                tank.AddComponent <TurretComponent>();

                tank.AddComponent <TankShootComponent>();

                tank.AddComponent <BulletComponent>();

                tank.AddComponent <OverHeadComponent>();
            }



            tankComponent.Add(tank);

            // 先将坦克加入TankComponent再赋值,因为赋值的时候会触发事件,事件中可能要从TankComponent中取坦克
            numericComponent[NumericType.MaxHpBase] = firstInfo.MaxHpBase;

            numericComponent[NumericType.HpBase] = firstInfo.HpBase;

            numericComponent[NumericType.AtkBase] = firstInfo.AtkBase;

            return(tank);
        }
Exemple #5
0
 public void Awake()
 {
     Instance = this;
 }