You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
4.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using UnityEngine.UI;
using System;
public class Level1Manager : MonoSingleton<Level1Manager>
{
RaycastHit rh;
public Animator sjzanimator;
[Header("声音")]
public AudioClip audioClips;
AudioSource audioSource;
[Header("人物")]
public NPCControl[] npcs;
public PlayerController player;
public GameObject clickPerson;
public GameObject person;//施救者
[Header("需要转移的物体")]
public GameObject[] needTransferObj;
[Header("游戏状态变量")]
[NonSerialized]
public bool mouseMove = false;
[NonSerialized]
public bool remove = false;
bool safe = false;
[NonSerialized]
public int OptionOne;//玩家选择的对应操作0对应转移1对应清理
[Header("UI")]
public ErrorTip errorTip;
public GameObject clickTip;
public GameObject GameEndTip;
[Header("操作历史")]
public Transform operateLog;
//[NonSerialized]
public List<Operate> allOperates = new List<Operate>();
protected override void Awake()
{
base.Awake();
DontDestroyOnLoad(gameObject);
audioSource = GetComponent<AudioSource>();
//safe = Random.Range(0,1f) > 0.5 ? true : false;
}
private void Start()
{
Init();
EventManager.Instance.register("DisperseCrowd", DisperseCrowd);
}
private void Update()
{
if (remove) {
Ray ray=Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out rh)) {
if (rh.collider.tag == "ZAW" && Input.GetMouseButtonDown(0)) {
if (rh.collider.GetComponent<Animator>())
{
rh.collider.GetComponent<Animator>().SetTrigger("Sankai");
}
else {
rh.collider.gameObject.SetActive(false);
clickTip.SetActive(false);
}
rh.collider.tag = "Untagged";
}
}
}
}
void Init() {
player.WalkAndSquat();
EventManager.Instance.emit("StartTip");
}
#region 安全判断
public void PanDuanSafe(bool safe) {
mouseMove = false;
EventManager.Instance.emit("PanDuanSafe", this.safe == safe,this.safe);
}
public void SetOptionOne(int index)
{
OptionOne = index;
if (index == 0)
{
EventManager.Instance.emit("OptionOne", 0);
Level1Manager.Instance.allOperates[1].Finished();
Level1Manager.Instance.AddOperate(Level1Const.operate3Info);
Invoke("TransferObjs", 1);
}
else if (index == 1)
{
EventManager.Instance.emit("OptionOne", 1);
}
}
#endregion
#region 转移操作
void TransferObjs() {
person.SetActive(true);
CinemachineFreeLook cmcamera= FindObjectOfType<CinemachineFreeLook>();
cmcamera.LookAt = needTransferObj[0].transform;
cmcamera.Follow = needTransferObj[0].transform;
cmcamera.m_YAxis.Value = 0.75f;
cmcamera.m_XAxis.Value = 56.27f;
cmcamera.m_Orbits[1].m_Radius = 10;
foreach (var obj in needTransferObj) {
obj.transform.position += new Vector3(1.5f, 0, -41.16f);
}
Invoke("ZhuanyiEnd",2);
}
void ZhuanyiEnd()
{
//allOperates[2].Finished();
GameEndTip.SetActive(true);
GameEndTip.GetComponentInChildren<Text>().text = "已成功转移到安全位置,请点击左侧工具包进行下一步操作";
foreach (var npc in npcs)
{
npc.gameObject.SetActive(true);
npc.StartWalk();
}
EventManager.Instance.emit("TransEnd");
}
#endregion
public void AddOperate(string text)
{
Operate op = Instantiate(Resources.Load<GameObject>("operate"), operateLog).GetComponent<Operate>();
allOperates.Add(op);
op.str = text;
op.color = Level2Const.operateFrontColor;
}
void DisperseCrowd(params object[] data) {
PlaySankai();
Invoke("SankaiAni",4f);
}
void EndGame() {
EventManager.Instance.emit("EndGame");
}
public void PlaySankai() {
audioSource.clip = audioClips;
audioSource.Play();
}
void SankaiAni() {
sjzanimator.SetTrigger("Sankai");
Invoke("Sankai", 2);
}
void Sankai() {
foreach (var npc in npcs)
{
npc.BackPos();
}
Invoke("EndGame", 1f);
}
}