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.
190 lines
4.6 KiB
190 lines
4.6 KiB
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEditor.Animations;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Pass03Manager : MonoBehaviour
|
|
{
|
|
[Header("相机点位")]
|
|
public List<Transform> cameraPoints;
|
|
[Header("操作步骤")]
|
|
public List<GameObject> ctrlPartList;
|
|
[Header("动画部件")]
|
|
public Animator studentAni;
|
|
[Header("历史操作")]
|
|
public Transform hisitoryInfoParent;
|
|
[Header("关卡提示")]
|
|
public TextWrite PartTipText;
|
|
public List<string> PartTipTxtList;
|
|
public Text errorTip;
|
|
public Text npcStateTxt;
|
|
|
|
private AudioSource audioSource;
|
|
|
|
private Dictionary<string, Action> AniActionDict = new Dictionary<string, Action>();
|
|
|
|
private void Start()
|
|
{
|
|
StartTimeAction(6, () =>
|
|
{
|
|
ChangeCameraPoint(1);
|
|
|
|
SetTip(1,()=> { SetCtrlPart(1); });
|
|
});
|
|
audioSource = GetComponent<AudioSource>();
|
|
InitAniAction();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 动画事件,每关单独做出来
|
|
/// </summary>
|
|
private void InitAniAction()
|
|
{
|
|
|
|
AniActionDict.Add("FuSu", () => {
|
|
|
|
SetCtrlPart(3);
|
|
SetTip(3);
|
|
|
|
});
|
|
|
|
AniActionDict.Add("RGHX", () => {
|
|
|
|
SetNpcSate("仍然无明显反应");
|
|
SetTip("人工呼吸完成,被救者仍然无明显反应");
|
|
PassOver();
|
|
});
|
|
|
|
}
|
|
|
|
|
|
#region 流程函数
|
|
|
|
public void SetNpcSate(string str)
|
|
{
|
|
npcStateTxt.text = str;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 错误提示
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
public void AddTip(string str)
|
|
{
|
|
errorTip.text = str;
|
|
errorTip.transform.parent.gameObject.SetActive(true);
|
|
StartTimeAction(2f, () => { errorTip.transform.parent.gameObject.SetActive(false); });
|
|
}
|
|
public void ErrorTip()
|
|
{
|
|
errorTip.transform.parent.gameObject.SetActive(true);
|
|
StartTimeAction(2f, () => { errorTip.transform.parent.gameObject.SetActive(false); });
|
|
}
|
|
|
|
public void ChangeCameraPoint(int index)
|
|
{
|
|
if (cameraPoints.Count < index) return;
|
|
Camera.main.transform.DOMove(cameraPoints[index - 1].position, 1f);
|
|
Camera.main.transform.DORotate(cameraPoints[index - 1].eulerAngles, 1f);
|
|
}
|
|
|
|
//设置提示
|
|
public void SetTip(int index)
|
|
{
|
|
|
|
PartTipText.ChangeText(PartTipTxtList[index - 1]);
|
|
}
|
|
public void SetTip(int index,Action action)
|
|
{
|
|
|
|
PartTipText.ChangeText(PartTipTxtList[index - 1],action);
|
|
}
|
|
public void SetTip(string str)
|
|
{
|
|
|
|
PartTipText.ChangeText(str);
|
|
}
|
|
/// <summary>
|
|
/// 设置操作步骤部件
|
|
/// </summary>
|
|
/// <param name="index"></param>
|
|
public void SetCtrlPart(int index)
|
|
{
|
|
for (int i = 0; i < ctrlPartList.Count; i++)
|
|
{
|
|
if (i == index - 1)
|
|
{
|
|
ctrlPartList[i].SetActive(true);
|
|
continue;
|
|
}
|
|
ctrlPartList[i].SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void SetStudentAni(string aniName)
|
|
{
|
|
//播放动画
|
|
studentAni.Play(aniName);
|
|
if (AniActionDict.ContainsKey(aniName))
|
|
{
|
|
// 获取AnimatorController
|
|
AnimatorController controller = studentAni.runtimeAnimatorController as AnimatorController;
|
|
|
|
// 获取名为"Walk"的AnimationClip
|
|
AnimationClip clip = controller.animationClips.FirstOrDefault(x => x.name == aniName);
|
|
//获取动画cilp的时间
|
|
float time = clip.length;
|
|
Debug.Log(time);
|
|
StartTimeAction(time, () =>
|
|
{
|
|
Action action;
|
|
if (AniActionDict.TryGetValue(aniName, out action))
|
|
{
|
|
action.Invoke();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
public void AddHisitoryInfo(string info)
|
|
{
|
|
GameObject go = GameObject.Instantiate(Resources.Load<GameObject>("Prefab/hisitoryText"), hisitoryInfoParent);
|
|
Text txt = go.GetComponent<Text>();
|
|
int index = go.transform.GetSiblingIndex() + 1;
|
|
txt.text = index + "-" + info;
|
|
}
|
|
|
|
|
|
public void PassOver()
|
|
{
|
|
AddTip("恭喜通关");
|
|
//向平台发送通关
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
public void StartTimeAction(float time, Action action)
|
|
{
|
|
StartCoroutine(TimeAction(time, action));
|
|
}
|
|
IEnumerator TimeAction(float time, Action action)
|
|
{
|
|
|
|
yield return new WaitForSeconds(time);
|
|
action.Invoke();
|
|
|
|
}
|
|
|
|
|
|
}
|