添加魔力队长角色
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BestHTTP;
|
||||
using DragonLi.Core;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using Unity.XR.PXR;
|
||||
using UnityEngine;
|
||||
@@ -115,6 +116,11 @@ public class GameManager : MonoBehaviour
|
||||
|
||||
public int curLevel = 0;
|
||||
|
||||
//添加
|
||||
[Header("AI角色")]
|
||||
public GameObject aiCharacterPre;//AI角色预制体
|
||||
private GameObject aiCharacter;//AI角色实例
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
@@ -258,11 +264,37 @@ public class GameManager : MonoBehaviour
|
||||
}
|
||||
|
||||
public bool isGamePlay;
|
||||
|
||||
//AI介绍是否完成
|
||||
private bool isAIIntroductionComplete = false;
|
||||
|
||||
// 游戏开始
|
||||
public void GamePlay()
|
||||
{
|
||||
//TODO:添加一个玩家进入游戏AI进行游戏介绍,介绍完后,AI自动回到玩家左侧
|
||||
//创建AI角色
|
||||
CreateAICharacter();
|
||||
|
||||
//isGamePlay = true;
|
||||
//CreateBoss();
|
||||
//PlayerUIMessage(0);
|
||||
//CoroutineTaskManager.Instance.WaitSecondTodo(() =>
|
||||
// AudioManager.Ins?.SoundPlay("bgm2", true), 10f);
|
||||
//CoroutineTaskManager.Instance.WaitSecondTodo(() =>
|
||||
// AudioManager.Ins?.SoundPlay("2.39BGM", true), 30f);
|
||||
}
|
||||
|
||||
//添加AI介绍完成后的游戏开始方法
|
||||
public void StartGameAfterIntroduction()
|
||||
{
|
||||
isAIIntroductionComplete = true;
|
||||
isGamePlay = true;
|
||||
|
||||
Debug.Log("AI介绍完成,开始游戏正常流程");
|
||||
|
||||
//创建Boss
|
||||
CreateBoss();
|
||||
|
||||
PlayerUIMessage(0);
|
||||
CoroutineTaskManager.Instance.WaitSecondTodo(() =>
|
||||
AudioManager.Ins?.SoundPlay("bgm2", true), 10f);
|
||||
@@ -270,6 +302,51 @@ public class GameManager : MonoBehaviour
|
||||
AudioManager.Ins?.SoundPlay("2.39BGM", true), 30f);
|
||||
}
|
||||
|
||||
//添加创建AI角色的方法
|
||||
private void CreateAICharacter()
|
||||
{
|
||||
//检查是否已经存在AI角色
|
||||
if (aiCharacter != null)
|
||||
{
|
||||
Debug.Log("AI角色已经存在,不再创建新的");
|
||||
return;
|
||||
}
|
||||
|
||||
if (aiCharacterPre != null)
|
||||
{
|
||||
Debug.Log("创建AI角色");
|
||||
|
||||
//在玩家前方创建AI角色
|
||||
Vector3 spawnPosition = player.transform.position + player.transform.forward * 3f;
|
||||
aiCharacter = Instantiate(aiCharacterPre, spawnPosition, Quaternion.identity);
|
||||
|
||||
//获取AIController并启动开场白
|
||||
AIController aiController = aiCharacter.GetComponent<AIController>();
|
||||
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 ShowPlayerUI()
|
||||
{
|
||||
OverlayUI.Ins.Cover("UI/PlayerUI", false);
|
||||
@@ -581,6 +658,19 @@ public class GameManager : MonoBehaviour
|
||||
ShowEndGameUI(true);
|
||||
GameInit.Ins.PlayAudio("1.17", GameInit.Ins.self.transform, true);
|
||||
AudioManager.Ins?.SoundPlay("bgm4", true);
|
||||
|
||||
//如需要:销毁AI角色
|
||||
if (aiCharacter != null)
|
||||
{
|
||||
//取消注册事件
|
||||
AIController aiController = aiCharacter.GetComponent<AIController>();
|
||||
if(aiController != null)
|
||||
{
|
||||
aiController.OnIntroductionComplete -= StartGameAfterIntroduction;
|
||||
}
|
||||
|
||||
Destroy(aiCharacter);
|
||||
}
|
||||
}
|
||||
|
||||
public void LoseEndGame()
|
||||
@@ -596,5 +686,18 @@ public class GameManager : MonoBehaviour
|
||||
isGameEnd = true;
|
||||
CurEnemyDie();
|
||||
AudioManager.Ins?.SoundPlay("bgm4", true);
|
||||
|
||||
//如需要:销毁AI角色
|
||||
if (aiCharacter != null)
|
||||
{
|
||||
//取消注册事件
|
||||
AIController aiController = aiCharacter.GetComponent<AIController>();
|
||||
if (aiController != null)
|
||||
{
|
||||
aiController.OnIntroductionComplete -= StartGameAfterIntroduction;
|
||||
}
|
||||
|
||||
Destroy(aiCharacter);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user