添加成都双流圣菲学校场景
This commit is contained in:
@@ -63,6 +63,7 @@ public enum Place
|
||||
Hunan_Changde_Lixian_WandaGuangchang=39,
|
||||
Jilin_Changchun_Beihu_WuyueGuangchang = 41,
|
||||
Chongqing_Yuzhong_Hongyadong_Xiakexing=42,
|
||||
Chengdu_Shuangliu_ShengfeiXuexiao=43,
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,9 @@ public class GameManager : NetworkBehaviour
|
||||
public GameObject enemyPlanePre;
|
||||
|
||||
public GameObject[] playerNpcPre;
|
||||
|
||||
//public GameObject PathGuidePre;
|
||||
//public GuideArrowPath pathGuide;//引导路径
|
||||
// 怪物ui预制体
|
||||
public GameObject EnemyUIPre;
|
||||
#endregion
|
||||
@@ -167,7 +170,7 @@ public class GameManager : NetworkBehaviour
|
||||
[SyncVar]
|
||||
public long vistEnd = 0;
|
||||
// 总游玩时长
|
||||
private int vistAllTime = (int)(60*12 );
|
||||
private int vistAllTime = (int)(60*12);
|
||||
[SyncVar]
|
||||
public string settleData = "";
|
||||
|
||||
@@ -204,7 +207,7 @@ public class GameManager : NetworkBehaviour
|
||||
isStart = false;
|
||||
CreateDoor();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//修改处:添加创建AI角色的方法
|
||||
@@ -238,6 +241,8 @@ public class GameManager : NetworkBehaviour
|
||||
{
|
||||
//注册AI介绍完成回调
|
||||
aiController.OnIntroductionComplete += StartGameAfterIntroduction;
|
||||
// 新增:注册AI离开回调
|
||||
// aiController.OnIntroductionComplete += CreateGuidancePathToDoor;
|
||||
|
||||
//添加延迟,确保所有组件已经完成初始化
|
||||
StartCoroutine(DelayedStartIntroduction(aiController));
|
||||
@@ -258,6 +263,57 @@ public class GameManager : NetworkBehaviour
|
||||
yield return new WaitForSeconds(0.1f); // 短暂延迟
|
||||
aiController.StartIntroduction();
|
||||
}
|
||||
//// 新增:创建从玩家到门的指引路径
|
||||
//private void CreateGuidancePathToDoor()
|
||||
//{
|
||||
// Debug.Log("AI离开,创建从玩家到门的指引路径");
|
||||
|
||||
// // 确保玩家和门的位置存在
|
||||
// if (player == null || GameLocal.Ins.doorPos == null)
|
||||
// {
|
||||
// Debug.LogError("无法创建指引路径:玩家或门的位置为空");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // 创建指引路径
|
||||
// CreatePathGuide();
|
||||
|
||||
// // 设置路径从玩家位置到门的位置
|
||||
// Vector3 startPos = player.transform.position;
|
||||
// Vector3 endPos = GameLocal.Ins.doorPos.position;
|
||||
|
||||
// pathGuide.SetPath(startPos, endPos);
|
||||
// pathGuide.ShowPath();
|
||||
|
||||
// Debug.Log($"指引路径已创建:从 {startPos} 到 {endPos}");
|
||||
|
||||
// // 可选:在玩家到达门后自动关闭指引
|
||||
// StartCoroutine(CheckPlayerReachedDoor());
|
||||
//}
|
||||
|
||||
//// 新增:检查玩家是否到达门的位置
|
||||
//private IEnumerator CheckPlayerReachedDoor()
|
||||
//{
|
||||
// if (player == null || GameLocal.Ins.doorPos == null) yield break;
|
||||
|
||||
// float arrivalDistance = 2.0f; // 到达门的判定距离
|
||||
|
||||
// while (pathGuide != null && pathGuide.gameObject.activeInHierarchy)
|
||||
// {
|
||||
// float distanceToDoor = Vector3.Distance(player.transform.position, GameLocal.Ins.doorPos.position);
|
||||
|
||||
// if (distanceToDoor <= arrivalDistance)
|
||||
// {
|
||||
// Debug.Log("玩家已到达门的位置,关闭指引路径");
|
||||
// ClosePathGuide();
|
||||
// yield break;
|
||||
// }
|
||||
|
||||
// yield return new WaitForSeconds(0.5f); // 每0.5秒检查一次
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Ins = this;
|
||||
@@ -358,6 +414,42 @@ public class GameManager : NetworkBehaviour
|
||||
}
|
||||
|
||||
[Server]
|
||||
//public void PlayEndEvent()
|
||||
//{
|
||||
// Debug.LogError("开启End事件");
|
||||
// gameState = GameState.EndEvent;
|
||||
// GivePistol(GunType.MeleeWeapon);
|
||||
// foreach (var item in PlayerAiList.Values)
|
||||
// {
|
||||
// item.EndEvent();
|
||||
// }
|
||||
// PlaySound2DRPC("1.61");
|
||||
// OpenDoor();
|
||||
// for (int i = 0; i < 7; i++)
|
||||
// {
|
||||
// Transform[] targetPos = GameLocal.Ins.enemyEndPos;
|
||||
// GameObject enemy = Instantiate(enemyEndAiPre);
|
||||
// NetworkServer.Spawn(enemy);
|
||||
// int posId =i/3;
|
||||
// enemy.transform.position = GameLocal.Ins.enemyStartPos[posId].position;
|
||||
// enemy.transform.eulerAngles = targetPos[posId].eulerAngles;
|
||||
// enemyIndex++;
|
||||
// Enemy enemyScript = enemy.GetComponent<Enemy>();
|
||||
// enemyScript.OnSpawn(enemyIndex, 3, 1,GameLocal.Ins.pkPos.position);
|
||||
// enemyScript.ai.maxSpeed = 2;
|
||||
// EnemyList.Add(enemyIndex, enemyScript);
|
||||
|
||||
// GameObject playerAi = Instantiate(playerEndAiPres);
|
||||
// NetworkServer.Spawn(playerAi);
|
||||
// playerAi.transform.position = GameLocal.Ins.endPlayerStartPos.position;
|
||||
// playerAi.transform.eulerAngles = AiInfos[1].EulerAngles;
|
||||
// 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;
|
||||
//}
|
||||
public void PlayEndEvent()
|
||||
{
|
||||
Debug.LogError("开启End事件");
|
||||
@@ -369,32 +461,123 @@ public class GameManager : NetworkBehaviour
|
||||
}
|
||||
PlaySound2DRPC("1.61");
|
||||
OpenDoor();
|
||||
|
||||
// 定义3x3范围的中心点和大小
|
||||
Vector3 centerPos = GameLocal.Ins.pkPos.position;
|
||||
float areaSize = 3f; // 3x3的范围
|
||||
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
Transform[] targetPos = GameLocal.Ins.enemyEndPos;
|
||||
GameObject enemy = Instantiate(enemyEndAiPre);
|
||||
NetworkServer.Spawn(enemy);
|
||||
int posId =i/3;
|
||||
enemy.transform.position = GameLocal.Ins.enemyStartPos[posId].position;
|
||||
enemy.transform.eulerAngles = targetPos[posId].eulerAngles;
|
||||
|
||||
// 检查是否为指定场地
|
||||
if (GameLocal.Ins.place == Place.Jiangsu_Xvzhou_Guolou_Oulebao)
|
||||
{
|
||||
// 在3x3范围内随机生成位置
|
||||
Vector3 randomOffset = new Vector3(
|
||||
Random.Range(-areaSize / 2f, areaSize / 2f),
|
||||
0,
|
||||
Random.Range(-areaSize / 2f, areaSize / 2f)
|
||||
);
|
||||
enemy.transform.position = centerPos + randomOffset;
|
||||
enemy.transform.eulerAngles = Vector3.zero; // 或者设置随机朝向
|
||||
}
|
||||
else
|
||||
{
|
||||
// 原有逻辑
|
||||
int posId = i / 3;
|
||||
enemy.transform.position = GameLocal.Ins.enemyStartPos[posId].position;
|
||||
enemy.transform.eulerAngles = targetPos[posId].eulerAngles;
|
||||
}
|
||||
|
||||
enemyIndex++;
|
||||
Enemy enemyScript = enemy.GetComponent<Enemy>();
|
||||
enemyScript.OnSpawn(enemyIndex, 3, 1,GameLocal.Ins.pkPos.position);
|
||||
enemyScript.OnSpawn(enemyIndex, 3, 1, GameLocal.Ins.pkPos.position);
|
||||
enemyScript.ai.maxSpeed = 2;
|
||||
EnemyList.Add(enemyIndex, enemyScript);
|
||||
|
||||
|
||||
GameObject playerAi = Instantiate(playerEndAiPres);
|
||||
NetworkServer.Spawn(playerAi);
|
||||
playerAi.transform.position = GameLocal.Ins.endPlayerStartPos.position;
|
||||
playerAi.transform.eulerAngles = AiInfos[1].EulerAngles;
|
||||
|
||||
// 检查是否为指定场地
|
||||
if (GameLocal.Ins.place == Place.Jiangsu_Xvzhou_Guolou_Oulebao)
|
||||
{
|
||||
// 在3x3范围内随机生成位置,确保与敌人位置不重叠
|
||||
Vector3 randomOffset;
|
||||
bool positionValid;
|
||||
int attempts = 0;
|
||||
|
||||
do
|
||||
{
|
||||
randomOffset = new Vector3(
|
||||
Random.Range(-areaSize / 2f, areaSize / 2f),
|
||||
0,
|
||||
Random.Range(-areaSize / 2f, areaSize / 2f)
|
||||
);
|
||||
|
||||
// 检查是否与现有单位位置太近
|
||||
positionValid = true;
|
||||
Vector3 proposedPos = centerPos + randomOffset;
|
||||
|
||||
foreach (var existingEnemy in EnemyList.Values)
|
||||
{
|
||||
if (Vector3.Distance(proposedPos, existingEnemy.transform.position) < 0.8f) // 稍微减小最小距离
|
||||
{
|
||||
positionValid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
attempts++;
|
||||
if (attempts > 15) break; // 增加尝试次数
|
||||
|
||||
} while (!positionValid);
|
||||
|
||||
playerAi.transform.position = centerPos + randomOffset;
|
||||
playerAi.transform.eulerAngles = Vector3.zero; // 或者设置随机朝向
|
||||
}
|
||||
else
|
||||
{
|
||||
// 原有逻辑
|
||||
playerAi.transform.position = GameLocal.Ins.endPlayerStartPos.position;
|
||||
playerAi.transform.eulerAngles = AiInfos[1].EulerAngles;
|
||||
}
|
||||
|
||||
PlayerAI playerAI = playerAi.GetComponent<PlayerAI>();
|
||||
playerAI.OnSpawn(i+2,PlayerAIType.EndPlayerAi, 1,enemy);
|
||||
playerAI.OnSpawn(i + 2, PlayerAIType.EndPlayerAi, 1, enemy);
|
||||
playerAI.ai.maxSpeed = 2;
|
||||
PlayerAiList.Add(i+2, playerAI);
|
||||
PlayerAiList.Add(i + 2, playerAI);
|
||||
}
|
||||
|
||||
curRoundEnemyCount = EnemyList.Count;
|
||||
|
||||
// 可选:在指定场地时添加调试可视化
|
||||
if (GameLocal.Ins.place == Place.Jiangsu_Xvzhou_Guolou_Oulebao)
|
||||
{
|
||||
Debug.Log($"在场地 {GameLocal.Ins.place} 中,所有单位已生成在3x3范围内,中心点: {centerPos}");
|
||||
|
||||
// 可视化3x3范围(仅在编辑器中)
|
||||
#if UNITY_EDITOR
|
||||
DrawDebugArea(centerPos, areaSize);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// 调试用:绘制3x3区域
|
||||
private void DrawDebugArea(Vector3 center, float size)
|
||||
{
|
||||
Vector3 bottomLeft = center + new Vector3(-size / 2, 0, -size / 2);
|
||||
Vector3 bottomRight = center + new Vector3(size / 2, 0, -size / 2);
|
||||
Vector3 topLeft = center + new Vector3(-size / 2, 0, size / 2);
|
||||
Vector3 topRight = center + new Vector3(size / 2, 0, size / 2);
|
||||
|
||||
Debug.DrawLine(bottomLeft, bottomRight, Color.red, 10f);
|
||||
Debug.DrawLine(bottomRight, topRight, Color.red, 10f);
|
||||
Debug.DrawLine(topRight, topLeft, Color.red, 10f);
|
||||
Debug.DrawLine(topLeft, bottomLeft, Color.red, 10f);
|
||||
}
|
||||
[ClientRpc]
|
||||
public void OpenDoor()
|
||||
{
|
||||
@@ -1310,5 +1493,26 @@ public class GameManager : NetworkBehaviour
|
||||
MasterAudio.PlaySound(JointIn);
|
||||
GameLocal.Ins.BGMState.StateChange(2);
|
||||
}
|
||||
//#region 引导系统
|
||||
//public void CreatePathGuide()
|
||||
//{
|
||||
// var pathGuideObj = Instantiate(PathGuidePre);
|
||||
// pathGuide = pathGuideObj.GetComponent<GuideArrowPath>();
|
||||
// pathGuide.ClosePath();
|
||||
//}
|
||||
|
||||
//public void ShowPathGuide()
|
||||
//{
|
||||
// pathGuide.ShowPath();
|
||||
|
||||
|
||||
//}
|
||||
|
||||
//public void ClosePathGuide()
|
||||
//{
|
||||
// pathGuide.ClosePath();
|
||||
//}
|
||||
|
||||
//#endregion
|
||||
}
|
||||
|
||||
|
||||
@@ -33,13 +33,14 @@ public enum HandState
|
||||
|
||||
public class Player : NetworkRoomPlayer,IDamagable
|
||||
{
|
||||
|
||||
public Transform LeftHand;
|
||||
public Transform RightHand;
|
||||
public Transform Aim;
|
||||
|
||||
public Collider Collider;
|
||||
public LayerMask AimLayer;
|
||||
|
||||
|
||||
[SyncVar]
|
||||
public bool isDie;
|
||||
|
||||
@@ -204,6 +205,7 @@ public class Player : NetworkRoomPlayer,IDamagable
|
||||
other.gameObject.SetActive(false);
|
||||
NetworkServer.Destroy(other.gameObject);
|
||||
GameManager.Ins.GameStart();
|
||||
|
||||
}
|
||||
|
||||
if (other.tag == "WeaponProp")
|
||||
@@ -491,6 +493,8 @@ public class Player : NetworkRoomPlayer,IDamagable
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user