123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- 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;
- /// <summary>
- /// 资源类型,后续扩展
- /// </summary>
- public enum ArtActionType
- {
- /// <summary>
- /// 未完成
- /// </summary>
- WAIT = -1,
- /// <summary>
- /// 未完成
- /// </summary>
- ACTION = 0,
- /// <summary>
- /// 完成
- /// </summary>
- 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<Animator>().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<BoxCollider>();
- startAction.GetComponentInChildren<Animator>().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<Animator>().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<Animator>().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<Animator>().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;
- }
- }
|