using BeinLab.Util;
using ShadowStudio.Model;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XRTool.Util;
using static ArtTaskInfo;
public class ArtTaskAction : MonoBehaviour
{
public ArtContainerHandler artContainerHandler;
///
/// 资源类型,后续扩展
///
public enum ArtActionType
{
///
/// 未完成
///
WAIT = -1,
///
/// 未完成
///
ACTION = 0,
///
/// 完成
///
FINISH = 1,
}
public ArtActionType aaType;
public TaskType ttype;
public GameObject actionGame;
public GameObject startAction;
public GameObject Action;
public GameObject finishAction;
public GameObject endAction;
public GameObject playBt;
public GameObject effect;
public GameObject Tip1;
public GameObject TipError;
private void OnDestroy()
{
ArtTaskInfo.removeTask(this);
}
public void ShowTipError()
{
Action.GetComponentInChildren().enabled = false;
Tip1.SetActive(false);
TipError.SetActive(true);
TimerMgr.Instance.CreateTimer(() => {
Tip1.SetActive(true);
TipError.SetActive(false);
}, 3f);
}
public void showPlayBt(bool isShow)
{
if(CommonMethod.isLookRoom())
{
playBt.SetActive(false);
}
else
{
playBt.SetActive(isShow);
}
}
private void Start()
{
if(!isInit)
{
// initAction();
setType(ArtActionType.WAIT);
showPlayBt(true);
}
ArtTaskInfo.addTask(this);
}
BoxCollider box;
private void initAction()
{
box = playBt.GetComponentInChildren();
startAction.GetComponentInChildren().enabled = false;
startAction.SetActive(true);
Action.SetActive(false);
finishAction.SetActive(false);
endAction.SetActive(false);
TimerMgr.Instance.CreateTimer(() => {
box.enabled = true;
}, 1f);
}
public void playAction()
{
effect.SetActive(false);
startAction.GetComponentInChildren().enabled = true;
startAction.SetActive(true);
Action.SetActive(false);
finishAction.SetActive(false);
endAction.SetActive(false);
TimerMgr.Instance.CreateTimer(() => {
showPlayBt(true);
effect.SetActive(true);
}, 8f);
showPlayBt(false);
}
public void playStartAction()
{
showPlayBt(false);
if (!startAction.GetComponentInChildren().enabled)
{
artContainerHandler.ArtState("task", "Play");
playAction();
}
else
{
StartAction();
artContainerHandler.ArtState("task", "start");
}
}
private void setType(ArtActionType tp)
{
Debug.Log("setType"+tp);
aaType = tp ;
}
public void StartAction()
{
showPlayBt(false);
effect.SetActive(false);
startAction.SetActive(false);
Action.SetActive(true);
finishAction.SetActive(false);
endAction.SetActive(false);
setType(ArtActionType.ACTION);
}
public void showStartAction(bool isSend = false)
{
showPlayBt(false);
startAction.SetActive(true);
Action.SetActive(false);
finishAction.SetActive(false);
endAction.SetActive(false);
}
public void showFinishAction(bool isSend = false)
{
showPlayBt(false);
startAction.SetActive(false);
Action.SetActive(false);
finishAction.SetActive(true);
endAction.SetActive(false);
StartCoroutine(checkFinish(isSend));
if (isSend)
artContainerHandler.ArtState("task", "finish");
setType(ArtActionType.FINISH);
}
IEnumerator checkFinish(bool isSend = false)
{
yield return new WaitForSeconds(0.5f);
AnimatorStateInfo animatorStateInfo = finishAction.GetComponentInChildren().GetCurrentAnimatorStateInfo(0);
// 判断动画是否播放完成
if (animatorStateInfo.normalizedTime >= 1.0f)
{
showEndAction(isSend);
}
else
{
StartCoroutine(checkFinish(isSend));
}
}
public void showEndAction(bool isSend=false)
{
showPlayBt(false);
startAction.SetActive(false);
Action.SetActive(false);
finishAction.SetActive(false);
endAction.SetActive(true);
if(isSend)
artContainerHandler.ArtState("task", "end");
}
private bool isInit;
public void showType(string type)
{
switch (type)
{
case "start":
StartAction();
break;
case "finish":
showFinishAction();
break;
case "end":
showEndAction();
break;
case "Play":
playAction();
break;
}
isInit = true;
}
}