220 lines
5.8 KiB
C#
220 lines
5.8 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
public class CharacterInturn : MonoBehaviour
|
||
{
|
||
|
||
private Button recubtn;//救援按钮
|
||
private Button disbtn;//配电箱按钮
|
||
private Button connectgun;//连接水枪按钮
|
||
private Button connectfa;//连接水阀按钮
|
||
private Button openfa;//打开水阀按钮
|
||
|
||
|
||
private CharacterAin Characterain;
|
||
|
||
private int XfsStep = 0;
|
||
|
||
public GameObject cha;
|
||
public GameObject xfs;
|
||
|
||
private GameObject timer;
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
xfs = GameObject.Find("Canvas/xfs");
|
||
|
||
recubtn = GameObject.Find("Canvas/Recuse").GetComponent<Button>();
|
||
disbtn = GameObject.Find("Canvas/Distribution box").GetComponent<Button>();
|
||
connectgun = GameObject.Find("Canvas/xfs/ConnectGun").GetComponent<Button>();
|
||
connectfa = GameObject.Find("Canvas/xfs/ConnectFa").GetComponent<Button>();
|
||
openfa = GameObject.Find("Canvas/xfs/OpenFa").GetComponent<Button>();
|
||
Characterain = this.GetComponent<CharacterAin>();
|
||
//animator = this.GetComponent<Animator>();
|
||
// stateInfo = animator.GetCurrentAnimatorStateInfo(0);
|
||
|
||
timer = GameObject.Find("Canvas/Timer");
|
||
|
||
recubtn.gameObject.SetActive(false);
|
||
disbtn.gameObject.SetActive(false);
|
||
xfs.gameObject.SetActive(false);
|
||
|
||
|
||
recubtn.onClick.AddListener(Recuse);
|
||
disbtn.onClick.AddListener(disClick);
|
||
connectgun.onClick.AddListener(CgunClick);
|
||
connectfa.onClick.AddListener(CfaClick);
|
||
openfa.onClick.AddListener(OfaClick);
|
||
|
||
}
|
||
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
|
||
}
|
||
|
||
void Recuse()//救援操作
|
||
{
|
||
Characterain.SetSkillAin(CharacterSkill.Rescue);
|
||
StartCoroutine(Rescuereturn(7f));
|
||
}
|
||
|
||
void disClick()//配电箱操作
|
||
{
|
||
|
||
|
||
}
|
||
|
||
void CgunClick()//连接水枪操作
|
||
{
|
||
if (XfsStep == 0)
|
||
{
|
||
//执行操作动画
|
||
Debug.Log("连接水枪");
|
||
CoGunHide(0);
|
||
XfsStep++;
|
||
StartCoroutine(AnimTimeSuccefful(6f));
|
||
Characterain.SetSkillAin(CharacterSkill.OperateSuccess);
|
||
}
|
||
else
|
||
{
|
||
|
||
//执行操作失败动画
|
||
Debug.Log("操作失败,重新开始");
|
||
XfsStep = 0;
|
||
CoGunHide(0);
|
||
StartCoroutine(AnimTimeFail(2f));
|
||
Characterain.SetSkillAin(CharacterSkill.OperateFail);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
void CfaClick()//连接水阀操作
|
||
{
|
||
if (XfsStep == 1)
|
||
{
|
||
//执行操作动画
|
||
Debug.Log("连接水阀");
|
||
CoGunHide(1);
|
||
XfsStep++;
|
||
StartCoroutine(AnimTimeSuccefful(6f));
|
||
connectfa.gameObject.SetActive(false);
|
||
Characterain.SetSkillAin(CharacterSkill.OperateSuccess);
|
||
}
|
||
else
|
||
{
|
||
//执行操作失败动画
|
||
XfsStep = 0;
|
||
CoGunHide(0);
|
||
StartCoroutine(AnimTimeFail(2f));
|
||
Characterain.SetSkillAin(CharacterSkill.OperateFail);
|
||
}
|
||
|
||
}
|
||
|
||
void OfaClick()//打开水阀操作
|
||
{
|
||
if (XfsStep == 2)
|
||
{
|
||
//执行操作动画
|
||
Debug.Log("打开水阀");
|
||
CoGunHide(1);
|
||
XfsStep++;
|
||
StartCoroutine(AnimTimeSuccefful(6f));
|
||
Characterain.SetSkillAin(CharacterSkill.OperateSuccess);
|
||
|
||
}
|
||
else
|
||
{
|
||
//执行操作失败动画
|
||
XfsStep = 0;
|
||
CoGunHide(0);
|
||
StartCoroutine(AnimTimeFail(2f));
|
||
Characterain.SetSkillAin(CharacterSkill.OperateFail);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
IEnumerator AnimTimeSuccefful(float timer)//操作成功执行的协程
|
||
{
|
||
TimerMgr.Instance.StartCooldown(timer, HandleCooldownFinished); // 传入冷却时间和结束事件
|
||
yield return null;
|
||
|
||
}
|
||
|
||
IEnumerator AnimTimeFail(float timer)//操作失败执行的协程
|
||
{
|
||
TimerMgr.Instance.StartCooldown(timer, HandleCooldownFinishedFailed);
|
||
yield return null;
|
||
}
|
||
|
||
void HandleCooldownFinished()//消防栓操作成功,这里添加一个事件用来处理计时器冷却技术后的逻辑
|
||
{
|
||
Characterain.SetSkillAin(CharacterSkill.NoSkill);
|
||
CoApper();
|
||
}
|
||
|
||
void HandleCooldownFinishedFailed()//消防栓操作失败结束后的事件处理,添加一个全局的气泡弹窗
|
||
{
|
||
PromptMgr.Instance.PromptBubble("操作失败");
|
||
Characterain.SetSkillAin(CharacterSkill.NoSkill);
|
||
CoApper();
|
||
|
||
}
|
||
|
||
IEnumerator Rescuereturn(float timer)//协程实现npc被救援成功后进行撤离
|
||
{
|
||
recubtn.gameObject.SetActive(false);
|
||
TimerMgr.Instance.StartCooldown(timer,HandleRescue);
|
||
yield return null;
|
||
|
||
|
||
}
|
||
void HandleRescue()//救援成功后对人物动作进行的处理,以及npc前往指定地点的处理
|
||
{
|
||
Characterain.SetSkillAin(CharacterSkill.NoSkill);
|
||
cha.GetComponent<RecuseNpc>().Setnpcstate();
|
||
}
|
||
void CoGunHide(int Hide)//执行动作期间对按钮进行隐藏
|
||
{
|
||
switch (Hide)
|
||
{
|
||
case 0:
|
||
connectgun.gameObject.SetActive(false);
|
||
connectfa.gameObject.SetActive(false);
|
||
openfa.gameObject.SetActive(false);
|
||
break;
|
||
case 1:
|
||
openfa.gameObject.SetActive(false);
|
||
break;
|
||
}
|
||
}
|
||
|
||
void CoApper()//显示当前步骤应该出现的按钮
|
||
{
|
||
switch (XfsStep)
|
||
{
|
||
case 0:
|
||
connectgun.gameObject.SetActive(true);
|
||
connectfa.gameObject.SetActive(true);
|
||
openfa.gameObject.SetActive(true);
|
||
break;
|
||
case 1:
|
||
connectfa.gameObject.SetActive(true);
|
||
openfa.gameObject.SetActive(true);
|
||
break;
|
||
case 2:
|
||
openfa.gameObject.SetActive(true);
|
||
break;
|
||
}
|
||
|
||
}
|
||
|
||
}
|