/// <summary> /// 玩家控制的方块攻击了一次 /// </summary> public void cubeAttack() { //Debug.LogError("需要攻击"); CubeBullet cubeBullet = CubeBulletFactory.CreateCubeBullet(); cubeBullet.Attack(cubeGun_Transform.gameObject, attackObject, cubePlayer_Controller.velocity); playerCubeNetComponent.needSyncBullet.Enqueue(cubeBullet); }
/// <summary> /// 发送一次网络包 /// </summary> public void sendNetPostion() { NetPackge.PositionX = cube_Transform.position.x; NetPackge.PositionY = cube_Transform.position.y; NetPackge.PositionZ = cube_Transform.position.z; NetPackge.RotationX = body_Transform.rotation.x; NetPackge.RotationY = body_Transform.rotation.y; NetPackge.RotationZ = body_Transform.rotation.z; NetPackge.RotationW = body_Transform.rotation.w; NetPackge.VelocityX = cube_CharacterController.velocity.x; NetPackge.VelocityY = cube_CharacterController.velocity.y; NetPackge.VelocityZ = cube_CharacterController.velocity.z; NetPackge.Fire = playerCubeAttackComponent.isAttacking(); int count = needSyncBullet.Count; for (int i = 0; i < count; i++) { CubeBullet cubeBullet = needSyncBullet.Dequeue(); if (cubeBullet.bulletFlying) { BulletInfo bulletInfo = new BulletInfo(); bulletInfo.Account = playerAccount; bulletInfo.PositionX = cubeBullet.bulletObj[1].transform.position.x; bulletInfo.PositionY = cubeBullet.bulletObj[1].transform.position.y; bulletInfo.PositionZ = cubeBullet.bulletObj[1].transform.position.z; bulletInfo.RotationX = cubeBullet.bulletObj[1].transform.rotation.x; bulletInfo.RotationY = cubeBullet.bulletObj[1].transform.rotation.y; bulletInfo.RotationZ = cubeBullet.bulletObj[1].transform.rotation.z; bulletInfo.RotationW = cubeBullet.bulletObj[1].transform.rotation.w; Vector3 velocity = cubeBullet.bulletObj[1].GetComponent <Rigidbody>().velocity; bulletInfo.VelocityX = velocity.x; bulletInfo.VelocityY = velocity.y; bulletInfo.VelocityZ = velocity.z; NetPackge.Bullets.Add(bulletInfo); } } //玩家活着才发包 if (!playerCube.PlayerDie) { hotfixSession.Send(NetPackge); } NetPackge.Bullets.Clear(); }
public static CubeBullet CreateCubeBullet() { if (rc == null) { assetRequest = Assets.LoadAsset("Assets/Bundles/Prefab/BulletFX.prefab", typeof(GameObject)); GameObject bundleGameObject = assetRequest.asset as GameObject; rc = bundleGameObject.GetComponent <ReferenceCollector>(); } if (hurtSyncComponent == null) { hurtSyncComponent = MapHelper.nowPlayerCube.GetComponent <HurtSyncComponent>(); } //池里至少有5个才取 if (cubeBulletPool.Count > 5) { CubeBullet cubeBullet = cubeBulletPool.Dequeue(); return(cubeBullet); } else { GameObject[] bulletObj = new GameObject[3] { GameObject.Instantiate <GameObject>(rc.Get <GameObject>("gunFire")), GameObject.Instantiate <GameObject>(rc.Get <GameObject>("bullet")), GameObject.Instantiate <GameObject>(rc.Get <GameObject>("hitEffect")) }; CubeBullet cubeBullet = ComponentFactory.Create <CubeBullet, GameObject[]>(bulletObj, false); cubeBullet.hurtSyncComponent = hurtSyncComponent; for (int i = 0; i < bulletObj.Length; i++) { bulletObj[i].transform.parent = cubeBullet.GameObject.transform; } //设置实体的管理组件 cubeBullet.Parent = Game.Scene.GetComponent <CubeBulletManagerComponent>(); return(cubeBullet); } }
protected override async ETTask Run(ETModel.Session session, G2C_OtherPlayerPosition message) { if (otherCubeManagerComponent == null) { otherCubeManagerComponent = Game.Scene.GetComponent <OtherCubeManagerComponent>(); } if (message.ServerTime > serverTime) { serverTime = message.ServerTime; int[] DirAccount = message.DirAccount.array; float[] PositionX = message.PositionX.array; float[] PositionY = message.PositionY.array; float[] PositionZ = message.PositionZ.array; float[] RotationX = message.RotationX.array; float[] RotationY = message.RotationY.array; float[] RotationZ = message.RotationZ.array; float[] RotationW = message.RotationW.array; float[] VelocityX = message.VelocityX.array; float[] VelocityY = message.VelocityY.array; float[] VelocityZ = message.VelocityZ.array; bool[] Fire = message.Fire.array; for (int i = 0; i < DirAccount.Length; i++) { OtherCubeNetSyncComponent otherCubeNetSyncComponent = otherCubeManagerComponent.GetNetSyncComponentByOtherCubeAccount(DirAccount[i]); if (otherCubeNetSyncComponent != null) { otherCubeNetSyncComponent.NetWorkAsyncPosition(new Vector3(PositionX[i], PositionY[i], PositionZ[i]), new Quaternion(RotationX[i], RotationY[i], RotationZ[i], RotationW[i]), new Vector3(VelocityX[i], VelocityY[i], VelocityZ[i])); //Log.Info("同步一次位置:" + DirAccount[i]); otherCubeNetSyncComponent.NetWorkAsyncFire(Fire[i]); } } PlayerInfoComponent playerInfoComponent = Game.Scene.GetComponent <PlayerInfoComponent>(); //if (message.Bullets.array.Length != 0) //{ // Debug.LogError("子弹数量:" + message.Bullets.count); //} //同步子弹数量 int count = message.Bullets.count; for (int i = 0; i < count; i++) { //不是自己的子弹才需要创建同步 if (message.Bullets[i].Account != playerInfoComponent.account) { CubeBullet cubeBullet = CubeBulletFactory.CreateCubeBullet(); cubeBullet.SyncBullet(new Vector3(message.Bullets[i].PositionX, message.Bullets[i].PositionY, message.Bullets[i].PositionZ), new Quaternion(message.Bullets[i].RotationX, message.Bullets[i].RotationY, message.Bullets[i].RotationZ, message.Bullets[i].RotationW), new Vector3(message.Bullets[i].VelocityX, message.Bullets[i].VelocityY, message.Bullets[i].VelocityZ)); //Debug.LogError("创建一颗子弹"); } } } else { Debug.LogError("丢包了: " + message.ServerTime + " || " + serverTime); } await ETTask.CompletedTask; }
/// <summary> /// CubeBullet回收进池 /// </summary> public static void CubeBulletEnPool(CubeBullet cubeBullet) { cubeBulletPool.Enqueue(cubeBullet); }