using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using Sirenix.OdinInspector;
///
/// 男童类,基督Boss关的那个
///
public class Boy : Interactive
{
// _____ _ _ _
// | __ \ | | | (_)
// | |__) | _| |__ | |_ ___
// | ___/ | | | '_ \| | |/ __|
// | | | |_| | |_) | | | (__
// |_| \__,_|_.__/|_|_|\___|
public enum State {wait, saving, OK}
///
/// 救下一个男童需要的时间
///
[Header("救下一个男童需要的时间")]
public float saveNeedTime;
// _____ _ _
// | __ \ (_) | |
// | |__) | __ ___ ____ _| |_ ___
// | ___/ '__| \ \ / / _` | __/ _ \
// | | | | | |\ V / (_| | || __/
// |_| |_| |_| \_/ \__,_|\__\___|
private State state;
///
/// 救这个男童还需要多长时间
///
[Header("救这个男童还需要多长时间")][SerializeField][ReadOnly]
private float saveNeedTimeLeft;
private YiSa yiSa;
private Animator animator;
// _____ _ _ ____ _
// / ____| | | | _ \ | |
// | | __ _| | | |_) | __ _ ___| | __
// | | / _` | | | _ < / _` |/ __| |/ /
// | |___| (_| | | | |_) | (_| | (__| <
// \_____\__,_|_|_|____/ \__,_|\___|_|\_\
void Start(){
Init();
}
void Update(){
//若处于被救中状态
if(state == State.saving){
//减少被救需要的剩余时间
saveNeedTimeLeft -= Time.deltaTime;
//判断是否已被救,若已成功被救
if(saveNeedTimeLeft < 0)
//触发被救事件
OnSave();
}
}
// _ _ _
// | \ | | | |
// | \| | ___ _ __ _ __ ___ __ _| |
// | . ` |/ _ \| '__| '_ ` _ \ / _` | |
// | |\ | (_) | | | | | | | | (_| | |
// |_| \_|\___/|_| |_| |_| |_|\__,_|_|
private void Init(){
//找到必须的组件和游戏物体
yiSa = FindObjectOfType();
animator = GetComponent();
//初始化救这个男童需要的剩余时间
saveNeedTimeLeft = saveNeedTime;
}
///
/// 成功被救的时候触发
///
private void OnSave(){
//修改状态至OK
state = State.OK;
//通知主人自己已被救
yiSa.OnSave(this);
//通知玩家自己已被救
FindObjectOfType().OnSave(this);
//播放被救动画
animator.SetBool("isSaving",true);
}
// ______ _
// | ____| | |
// | |____ _____ _ __ | |_
// | __\ \ / / _ \ '_ \| __|
// | |___\ V / __/ | | | |_
// |______\_/ \___|_| |_|\__|
///
/// 当玩家对男童使用交互
///
public override void OnCall(){
//只有当自己还在等待的时候,才能触发被救
if(state == State.wait)
//修改自身状态至saving
state = State.saving;
}
///
/// 当玩家抬起交互键的时候触发
///
public override void OnCallCancel(){
if(state == State.saving){
Debug.Log("救人中断了");
state = State.wait;
saveNeedTimeLeft = saveNeedTime;
}
}
///
/// 当玩家离开catching范围时触发
///
public override void OnLeave(){
//如果正在救,则触发玩家的中断事件
if(state == State.saving){
FindObjectOfType().OnInteractiveException();
}
}
public override int RetuenState(){
return (int)state;
}
}