fix:调整联机问题。调整最后一波拼刀问题

This commit is contained in:
bzx
2025-10-11 18:34:10 +08:00
parent b8cb472404
commit 7b1c3a025d
52 changed files with 299667 additions and 12475 deletions

View File

@@ -167,7 +167,7 @@ public class GameManager : NetworkBehaviour
[SyncVar]
public long vistEnd = 0;
// 总游玩时长
private int vistAllTime = (int)(60*15 );
private int vistAllTime = (int)(60*12 );
[SyncVar]
public string settleData = "";
@@ -253,7 +253,7 @@ public class GameManager : NetworkBehaviour
{
//GameOver(GameState.Settle);
StartSpecialEvent(GameEnemyEventType.CleanUp);
}, 60f * 13f);
}, vistAllTime);
}
[ClientRpc]
@@ -294,7 +294,7 @@ public class GameManager : NetworkBehaviour
item.EndEvent();
}
PlaySound2DRPC("1.61");
GameLocal.Ins.OpenDoor();
OpenDoor();
for (int i = 0; i < 7; i++)
{
Transform[] targetPos = GameLocal.Ins.enemyEndPos;
@@ -308,25 +308,23 @@ public class GameManager : NetworkBehaviour
enemyScript.OnSpawn(enemyIndex, 3, 1,GameLocal.Ins.pkPos.position);
enemyScript.ai.maxSpeed = 2;
EnemyList.Add(enemyIndex, enemyScript);
}
for (int i = 0; i < 7; i++)
{
GameObject playerAi = Instantiate(playerEndAiPres);
NetworkServer.Spawn(playerAi);
playerAi.transform.position = GameLocal.Ins.endPlayerStartPos.position;
playerAi.transform.eulerAngles = AiInfos[1].EulerAngles;
PlayerAI enemyScript = playerAi.GetComponent<PlayerAI>();
enemyScript.OnSpawn(i+2,PlayerAIType.EndPlayerAi, 1,GetEnemy(playerAi.transform));
enemyScript.ai.maxSpeed = 2;
PlayerAiList.Add(i+2, enemyScript);
PlayerAI playerAI = playerAi.GetComponent<PlayerAI>();
playerAI.OnSpawn(i+2,PlayerAIType.EndPlayerAi, 1,enemy);
playerAI.ai.maxSpeed = 2;
PlayerAiList.Add(i+2, playerAI);
}
curRoundEnemyCount = EnemyList.Count;
}
[Server]
public void ChangePlayerAiKillTime()
[ClientRpc]
public void OpenDoor()
{
GameLocal.Ins.OpenDoor();
}
[ClientRpc]
@@ -427,31 +425,33 @@ public class GameManager : NetworkBehaviour
{
if (gameMode == GameMode.OnePlayer)
{
for (int i = 0; i < 2; i++)
{
GameObject playerAi = Instantiate(playerAiPres[i]);
NetworkServer.Spawn(playerAi);
playerAi.transform.position = GameLocal.Ins.playerAiPos[i].position;
playerAi.transform.eulerAngles = AiInfos[i+1].EulerAngles;
PlayerAI enemyScript = playerAi.GetComponent<PlayerAI>();
enemyScript.OnSpawn(i,(PlayerAIType)i, 1,GameLocal.Ins.playerAiEndPos[i].gameObject);
PlayerAiList.Add(i, enemyScript);
}
}
else if(gameMode == GameMode.TwoPlayers)
for (int i = 0; i < 2; i++)
{
GameObject playerAi = Instantiate(playerAiPres[0]);
GameObject playerAi = Instantiate(playerAiPres[i]);
NetworkServer.Spawn(playerAi);
playerAi.transform.position = GameLocal.Ins.playerAiPos[0].position;
playerAi.transform.eulerAngles = AiInfos[1].EulerAngles;
playerAi.transform.position = GameLocal.Ins.playerAiPos[i].position;
playerAi.transform.eulerAngles = AiInfos[i+1].EulerAngles;
PlayerAI enemyScript = playerAi.GetComponent<PlayerAI>();
enemyScript.OnSpawn(0,0, 1,GameLocal.Ins.playerAiEndPos[0].gameObject);
PlayerAiList.Add(0, enemyScript);
enemyScript.OnSpawn(i,(PlayerAIType)i, 1,GameLocal.Ins.playerAiEndPos[i].gameObject);
PlayerAiList.Add(i, enemyScript);
}
// else if(gameMode == GameMode.TwoPlayers)
// {
// GameObject playerAi = Instantiate(playerAiPres[0]);
// NetworkServer.Spawn(playerAi);
// playerAi.transform.position = GameLocal.Ins.playerAiPos[0].position;
// playerAi.transform.eulerAngles = AiInfos[1].EulerAngles;
// PlayerAI enemyScript = playerAi.GetComponent<PlayerAI>();
// enemyScript.OnSpawn(0,0, 1,GameLocal.Ins.playerAiEndPos[0].gameObject);
// PlayerAiList.Add(0, enemyScript);
// }
}
#region
[Server]
public void CreateExplosion(Vector3 pos,EnemyType type)
{
if(!isServer)
@@ -505,15 +505,12 @@ public class GameManager : NetworkBehaviour
public List<Enemy> GetRoundEnemy()
{
List<Enemy> curEnemyList = new List<Enemy>();
int curRoundIndex=Random.Range(1,RoundInfos.Count);
var roundInfo=roundIndex <= 2? RoundInfos[0]: RoundInfos[curRoundIndex];
int curRoundIndex=roundIndex>= RoundInfos.Count? Random.Range(1,RoundInfos.Count):roundIndex;
var roundInfo=RoundInfos[curRoundIndex];
// curRoundIndex=5;
// roundInfo= RoundInfos[curRoundIndex];
roundIndex = curRoundIndex;
StartEvent(roundInfo);
if (roundIndex == 5)
if (roundIndex%5==0&&roundIndex!=0)
{
CoroutineTaskManager.Instance.WaitSecondTodo(() =>
{
@@ -639,7 +636,7 @@ public class GameManager : NetworkBehaviour
{
if (Input.GetKeyDown(KeyCode.Space))
{
GameLocal.Ins.OpenDoor();
StartSpecialEvent(GameEnemyEventType.CleanUp);
}
}
@@ -687,16 +684,16 @@ public class GameManager : NetworkBehaviour
}
}
public Enemy GetEnemy(EnemyType type)
[ClientRpc]
public void OpenEndBullet()
{
foreach (var item in EnemyList.Values)
{
if (item.type == type)
{
return item;
}
}
return null;
GameLocal.Ins.OpenEndBullet();
}
[ClientRpc]
public void DownEndBullet()
{
GameLocal.Ins.DownEndBullet();
}
public List<Enemy> NpcEnemyList = new List<Enemy>();
@@ -749,7 +746,7 @@ public class GameManager : NetworkBehaviour
NetworkServer.Spawn(enemy);
enemy.GetComponent<Enemy>().OnSpawn(-j, 3, -1, GameLocal.Ins.npcPos[posId].position);
enemy.GetComponent<Enemy>().outline.enabled = true;
enemy.GetComponent<Enemy>().isOutLine = true;
NpcEnemyList.Add(enemy.GetComponent<Enemy>());
}
}
@@ -758,20 +755,8 @@ public class GameManager : NetworkBehaviour
public void CreateEnemyEndBullet()
{
// for (int i = 0; i < 8; i++)
// {
// if(!isStart)
// return;
// var item= Instantiate(endBulletPre);
// NetworkServer.Spawn(item);
// int z = Random.Range(-5, 5);
// int x = Random.Range(-5, 5);
// item.transform.position=GameLocal.Ins.endBulletPos.position+new Vector3(x,0,z);
// item.GetComponent<CleanBullet>().Launch();
// }
PlayerAiList[0].PlaySound3DRPC("1.65",true);
GameLocal.Ins.OpenEndBullet();
OpenEndBullet();
CoroutineTaskManager.Instance.WaitSecondTodo(() =>
{
foreach (var item in EnemyList.Values)
@@ -786,7 +771,7 @@ public class GameManager : NetworkBehaviour
CoroutineTaskManager.Instance.WaitSecondTodo(() =>
{
PlayEndEvent();
GameLocal.Ins.DownEndBullet();
DownEndBullet();
}, 8);
}
@@ -806,7 +791,7 @@ public class GameManager : NetworkBehaviour
{
if (enemy.type == type)
{
enemy.outline.enabled = true;
enemy.isOutLine = true;
}
}
}
@@ -968,9 +953,37 @@ public class GameManager : NetworkBehaviour
}
/// <summary>
/// 获取最近的玩家
/// 获取最近的Ai
/// </summary>
/// <returns></returns>
public GameObject GetPlayerAi(Transform curTransform)
{
if (PlayerAiList.Count==0 )
return null;
GameObject nearestPlayer = null;
float minDistance = float.MaxValue;
foreach (var player in PlayerAiList)
{
if (player.Value == null|| player.Key<=1|| player.Value.isGet) continue;
// 计算XZ平面距离使用你的 ReflectVectorXOZ 方法)
float dis = Vector3.Distance(
player.Value.transform.position.ReflectVectorXOZ(),
curTransform.position.ReflectVectorXOZ()
);
if (dis < minDistance)
{
minDistance = dis;
player.Value.isGet = true;
nearestPlayer = player.Value.gameObject;
}
}
return nearestPlayer;
}
public GameObject GetPlayer(Transform curTransform)
{
if (players == null || players.Count == 0)