diff --git a/Assets/Plugins/Android/AndroidManifest.xml b/Assets/Plugins/Android/AndroidManifest.xml index a1f7cf3a..55bcbb58 100644 --- a/Assets/Plugins/Android/AndroidManifest.xml +++ b/Assets/Plugins/Android/AndroidManifest.xml @@ -9,7 +9,7 @@ - + diff --git a/Assets/_DefendNJ/Scenes/Yunnan_Lincang_Linxiang_Hengji_Dixia.unity b/Assets/_DefendNJ/Scenes/Yunnan_Lincang_Linxiang_Hengji_Dixia.unity index 147944b0..16688c3a 100644 --- a/Assets/_DefendNJ/Scenes/Yunnan_Lincang_Linxiang_Hengji_Dixia.unity +++ b/Assets/_DefendNJ/Scenes/Yunnan_Lincang_Linxiang_Hengji_Dixia.unity @@ -17963,6 +17963,7 @@ MonoBehaviour: doorPos: {fileID: 1128989868} pkPos: {fileID: 107388154} gQPos: {fileID: 508421177} + endPkPos: [] doorAnim: {fileID: 2116810936} --- !u!1 &1318686166 GameObject: diff --git a/Assets/_DefendNJ/Scenes/Zhejiang_Shaoxing_Shengzhou_WuyueGuangchang.unity b/Assets/_DefendNJ/Scenes/Zhejiang_Shaoxing_Shengzhou_WuyueGuangchang.unity index 8d9bfdf9..77555ac8 100644 --- a/Assets/_DefendNJ/Scenes/Zhejiang_Shaoxing_Shengzhou_WuyueGuangchang.unity +++ b/Assets/_DefendNJ/Scenes/Zhejiang_Shaoxing_Shengzhou_WuyueGuangchang.unity @@ -3205,11 +3205,6 @@ PrefabInstance: propertyPath: m_StaticEditorFlags value: 2147483647 objectReference: {fileID: 0} - - target: {fileID: 125438559129076651, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, - type: 3} - propertyPath: InitialModule.maxNumParticles - value: 50 - objectReference: {fileID: 0} - target: {fileID: 325528734496708736, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, type: 3} propertyPath: m_Layer @@ -3250,11 +3245,6 @@ PrefabInstance: propertyPath: m_StaticEditorFlags value: 2147483647 objectReference: {fileID: 0} - - target: {fileID: 696986871974989167, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, - type: 3} - propertyPath: InitialModule.maxNumParticles - value: 50 - objectReference: {fileID: 0} - target: {fileID: 767076224265852409, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, type: 3} propertyPath: m_Layer @@ -3275,11 +3265,6 @@ PrefabInstance: propertyPath: m_StaticEditorFlags value: 2147483647 objectReference: {fileID: 0} - - target: {fileID: 849753062788746413, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, - type: 3} - propertyPath: InitialModule.maxNumParticles - value: 50 - objectReference: {fileID: 0} - target: {fileID: 932296904113508712, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, type: 3} propertyPath: m_Layer @@ -3350,11 +3335,6 @@ PrefabInstance: propertyPath: InitialModule.maxNumParticles value: 50 objectReference: {fileID: 0} - - target: {fileID: 1559004533640969959, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, - type: 3} - propertyPath: InitialModule.maxNumParticles - value: 50 - objectReference: {fileID: 0} - target: {fileID: 1575143325444183624, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, type: 3} propertyPath: m_Layer @@ -3450,11 +3430,6 @@ PrefabInstance: propertyPath: m_StaticEditorFlags value: 2147483647 objectReference: {fileID: 0} - - target: {fileID: 2161852625863448104, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, - type: 3} - propertyPath: InitialModule.maxNumParticles - value: 50 - objectReference: {fileID: 0} - target: {fileID: 2169765853339070852, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, type: 3} propertyPath: m_Layer @@ -3570,11 +3545,6 @@ PrefabInstance: propertyPath: m_StaticEditorFlags value: 0 objectReference: {fileID: 0} - - target: {fileID: 2800988552003539462, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, - type: 3} - propertyPath: InitialModule.maxNumParticles - value: 50 - objectReference: {fileID: 0} - target: {fileID: 2809215041857795529, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, type: 3} propertyPath: m_Layer @@ -3845,11 +3815,6 @@ PrefabInstance: propertyPath: m_StaticEditorFlags value: 0 objectReference: {fileID: 0} - - target: {fileID: 4518913866118265272, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, - type: 3} - propertyPath: InitialModule.maxNumParticles - value: 50 - objectReference: {fileID: 0} - target: {fileID: 4555798657936325690, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, type: 3} propertyPath: m_Layer @@ -3905,6 +3870,11 @@ PrefabInstance: propertyPath: m_Layer value: 3 objectReference: {fileID: 0} + - target: {fileID: 5275817385415783309, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, + type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 5275817385415783309, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, type: 3} propertyPath: m_StaticEditorFlags @@ -4135,11 +4105,6 @@ PrefabInstance: propertyPath: m_StaticEditorFlags value: 0 objectReference: {fileID: 0} - - target: {fileID: 6972230966064420177, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, - type: 3} - propertyPath: InitialModule.maxNumParticles - value: 50 - objectReference: {fileID: 0} - target: {fileID: 7009990496002484994, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, type: 3} propertyPath: m_Layer @@ -4155,6 +4120,11 @@ PrefabInstance: propertyPath: m_Layer value: 3 objectReference: {fileID: 0} + - target: {fileID: 7039734615616457527, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, + type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 7039734615616457527, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, type: 3} propertyPath: m_StaticEditorFlags @@ -4275,6 +4245,11 @@ PrefabInstance: propertyPath: m_Layer value: 3 objectReference: {fileID: 0} + - target: {fileID: 7503390424723436801, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, + type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 7503390424723436801, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, type: 3} propertyPath: m_StaticEditorFlags @@ -4455,6 +4430,11 @@ PrefabInstance: propertyPath: m_Layer value: 3 objectReference: {fileID: 0} + - target: {fileID: 8565888180607937789, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, + type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} - target: {fileID: 8565888180607937789, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, type: 3} propertyPath: m_StaticEditorFlags @@ -4485,11 +4465,6 @@ PrefabInstance: propertyPath: m_StaticEditorFlags value: 2147483647 objectReference: {fileID: 0} - - target: {fileID: 8943207355180049069, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, - type: 3} - propertyPath: InitialModule.maxNumParticles - value: 50 - objectReference: {fileID: 0} - target: {fileID: 9054703962487105819, guid: a10f9fe5b3ccfcb4e8d0c9fb8aadf1ad, type: 3} propertyPath: m_Layer @@ -6863,7 +6838,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!4 &486593705 Transform: m_ObjectHideFlags: 0 @@ -11008,7 +10983,7 @@ MonoBehaviour: IncludeChildColliders: 0 RuntimeFollower: {fileID: 0} colliderMaxDistance: 100 - lastTimeMaxDistanceCalced: 638966400076664385 + lastTimeMaxDistanceCalced: 638948461884566024 --- !u!82 &675942809 AudioSource: m_ObjectHideFlags: 0 diff --git a/Assets/_DefendNJ/Scripts/Manager/GameManager.cs b/Assets/_DefendNJ/Scripts/Manager/GameManager.cs index 25526b1d..3b214551 100644 --- a/Assets/_DefendNJ/Scripts/Manager/GameManager.cs +++ b/Assets/_DefendNJ/Scripts/Manager/GameManager.cs @@ -70,7 +70,7 @@ public enum GameMode public class GameManager : NetworkBehaviour { public static GameManager Ins { get; private set; } - + #region 预制体 public GameObject DoorPre; public GameObject itemPropPre; @@ -83,13 +83,13 @@ public class GameManager : NetworkBehaviour public GameObject[] EnemyPres; public GameObject[] playerAiPres; - + public GameObject playerEndAiPres; public GameObject explosionPre; - + public GameObject enemyGrenadePre; - + public GameObject enemyGasBombPre; public GameObject enemyEndAiPre; @@ -104,29 +104,29 @@ public class GameManager : NetworkBehaviour private JsonLiteDB DB; // 怪物信息集合 //public Dictionary EnemyInfos = new Dictionary(); - - public Dictionary PlayerAiInfos = new Dictionary(); - + + public Dictionary PlayerAiInfos = new Dictionary(); + // 炮塔信息集合 public Dictionary> TowerInfos = new Dictionary>(); // 枪械信息集合 //public Dictionary GunInfos = new Dictionary(); // 子弹信息集合 - public Dictionary BulletInfos = new Dictionary(); - - public Dictionary AiInfos = new Dictionary(); - - public Dictionary RoundInfos = new Dictionary(); - + public Dictionary BulletInfos = new Dictionary(); + + public Dictionary AiInfos = new Dictionary(); + + public Dictionary RoundInfos = new Dictionary(); + // 剧情信息 public Dictionary CombatUnitInfos = new Dictionary(); - + private List curGunPropList = new List(); public Dictionary players = new Dictionary(); - + public GameMode gameMode = GameMode.OnePlayer; - + /// /// 敌人自增 /// @@ -136,14 +136,14 @@ public class GameManager : NetworkBehaviour /// 所有敌人 /// public Dictionary EnemyList = new Dictionary(); - - public Dictionary PlayerAiList = new Dictionary(); + + public Dictionary PlayerAiList = new Dictionary(); /// /// 所有敌人UI /// public Dictionary EnemyUIList = new Dictionary(); - + /// /// 所有炮塔 /// @@ -154,7 +154,7 @@ public class GameManager : NetworkBehaviour public Dictionary SettleInfos = new Dictionary(); //public List curEnemyList = new List(); - + [SyncVar] public bool isStart; /// @@ -167,7 +167,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 = ""; @@ -175,78 +175,10 @@ public class GameManager : NetworkBehaviour public GameState gameState = GameState.None; [SoundGroup] public string JointIn; [SoundGroup] public string roundSound; - + public int roundWaveTime; public int curRoundWaveTime; - - //添加 - [Header("魔力队长角色")] - public GameObject player; - public GameObject aiCharacterPre;//AI角色预制体 - private GameObject aiCharacter;//AI角色实例 - private bool isAIIntroductionComplete = false; - //修改处:添加创建AI角色的方法 - public void GamePlay() - { - CreateAICharacter(); - } - private void CreateAICharacter() - { - //检查是否已经存在AI角色 - if (aiCharacter != null) - { - Debug.Log("AI角色已经存在,不再创建新的"); - return; - } - - if (aiCharacterPre != null) - { - Debug.Log("创建AI角色"); - - //获取第一个玩家 - Transform player = players[0].transform ; - if (player == null) - { - Debug.LogError("找不到玩家,无法创建AI角色"); - return; - } - //在玩家前方创建AI角色 - Vector3 spawnPosition = player.transform.position + player.transform.forward * 3f; - spawnPosition.y = 0f; // 固定Y坐标为0 - aiCharacter = Instantiate(aiCharacterPre, spawnPosition, Quaternion.identity); - - //获取AIController并启动开场白 - AIController aiController = aiCharacter.GetComponent(); - if (aiController != null) - { - //注册AI介绍完成回调 - aiController.OnIntroductionComplete += StartGameAfterIntroduction; - - //添加延迟,确保所有组件已经完成初始化 - StartCoroutine(DelayedStartIntroduction(aiController)); - } - else - { - Debug.LogError("AI预制体中的AIController组件丢失"); - } - } - else - { - Debug.LogError("AI预制体没有在GameManager分配!"); - } - } - - private IEnumerator DelayedStartIntroduction(AIController aiController) - { - yield return new WaitForSeconds(0.1f); // 短暂延迟 - aiController.StartIntroduction(); - } - public void StartGameAfterIntroduction() - { - isAIIntroductionComplete = true; - GameStart(); - } - + void Awake() { Ins = this; @@ -267,7 +199,7 @@ public class GameManager : NetworkBehaviour public void CreateDoor() { UpdateConf(); - if (!isServer) + if(!isServer) return; GameObject door = Instantiate(DoorPre); door.transform.position = GameLocal.Ins.doorPos.position.ReflectVectorXOZ(); @@ -305,11 +237,9 @@ public class GameManager : NetworkBehaviour [Server] public void GameStart() { - gameState = GameState.Playing; - gameMode = players.Count <= 1 ? GameMode.OnePlayer : GameMode.TwoPlayers; + gameMode=players.Count<=1 ? GameMode.OnePlayer : GameMode.TwoPlayers; vistEnd = (long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds + vistAllTime; - isStart = true; ChangeBgmRpc(0); AstarPath.active.Scan(); @@ -322,7 +252,7 @@ public class GameManager : NetworkBehaviour CoroutineTaskManager.Instance.WaitSecondTodo(() => { //GameOver(GameState.Settle); - StartSpecialEvent(GameEnemyEventType.CleanUp); + StartSpecialEvent(GameEnemyEventType.CleanUp); }, vistAllTime); } @@ -370,23 +300,23 @@ public class GameManager : NetworkBehaviour Transform[] targetPos = GameLocal.Ins.enemyEndPos; GameObject enemy = Instantiate(enemyEndAiPre); NetworkServer.Spawn(enemy); - int posId = i / 3; + int posId =i/3; enemy.transform.position = GameLocal.Ins.enemyStartPos[posId].position; enemy.transform.eulerAngles = targetPos[posId].eulerAngles; enemyIndex++; Enemy enemyScript = enemy.GetComponent(); - 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; PlayerAI playerAI = playerAi.GetComponent(); - 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; } @@ -400,7 +330,7 @@ public class GameManager : NetworkBehaviour [ClientRpc] public void RpcShowWin(bool isBlue) { - + } [ClientRpc] @@ -415,22 +345,22 @@ public class GameManager : NetworkBehaviour [Server] public void RpcMessageRound() { - if (!isStart) + if(!isStart) return; CoroutineTaskManager.Instance.WaitSecondTodo(() => { - if (!isStart || gameState == GameState.EndEvent) + if(!isStart|| gameState== GameState.EndEvent) return; PlaySound2DRPC("1.4"); }, curRoundWaveTime); CoroutineTaskManager.Instance.WaitSecondTodo(() => { - if (!isStart || gameState == GameState.EndEvent) + if(!isStart|| gameState== GameState.EndEvent) return; GetRoundEnemy(); SetGameState(GameState.Playing); }, roundWaveTime); - + } [ClientRpc] @@ -458,10 +388,10 @@ public class GameManager : NetworkBehaviour int enemyId = info.EnemyList[i]; bool isUerInfoAngles = (EnemyType)enemyId == EnemyType.Mortar; Transform[] targetPos = GameLocal.Ins.enemyEndPos; - GameObject enemy = Instantiate(EnemyPres[enemyId - 3]); + GameObject enemy = Instantiate(EnemyPres[enemyId-3]); NetworkServer.Spawn(enemy); - int posId = i / 3; - int posX = i % 3 == 0 ? 0 : i % 3 == 1 ? 1 : -1; + int posId =i/3; + int posX=i%3==0? 0: i%3==1 ? 1 : -1; if (isUerInfoAngles) posX = 0; switch ((EnemyType)enemyId) @@ -474,7 +404,7 @@ public class GameManager : NetworkBehaviour break; } enemy.transform.position = GameLocal.Ins.enemyStartPos[posId].position; - enemy.transform.eulerAngles = isUerInfoAngles ? AiInfos[i + 3].EulerAngles : targetPos[posId].eulerAngles; + enemy.transform.eulerAngles =isUerInfoAngles? AiInfos[i+3].EulerAngles: targetPos[posId].eulerAngles; enemyIndex++; Enemy enemyScript = enemy.GetComponent(); Vector3 endPos = targetPos[posId].position + new Vector3(0, 0, posX); @@ -482,12 +412,12 @@ public class GameManager : NetworkBehaviour { endPos = GameLocal.Ins.riflemenPos.position; } - enemyScript.OnSpawn(enemyIndex, info.EnemyList[i], 1, endPos); + enemyScript.OnSpawn(enemyIndex, info.EnemyList[i], 1,endPos); EnemyList.Add(enemyIndex, enemyScript); yield return new WaitForSeconds(0.5f); } } - + /// /// 创建辅助AI /// @@ -498,9 +428,9 @@ public class GameManager : NetworkBehaviour GameObject playerAi = Instantiate(playerAiPres[i]); NetworkServer.Spawn(playerAi); playerAi.transform.position = GameLocal.Ins.playerAiPos[i].position; - playerAi.transform.eulerAngles = AiInfos[i + 1].EulerAngles; + playerAi.transform.eulerAngles = AiInfos[i+1].EulerAngles; PlayerAI enemyScript = playerAi.GetComponent(); - enemyScript.OnSpawn(i, (PlayerAIType)i, 1, GameLocal.Ins.playerAiEndPos[i].gameObject); + enemyScript.OnSpawn(i,(PlayerAIType)i, 1,GameLocal.Ins.playerAiEndPos[i].gameObject); PlayerAiList.Add(i, enemyScript); } // else if(gameMode == GameMode.TwoPlayers) @@ -518,65 +448,65 @@ public class GameManager : NetworkBehaviour #region 创造敌人道具 [Server] - public void CreateExplosion(Vector3 pos, EnemyType type) - { - if (!isServer) - return; - var ex = Instantiate(explosionPre, pos, Quaternion.identity); - NetworkServer.Spawn(ex); + public void CreateExplosion(Vector3 pos,EnemyType type) + { + if(!isServer) + return; + var ex= Instantiate(explosionPre, pos, Quaternion.identity); + NetworkServer.Spawn(ex); ex.GetComponent().Init(type); } public void CreateGrenade(Vector3 startPos) { - if (!isServer) - return; - var ex = Instantiate(enemyGrenadePre, startPos, Quaternion.identity); - NetworkServer.Spawn(ex); - float x = Random.Range(-3, 3); - float z = Random.Range(-3, 3); - ex.GetComponent().Init(startPos, GameLocal.Ins.endMortarPos.position + new Vector3(x, 0, z)); + if(!isServer) + return; + var ex= Instantiate(enemyGrenadePre, startPos, Quaternion.identity); + NetworkServer.Spawn(ex); + float x=Random.Range(-3,3); + float z=Random.Range(-3,3); + ex.GetComponent().Init(startPos, GameLocal.Ins.endMortarPos.position+new Vector3(x,0,z)); } - + public void CreateGasBomb(Vector3 startPos) { - if (!isServer) - return; - var ex = Instantiate(enemyGasBombPre, startPos, Quaternion.identity); - NetworkServer.Spawn(ex); - float x = Random.Range(-3, 3); - float z = Random.Range(-3, 3); - ex.GetComponent().Init(startPos, GameLocal.Ins.endMortarPos.position + new Vector3(x, 0, z)); + if(!isServer) + return; + var ex= Instantiate(enemyGasBombPre, startPos, Quaternion.identity); + NetworkServer.Spawn(ex); + float x=Random.Range(-3,3); + float z=Random.Range(-3,3); + ex.GetComponent().Init(startPos,GameLocal.Ins.endMortarPos.position+new Vector3(x,0,z)); } public void CreateEnemyPlane(Transform startPos) { - if (!isServer) - return; - var ex = Instantiate(enemyPlanePre, startPos.position, Quaternion.identity); - NetworkServer.Spawn(ex); + if(!isServer) + return; + var ex= Instantiate(enemyPlanePre, startPos.position, Quaternion.identity); + NetworkServer.Spawn(ex); } public void CreateItemProp(Transform pos) { - if (!isStart) + if(!isStart) return; - var item = Instantiate(itemPropPre); - NetworkServer.Spawn(item); - item.transform.position = new Vector3(pos.position.x, 0.5f, pos.position.z); + var item= Instantiate(itemPropPre); + NetworkServer.Spawn(item); + item.transform.position=new Vector3(pos.position.x,0.5f,pos.position.z); item.GetComponent().SetItemProp(ItemPropType.Hp); } #endregion - + public List GetRoundEnemy() { List curEnemyList = new List(); - int curRoundIndex = roundIndex >= RoundInfos.Count ? Random.Range(1, RoundInfos.Count) : roundIndex; - var roundInfo = RoundInfos[curRoundIndex]; - // curRoundIndex=5; - // roundInfo= RoundInfos[curRoundIndex]; + int curRoundIndex=roundIndex>= RoundInfos.Count? Random.Range(1,RoundInfos.Count):roundIndex; + var roundInfo=RoundInfos[curRoundIndex]; + // curRoundIndex=5; + // roundInfo= RoundInfos[curRoundIndex]; StartEvent(roundInfo); - if (roundIndex % 5 == 0 && roundIndex != 0) + if (roundIndex==5) { CoroutineTaskManager.Instance.WaitSecondTodo(() => { @@ -598,7 +528,7 @@ public class GameManager : NetworkBehaviour CoroutineTaskManager.Instance.WaitSecondTodo(() => { Debug.LogError("播放音效:1.10"); - PlayerAiList[0].PlaySound3DRPC("1.10", true); + PlayerAiList[0].PlaySound3DRPC("1.10",true); EnemyShowOutline(EnemyType.Ordinary); EnemyShowOutline(EnemyType.Charge); }, 10); @@ -606,64 +536,64 @@ public class GameManager : NetworkBehaviour case GameEnemyEventType.Snipe: CoroutineTaskManager.Instance.WaitSecondTodo(() => { - PlayerAiList[0].PlaySound3DRPC("1.14", true); + PlayerAiList[0].PlaySound3DRPC("1.14",true); }, 5); CoroutineTaskManager.Instance.WaitSecondTodo(() => { - PlayerAiList[0].PlaySound3DRPC("1.15", true); + PlayerAiList[0].PlaySound3DRPC("1.15",true); EnemyShowOutline(EnemyType.Sniper); }, 7); break; case GameEnemyEventType.Mortar: CoroutineTaskManager.Instance.WaitSecondTodo(() => { - PlayerAiList[0].PlaySound3DRPC("1.20", true); + PlayerAiList[0].PlaySound3DRPC("1.20",true); StartCoroutine(CreateMortarBullet()); }, 7); CoroutineTaskManager.Instance.WaitSecondTodo(() => { - PlayerAiList[0].PlaySound3DRPC("1.21", true); + PlayerAiList[0].PlaySound3DRPC("1.21",true); EnemyShowOutline(EnemyType.Mortar); }, 10); break; case GameEnemyEventType.MachineGun: CoroutineTaskManager.Instance.WaitSecondTodo(() => { - PlayerAiList[0].PlaySound3DRPC("1.24", true); + PlayerAiList[0].PlaySound3DRPC("1.24",true); StartCoroutine(CreateGQBullet()); }, 7); CoroutineTaskManager.Instance.WaitSecondTodo(() => { - PlayerAiList[0].PlaySound3DRPC("1.25", true); - EnemyShowOutline(EnemyType.Riflemen); + PlayerAiList[0].PlaySound3DRPC("1.25",true); + EnemyShowOutline( EnemyType.Riflemen); }, 10); break; case GameEnemyEventType.Grenade: CoroutineTaskManager.Instance.WaitSecondTodo(() => { - PlayerAiList[0].PlaySound3DRPC("1.35", true); + PlayerAiList[0].PlaySound3DRPC("1.35",true); }, 5); CoroutineTaskManager.Instance.WaitSecondTodo(() => { - PlayerAiList[0].PlaySound3DRPC("1.38", true); + PlayerAiList[0].PlaySound3DRPC("1.38",true); EnemyShowOutline(EnemyType.Grenade); }, 7); break; case GameEnemyEventType.Biochemical: CoroutineTaskManager.Instance.WaitSecondTodo(() => { - PlayerAiList[0].PlaySound3DRPC("1.40", true); + PlayerAiList[0].PlaySound3DRPC("1.40",true); }, 5); CoroutineTaskManager.Instance.WaitSecondTodo(() => { - PlayerAiList[0].PlaySound3DRPC("1.42", true); + PlayerAiList[0].PlaySound3DRPC("1.42",true); EnemyShowOutline(EnemyType.Virus); }, 7); break; case GameEnemyEventType.Bomber: CoroutineTaskManager.Instance.WaitSecondTodo(() => { - PlayerAiList[0].PlaySound3DRPC("1.56", true); + PlayerAiList[0].PlaySound3DRPC("1.56",true); EnemyShowOutline(EnemyType.Commander); EnemyShowOutline(EnemyType.Mortar); EnemyShowOutline(EnemyType.Grenade); @@ -674,8 +604,8 @@ public class GameManager : NetworkBehaviour }, 10); CoroutineTaskManager.Instance.WaitSecondTodo(() => { - PlayerAiList[0].PlaySound3DRPC("1.59", true); - + PlayerAiList[0].PlaySound3DRPC("1.59",true); + }, 20); break; } @@ -689,7 +619,7 @@ public class GameManager : NetworkBehaviour CreateNpc(); CoroutineTaskManager.Instance.WaitSecondTodo(() => { - PlayerAiList[0].PlaySound3DRPC("1.67", true); + PlayerAiList[0].PlaySound3DRPC("1.67",true); }, 5); break; case GameEnemyEventType.CleanUp: @@ -712,39 +642,39 @@ public class GameManager : NetworkBehaviour IEnumerator CreateMortarBullet() { - Transform insPos = GameLocal.Ins.insMortarPos; - Transform endPos = GameLocal.Ins.endMortarPos; + Transform insPos=GameLocal.Ins.insMortarPos; + Transform endPos=GameLocal.Ins.endMortarPos; bool isHaveMortar = IsHaveTypeEnemy(EnemyType.Mortar); while (isHaveMortar) { - var item = Instantiate(mortarBulletPre); - NetworkServer.Spawn(item); - item.transform.position = insPos.position; + var item= Instantiate(mortarBulletPre); + NetworkServer.Spawn(item); + item.transform.position=insPos.position; int rangeIndexX = Random.Range(-5, 5); int rangeIndexZ = Random.Range(-2, 2); - item.GetComponent().Init(insPos.position, endPos.position + new Vector3(rangeIndexX, 0, rangeIndexZ)); + item.GetComponent().Init(insPos.position,endPos.position+new Vector3(rangeIndexX,0,rangeIndexZ)); yield return new WaitForSeconds(AiInfos[(int)EnemyType.Mortar].FiringRate); isHaveMortar = IsHaveTypeEnemy(EnemyType.Mortar); } } - + IEnumerator CreateGQBullet() { - Transform insPos = GameLocal.Ins.gQPos; - Vector3 endPos = GameLocal.Ins.riflemenEndPos.position; + Transform insPos=GameLocal.Ins.gQPos; + Vector3 endPos=GameLocal.Ins.riflemenEndPos.position; bool isHaveMortar = IsHaveTypeEnemy(EnemyType.Riflemen); while (isHaveMortar) { - var item = Instantiate(gqBulletPre); - NetworkServer.Spawn(item); - item.transform.position = insPos.position; - + var item= Instantiate(gqBulletPre); + NetworkServer.Spawn(item); + item.transform.position=insPos.position; + int rangeIndexZ = Random.Range(-2, 2); - item.GetComponent().OnSpawn(endPos + new Vector3(rangeIndexZ, 0, rangeIndexZ), 20); - - var itemMuzzle = Instantiate(gqMuzzleBulletPre); - NetworkServer.Spawn(itemMuzzle); - itemMuzzle.transform.position = insPos.position; + item.GetComponent().OnSpawn(endPos+new Vector3(rangeIndexZ,0,rangeIndexZ),20); + + var itemMuzzle= Instantiate(gqMuzzleBulletPre); + NetworkServer.Spawn(itemMuzzle); + itemMuzzle.transform.position=insPos.position; CoroutineTaskManager.Instance.WaitSecondTodo(() => { NetworkServer.Destroy(itemMuzzle.gameObject); @@ -759,7 +689,7 @@ public class GameManager : NetworkBehaviour { GameLocal.Ins.OpenEndBullet(); } - + [ClientRpc] public void DownEndBullet() { @@ -822,20 +752,20 @@ public class GameManager : NetworkBehaviour } } - + public void CreateEnemyEndBullet() { - PlayerAiList[0].PlaySound3DRPC("1.65", true); + PlayerAiList[0].PlaySound3DRPC("1.65",true); OpenEndBullet(); CoroutineTaskManager.Instance.WaitSecondTodo(() => { foreach (var item in EnemyList.Values) { - item.Die(null, transform); + item.Die(null,transform); } foreach (var item in NpcEnemyList) { - item.Die(null, transform); + item.Die(null,transform); } }, 5); CoroutineTaskManager.Instance.WaitSecondTodo(() => @@ -870,7 +800,7 @@ public class GameManager : NetworkBehaviour /// 删除敌方单位 /// [Server] - public void DeleteEnemy(int id, bool isNpcEnemy) + public void DeleteEnemy(int id,bool isNpcEnemy) { if (isNpcEnemy) { @@ -886,14 +816,14 @@ public class GameManager : NetworkBehaviour return; } GameObject enemy = EnemyList[id].gameObject; - + EnemyList.Remove(id); - + curRoundEnemyCount--; - + NetworkServer.Destroy(enemy); ChangePlayerAiCountdownTime(); - if (curRoundEnemyCount <= 0) + if (curRoundEnemyCount<=0) { CreateNextRound(); if (gameState == GameState.EndEvent) @@ -934,7 +864,7 @@ public class GameManager : NetworkBehaviour roundWaveTime = 15; curRoundWaveTime = 12; - + AiInfos.Clear(); RoundInfos.Clear(); TableReader infoReader = DB["AiInfo"].GetReader(); @@ -982,14 +912,14 @@ public class GameManager : NetworkBehaviour while (infoReader.Read()) { AiInfo info = new AiInfo(infoReader); - AiInfos.Add(info.ID, info); + AiInfos.Add(info.ID,info); } - + infoReader = DB["RoundInfo"].GetReader(); while (infoReader.Read()) { RoundInfo info = new RoundInfo(infoReader); - RoundInfos.Add(info.ID, info); + RoundInfos.Add(info.ID,info); } // infoReader = DB["StoryProgressInfo"].GetReader(); @@ -1028,14 +958,14 @@ public class GameManager : NetworkBehaviour /// public GameObject GetPlayerAi(Transform curTransform) { - if (PlayerAiList.Count == 0) + 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; + if (player.Value == null|| player.Key<=1|| player.Value.isGet) continue; // 计算XZ平面距离(使用你的 ReflectVectorXOZ 方法) float dis = Vector3.Distance( @@ -1053,7 +983,7 @@ public class GameManager : NetworkBehaviour return nearestPlayer; } - + public GameObject GetPlayer(Transform curTransform) { if (players == null || players.Count == 0) @@ -1120,7 +1050,7 @@ public class GameManager : NetworkBehaviour public Transform GetPlayerPos() { int rand = Random.Range(0, 100); - + if (players.Count >= 2) // 双人模式 { if (rand < 45) // 0-44 @@ -1140,7 +1070,7 @@ public class GameManager : NetworkBehaviour return PlayerAiList[1].transform; // 队友B } } - + [Server] public void CreateEnemyUI(Enemy enemy) { @@ -1157,15 +1087,15 @@ public class GameManager : NetworkBehaviour GameObject enemyUI = EnemyUIList[id].gameObject; EnemyUIList.Remove(id); NetworkServer.Destroy(enemyUI); - + } [ClientRpc] public void RpcShowHUD() { - HUDPanel.Show(); + HUDPanel.Show(); } - + #region 空投道具 /// /// 修复炮塔 @@ -1258,7 +1188,7 @@ public class GameManager : NetworkBehaviour { return EnemyList.Count > 0; } - + #region 工具 public string GetLessTimeStr() { @@ -1287,25 +1217,24 @@ public class GameManager : NetworkBehaviour return string.Format("{0}:{1}", mm, ss); } #endregion - + public void PlaySound2DRPC(string sound) { MasterAudio.PlaySound(sound); } [ClientRpc] - public void PlaySound3DRPC(string sound, Transform tran, bool isStop) + public void PlaySound3DRPC(string sound,Transform tran,bool isStop) { - if (isStop) + if(isStop) MasterAudio.StopAllSoundsOfTransform(tran); MasterAudio.PlaySound3DAtTransform(sound, tran); } - + public void PlayJointMusic() { MasterAudio.PlaySound(JointIn); GameLocal.Ins.BGMState.StateChange(2); } - } diff --git a/Assets/_DefendNJ/Scripts/Manager/TrueGearEffectManager.cs b/Assets/_DefendNJ/Scripts/Manager/TrueGearEffectManager.cs index acf03f8f..2ea3312b 100644 --- a/Assets/_DefendNJ/Scripts/Manager/TrueGearEffectManager.cs +++ b/Assets/_DefendNJ/Scripts/Manager/TrueGearEffectManager.cs @@ -18,7 +18,7 @@ public class TrueGearEffectManager : MonoBehaviour GetConnectIndex = 20; AddHitPart(); #if !UNITY_EDITOR - StartRequestTrueGear(); + //TrueGearEffectManager.Ins.StartRequestTrueGear(); #endif } @@ -111,17 +111,27 @@ public class TrueGearEffectManager : MonoBehaviour if (!res) return; - List res1 = androidConnector.GetScanedDevices(); - Debug.Log(res1.ToString()); - foreach (var item in res1) + List devices = androidConnector.GetScanedDevices(); + if (devices == null || devices.Count == 0) { + Debug.Log("未扫描到任何设备"); + return; + } + + foreach (var device in devices) + { + bool connected = androidConnector.ConnectToDevice(device.address); + if (connected) { - androidConnector.ConnectToDevice(item.address); - Debug.Log(string.Format("Device Connect: {0}, {1}", item.name, item.address)); + Debug.Log($"成功连接设备: {device.name} - {device.address}"); isGetConnect = true; ChangeElectricalLevel(); return; } + else + { + Debug.LogWarning($"设备被占用或连接失败: {device.name} - {device.address}"); + } } Debug.Log("No device found"); } @@ -197,7 +207,7 @@ public class TrueGearEffectManager : MonoBehaviour }} ] }}"; - + SendPlayEffectByContent(json); } @@ -208,8 +218,34 @@ public class TrueGearEffectManager : MonoBehaviour Debug.Log("OnTestClick" + res); if (!res) return; - androidConnector.SendPlayEffectByContent(jsonStr); + try + { + androidConnector.SendPlayEffectByContent(jsonStr); + } + catch (Exception ex) + { + Debug.LogError("调用 TrueGear 崩溃保护: " + ex); + ReconnectTrueGear(); + } + } + + // 当检测蓝牙断开或异常时调用 + void ReconnectTrueGear() + { + try + { + var conn = TruegearAndroidConnector.Instance; + conn.InitShellJavaObject(); + conn.RequestPermission(); + conn.StartScan(); + } + catch (Exception e) + { + Debug.LogError("重新初始化 TrueGear 失败:" + e); + } + } + public List hitParts=new List(); public void AddHitPart() @@ -222,7 +258,28 @@ public class TrueGearEffectManager : MonoBehaviour } public void OnHit(bool isUp, int index,bool isArm) { - //ChangeElectricalLevel(); + TruegearAndroidConnector androidConnector = TruegearAndroidConnector.Instance; + if (androidConnector == null) + { + Debug.LogWarning("TrueGear connector 为空,跳过调用"); + isGetConnect = false; + return; + } + + if (!androidConnector.IsAvailable()) + { + Debug.LogWarning("TrueGear 蓝牙不可用或断开,跳过调用"); + isGetConnect = false; + return; + } + + if (!isGetConnect) + { + androidConnector.InitShellJavaObject(); + androidConnector.RequestPermission(); + StartCoroutine(TrueGearAndroidConnector()); + return; + } List motorIDs = new List(); string hitPart= hitParts[index]; switch (hitPart) @@ -236,11 +293,11 @@ public class TrueGearEffectManager : MonoBehaviour case "rightDown": motorIDs.AddRange(isUp?new int[] { 10,11,14,15}: new int[] { 114, 115, 118,119 }); break; case "rightAim": - Debug.Log("xxzz"); motorIDs.AddRange(new int[] { 0,100}); break; default: motorIDs.Add(0); break; } + PlayVibrationEffect( effectName: $"Hit_{hitPart}", motorIndex: motorIDs, diff --git a/Assets/_DefendNJ/Scripts/Player.cs b/Assets/_DefendNJ/Scripts/Player.cs index 9b4c000c..2a41c7fc 100644 --- a/Assets/_DefendNJ/Scripts/Player.cs +++ b/Assets/_DefendNJ/Scripts/Player.cs @@ -127,25 +127,10 @@ public class Player : NetworkRoomPlayer,IDamagable Vector3 directionFormHit=(transform.position-_sender.position).normalized; float angle = Vector3.Angle(forward, directionFormHit); int index = Random.Range(0, 4); - TrueGearEffectManager.Ins.OnHit(angle > 90,index,false); + if(TrueGearEffectManager.Ins!=null) + TrueGearEffectManager.Ins.OnHit(angle > 90,index,false); } #endif - // if (currentHp <= 0 && IsAlive) - // { - // IsAlive = false; - // isDie = true; - // GameLocal.Ins.DieUI.SetActive(true); - // GameManager.Ins.PlaySound2DRPC("1.35"); - // MonoSingleton.Instance.WaitSecondTodo(() => - // { - // IsAlive = true; - // isDie = false; - // GameLocal.Ins.DieUI.SetActive(false); - // currentHp = maxHp; - // EventDispatcher.TriggerEvent("HpChange", currentHp, maxHp); - // time = 0f; - // }, 5f, this); - // } if (currentHp > 0) { GameLocal.Ins.HitUI.SetActive(true); diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 8be69ae9..d9077eae 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -53,7 +53,7 @@ EditorBuildSettings: - enabled: 0 path: Assets/_DefendNJ/Scenes/Zhejiang_Hangzhou_Linping_Yintaicheng_Shinei.unity guid: fb54f32cfb20d284faaa1f29ffd58371 - - enabled: 0 + - enabled: 1 path: Assets/_DefendNJ/Scenes/Yunnan_Lincang_Linxiang_Hengji_Dixia.unity guid: dc51f151175283c4e9315b04d47ec85b - enabled: 0 diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index a57fe4a1..3fc52055 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -13,7 +13,7 @@ PlayerSettings: useOnDemandResources: 0 accelerometerFrequency: 60 companyName: pineappletech - productName: "\u4FDD\u536B\u91D1\u9675" + productName: "\u4FDD\u536B\u91D1\u9675_\u5730\u4E0B" defaultCursor: {fileID: 0} cursorHotspot: {x: 0, y: 0} m_SplashScreenBackgroundColor: {r: 0.13725491, g: 0.12156863, b: 0.1254902, a: 1} @@ -165,7 +165,7 @@ PlayerSettings: androidSupportedAspectRatio: 1 androidMaxAspectRatio: 2.1 applicationIdentifier: - Android: com.pineappletech.defendnj.hunanjishouqianzhoutianhong + Android: com.pineappletech.defendnj.yunnanlincanglinxianghengjidixia Standalone: com.DefaultCompany.com.unity.template.ar buildNumber: Standalone: 0