113 lines
3.3 KiB
C#
113 lines
3.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class StepControl : MonoBehaviour
|
|
{
|
|
public Transform CameraTrans;//相机
|
|
public int CurrStepIndex;//当前执行的步骤索引号
|
|
Step CurrStep;//当前步骤
|
|
public Transform StepParent;//列表的父物体
|
|
List<Step> StepList;//步骤列表
|
|
int i;
|
|
public AudioSource CorrectAud;
|
|
|
|
void Start()
|
|
{
|
|
//获取步骤列表
|
|
StepList = new List<Step>();
|
|
for (i = 0; i < StepParent.childCount; i++)
|
|
StepList.Add(StepParent.GetChild(i).GetComponent<Step>());
|
|
//执行
|
|
Invoke("StepWork", 2);
|
|
}
|
|
//执行步骤
|
|
bool ifRun,ifAni,ifCheckPos;
|
|
public float Dis;//距离
|
|
public void StepWork()
|
|
{
|
|
if (CurrStepIndex < StepList.Count)
|
|
{
|
|
CurrStep = StepList[CurrStepIndex];//当前步骤
|
|
Debug.Log("当前执行点" + CurrStepIndex.ToString() + ":" + CurrStep.name);
|
|
///////////节点动作:显示物体
|
|
for (i = 0; i < CurrStep.ShowObj.Length; i++)
|
|
CurrStep.ShowObj[i].SetActive(true);
|
|
///////////节点动作:语音播放
|
|
if (CurrStep.Aud != null)
|
|
CurrStep.Aud.Play();
|
|
///////////节点动作:播放动画
|
|
if (CurrStep.Anin != null)
|
|
CurrStep.Anin.Play(CurrStep.AniClipName);
|
|
/////////////////////////////////////////////////////////判断继续类型
|
|
if (CurrStep.ContiKind == ContinueKind.Continue)
|
|
{
|
|
Next();
|
|
}
|
|
else if (CurrStep.ContiKind == ContinueKind.AnimationEnd)
|
|
{
|
|
ifAni = true;
|
|
}
|
|
else if (CurrStep.ContiKind == ContinueKind.CamArrived)
|
|
{
|
|
ifCheckPos = true;
|
|
}
|
|
else
|
|
{ }
|
|
}
|
|
else//结束
|
|
{
|
|
Debug.Log("步骤结束");
|
|
}
|
|
}
|
|
public void Next()
|
|
{
|
|
Invoke("EndWork", CurrStep.DelayNextTime);
|
|
Invoke("StepWork",CurrStep .DelayNextTime );
|
|
CurrStepIndex++;
|
|
}
|
|
void EndWork()//节点的结束工作
|
|
{
|
|
//隐藏物体
|
|
for (i = 0; i < CurrStep.DisObjAtEnd.Length; i++)
|
|
CurrStep.DisObjAtEnd[i].SetActive(false);
|
|
}
|
|
void Update()
|
|
{
|
|
//检测动画结束
|
|
if (ifAni)
|
|
{
|
|
if (!CurrStep.Anin.isPlaying)//结束
|
|
{
|
|
ifAni = false;
|
|
Next();
|
|
}
|
|
}
|
|
//检测到达位置
|
|
if (ifCheckPos)
|
|
{
|
|
Dis = Mathf.Abs(CameraTrans.position.x - CurrStep.AimTrans.position.x) + Mathf.Abs(CameraTrans.position.z - CurrStep.AimTrans.position.z);
|
|
if (Dis < 2)
|
|
{
|
|
ifCheckPos = false;
|
|
CurrStep.AimTrans.gameObject.SetActive(false);
|
|
CorrectAud.Play();
|
|
Next();
|
|
}
|
|
}
|
|
}
|
|
public void LoadScene(int sNum)
|
|
{
|
|
SceneManager.LoadScene(sNum);
|
|
}
|
|
}
|
|
//节点触发继续的类型:
|
|
public enum ContinueKind
|
|
{
|
|
Continue,//直接继续
|
|
Wait,//等待交互
|
|
CamArrived,//相机到达目标位置
|
|
AnimationEnd//等待动画结束
|
|
};
|