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.
334 lines
8.5 KiB
334 lines
8.5 KiB
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class PassManager : MonoBehaviour
|
|
{
|
|
public static PassManager Instance = null;
|
|
|
|
[Header("动画事件")]
|
|
public AniAction aniAction;
|
|
[Header("相机点位")]
|
|
public List<Transform> cameraPoints;
|
|
[Header("操作步骤")]
|
|
public List<GameObject> ctrlPartList;
|
|
[Header("动画部件")]
|
|
public Animator studentAni;
|
|
public Animator[] npcAni;
|
|
[Header("历史操作")]
|
|
public Transform hisitoryInfoParent;
|
|
private List<Text> historyInfoList=new List<Text>();
|
|
[Header("关卡提示")]
|
|
public TextWrite PartTipText;
|
|
public List<string> PartTipTxtList;
|
|
public Text errorTip;
|
|
public Text npcStateTxt;
|
|
public Text npcHuxiTxt;
|
|
public Text timeTipTxt;
|
|
public GameObject timeOutTip;
|
|
public float startTime = 5f;
|
|
|
|
private float timer = 0f;
|
|
public bool isTest = false;
|
|
[HideInInspector]
|
|
public bool isEnd = false;
|
|
|
|
public AudioSource audioSource;
|
|
|
|
private Dictionary<string, Action> AniActionDict = new Dictionary<string, Action>();
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
private void Start()
|
|
{
|
|
|
|
}
|
|
|
|
public void GameStart()
|
|
{
|
|
StartTimeAction(startTime, () =>
|
|
{
|
|
ChangeCameraPoint(1);
|
|
|
|
SetTip(1, () => { SetCtrlPart(1); });
|
|
|
|
});
|
|
//audioSource = GetComponent<AudioSource>();
|
|
InitAniAction();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (isTest&&!isEnd)
|
|
{
|
|
timer += Time.deltaTime;
|
|
timeTipTxt.text = (240-timer).ToString("0");
|
|
if (timer >= (240))
|
|
{
|
|
//提示通关失败
|
|
timeOutTip.gameObject.SetActive(true);
|
|
isEnd = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 动画事件,每关单独做出来
|
|
/// </summary>
|
|
private void InitAniAction()
|
|
{
|
|
|
|
aniAction.InitAniAction();
|
|
|
|
}
|
|
|
|
|
|
#region 流程函数
|
|
|
|
public void SetNpcSate(string str)
|
|
{
|
|
npcStateTxt.text = str;
|
|
npcHuxiTxt.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.GetComponent<Text>().text = "操作有误,请重新考虑并选择";
|
|
errorTip.transform.parent.gameObject.SetActive(true);
|
|
audioSource.clip = Resources.Load<AudioClip>("Audio/错误提示");
|
|
audioSource.Play();
|
|
StartTimeAction(2f, () => { errorTip.transform.parent.gameObject.SetActive(false); });
|
|
|
|
}
|
|
|
|
|
|
public void ErrorTip(string str)
|
|
{
|
|
errorTip.transform.parent.gameObject.SetActive(true);
|
|
errorTip.GetComponent<Text>().text = str;
|
|
audioSource.clip = Resources.Load<AudioClip>("Audio/错误提示");
|
|
audioSource.Play();
|
|
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)
|
|
{
|
|
if (PartTipTxtList[index] == "")
|
|
{
|
|
PartTipText.transform.parent.gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
PartTipText.ChangeText(PartTipTxtList[index - 1]);
|
|
}
|
|
public void SetTip(int index, Action action)
|
|
{
|
|
|
|
PartTipText.ChangeText(PartTipTxtList[index - 1], action);
|
|
}
|
|
public void SetTip(string str, Action action)
|
|
{
|
|
|
|
PartTipText.ChangeText(str, 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 HideCtrlPart(int index)
|
|
{
|
|
ctrlPartList[index-1].SetActive(false);
|
|
}
|
|
|
|
public void SetStudentAni(string aniName)
|
|
{
|
|
//播放动画
|
|
studentAni.Play(aniName);
|
|
Action action = aniAction.GetAction(aniName);
|
|
if (action != null)
|
|
{
|
|
// 获取AnimatorController
|
|
//var controller = studentAni.runtimeAnimatorController as AnimatorController;
|
|
|
|
AnimationClip[] clips = studentAni.runtimeAnimatorController.animationClips;
|
|
AnimationClip clip = null;
|
|
for (int i = 0; i < clips.Length; i++)
|
|
{
|
|
if (clips[i].name == aniName)
|
|
{
|
|
clip = clips[i];
|
|
}
|
|
}
|
|
// 获取名为"Walk"的AnimationClip
|
|
// AnimationClip clip = controller.animationClips.FirstOrDefault(x => x.name == aniName);
|
|
//获取动画cilp的时间
|
|
float time = clip.length;
|
|
Debug.Log(time);
|
|
StartTimeAction(time, () =>
|
|
{
|
|
action.Invoke();
|
|
});
|
|
}
|
|
}
|
|
public void SetStudentAni(string aniName,float fadetime)
|
|
{
|
|
//播放动画
|
|
// studentAni.Play(aniName);
|
|
studentAni.Play(aniName, -1, fadetime);
|
|
Action action = aniAction.GetAction(aniName);
|
|
if (action != null)
|
|
{
|
|
// 获取AnimatorController
|
|
//var controller = studentAni.runtimeAnimatorController as AnimatorController;
|
|
|
|
AnimationClip[] clips = studentAni.runtimeAnimatorController.animationClips;
|
|
AnimationClip clip = null;
|
|
for (int i = 0; i < clips.Length; i++)
|
|
{
|
|
if (clips[i].name == aniName)
|
|
{
|
|
clip = clips[i];
|
|
}
|
|
}
|
|
// 获取名为"Walk"的AnimationClip
|
|
// AnimationClip clip = controller.animationClips.FirstOrDefault(x => x.name == aniName);
|
|
//获取动画cilp的时间
|
|
float time = clip.length;
|
|
Debug.Log(time);
|
|
StartTimeAction(time-fadetime, () =>
|
|
{
|
|
action.Invoke();
|
|
});
|
|
}
|
|
}
|
|
|
|
public void SetNpcAni(string AniName)
|
|
{
|
|
for (int i = 0; i < npcAni.Length; i++)
|
|
{
|
|
npcAni[i].Play(AniName);
|
|
}
|
|
Debug.Log("NPC动画");
|
|
}
|
|
|
|
public void AddHisitoryInfo(string info)
|
|
{
|
|
for (int i = 0; i < historyInfoList.Count; i++)
|
|
{
|
|
if (historyInfoList[i].text == info)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
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;
|
|
historyInfoList.Add(txt);
|
|
|
|
for (int i = 0; i < historyInfoList.Count; i++)
|
|
{
|
|
historyInfoList[i].color = new Color(0.65f,0.65f,0.65f,1);
|
|
}
|
|
|
|
txt.color = new Color(255, 255, 255, 255);
|
|
|
|
}
|
|
|
|
|
|
public void PassOver()
|
|
{
|
|
AddTip("恭喜通关");
|
|
//向平台发送通关
|
|
EduCoderTool.WebConnecter.Singleton.SendResultToWeb(true);
|
|
}
|
|
|
|
public void LoadScene(string sceneName)
|
|
{
|
|
SceneManager.LoadScene(sceneName);
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
public void PlayAudio(AudioClip clip)
|
|
{
|
|
if (clip != null)
|
|
{
|
|
audioSource.clip = clip;
|
|
audioSource.Play();
|
|
}
|
|
}
|
|
public void PlayLoopAudio(AudioClip clip)
|
|
{
|
|
if (clip != null)
|
|
{
|
|
audioSource.clip = clip;
|
|
audioSource.loop = true;
|
|
audioSource.Play();
|
|
}
|
|
}
|
|
|
|
public void StartTimeAction(float time, Action action)
|
|
{
|
|
StartCoroutine(TimeAction(time, action));
|
|
}
|
|
IEnumerator TimeAction(float time, Action action)
|
|
{
|
|
|
|
yield return new WaitForSeconds(time);
|
|
action.Invoke();
|
|
|
|
}
|
|
|
|
|
|
}
|