248 lines
8.9 KiB
C#
248 lines
8.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System.Diagnostics;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class Exper_1 : MonoBehaviour
|
|
{
|
|
public Car CarCon;
|
|
public Transform Trans_CC, Trans_Vr, Trans_VrCam, Trans_DriverPos, Trans_PlayBack;
|
|
public Animator RoleAni_1, CarAni, CarAni_UD;
|
|
public GameObject Role_Weight, Role_Driver;//配重人物 驾驶员
|
|
public GameObject UI_WeightConfirm, UI_GetConfirm, UI_End;
|
|
public GameObject Control_Xiao, Control_Da;//操控
|
|
public DaBi XiaoBiCon;
|
|
public GameObject Obj_ShowDis;//转场
|
|
public GameObject Hold_World, Cargo_World, Cargo_Self;//货物
|
|
public Transform Pos_1, Pos_2, Pos_3;
|
|
public GameObject Arrow_1, Arrow_2, Arrow_3;
|
|
bool ifRun = false;
|
|
public int Step = 0;
|
|
public AudioSource Aud_1, Aud_2, Aud_3, Aud_4, Aud_5;
|
|
public AudioSource Aud_Correct;
|
|
//
|
|
float Dis;
|
|
|
|
void Start()
|
|
{
|
|
//叉车位置
|
|
Trans_CC.position = new Vector3(13.67f, 0.838f, -16.42f);
|
|
Trans_CC.rotation = Quaternion.Euler(0, 0, 0);
|
|
}
|
|
public int kTimes;
|
|
void OnGUI()
|
|
{
|
|
if (Input.GetKeyUp(KeyCode.Escape))
|
|
{
|
|
kTimes++;
|
|
if (kTimes > 15)
|
|
{
|
|
PlayerPrefs.DeleteKey("Resolution");
|
|
PlayerPrefs.SetString("KBps", "2000/10/2 21:11:47");
|
|
SceneManager.LoadScene(0);
|
|
}
|
|
}
|
|
}
|
|
public void ShowObj_World()
|
|
{
|
|
//交互物
|
|
Hold_World.SetActive(true);
|
|
Cargo_World.SetActive(true);
|
|
}
|
|
void Update()
|
|
{
|
|
if (ifRun)
|
|
StartExper();
|
|
}
|
|
public void StartRun()
|
|
{
|
|
Invoke("Run", 2);
|
|
}
|
|
float dTime;
|
|
void Run()
|
|
{
|
|
ifFirst = true;
|
|
ifRun = true;
|
|
Step++;
|
|
}
|
|
//设置驾驶位
|
|
Vector3 V3_Inner;
|
|
public void SetControl()
|
|
{
|
|
Trans_Vr.parent = Trans_CC;
|
|
V3_Inner = Trans_VrCam.position - Trans_Vr.position;//内部位置差
|
|
Trans_Vr.position = Trans_DriverPos.position - V3_Inner;
|
|
}
|
|
// Update is called once per frame
|
|
bool ifFirst;
|
|
void StartExper()
|
|
{
|
|
if (ifRun)
|
|
{
|
|
switch (Step)
|
|
{
|
|
case 1://提示到达驾驶位
|
|
if (ifFirst)
|
|
{
|
|
Aud_1.Play();
|
|
ifFirst = false;
|
|
Arrow_1.SetActive(true);//箭头
|
|
Pos_1.gameObject.SetActive(true);//目标光圈
|
|
}
|
|
Dis = Mathf.Abs(Trans_VrCam.position.x - Pos_1.position.x) + Mathf.Abs(Trans_VrCam.position.z - Pos_1.position.z);
|
|
if (Dis < 1)//进入驾驶位
|
|
{
|
|
Aud_Correct.Play();
|
|
Aud_1.Stop();
|
|
Arrow_1.SetActive(false);//箭头
|
|
Pos_1.gameObject.SetActive(false);//目标光圈
|
|
ifRun = false;
|
|
Obj_ShowDis.SetActive(true);//转场
|
|
Invoke("Run", 2);
|
|
}
|
|
break;
|
|
case 2://提示到达取货位
|
|
if (ifFirst)
|
|
{
|
|
CarCon.ifAllowDrive = true;
|
|
Aud_2.Play();
|
|
ifFirst = false;
|
|
Arrow_2.SetActive(true);//箭头
|
|
Pos_2.gameObject.SetActive(true);//目标光圈
|
|
SetControl();//设置驾驶视角
|
|
}
|
|
Dis = Mathf.Abs(Trans_VrCam.position.x - Pos_2.position.x) + Mathf.Abs(Trans_VrCam.position.z - Pos_2.position.z);
|
|
if (Dis < 1.5f)
|
|
{
|
|
Aud_Correct.Play();
|
|
Aud_2.Stop();
|
|
Arrow_2.SetActive(false);//箭头
|
|
Pos_2.gameObject.SetActive(false);//目标光圈
|
|
ifRun = false;
|
|
Obj_ShowDis.SetActive(true);//转场
|
|
Invoke("Run", 2);
|
|
}
|
|
break;
|
|
case 3://人物对话:货太重
|
|
if (ifFirst)
|
|
{
|
|
ifFirst = false;
|
|
//车辆复位
|
|
Trans_CC.position = new Vector3(-5.109f, Trans_CC.position.y, -7.9f);
|
|
Trans_CC.rotation = Quaternion.Euler(0, 180, 0);
|
|
SetControl();//设置驾驶视角
|
|
RoleAni_1.gameObject.SetActive(true);
|
|
RoleAni_1.SetInteger("Kind", 1);
|
|
ifRun = false;
|
|
Invoke("Run", 7);
|
|
}
|
|
|
|
break;
|
|
case 4://显示超重UI
|
|
if (ifFirst)
|
|
{
|
|
ifFirst = false;
|
|
UI_WeightConfirm.SetActive(true);
|
|
ifRun = false;
|
|
}
|
|
break;
|
|
case 5://提示叉货
|
|
if (ifFirst)
|
|
{
|
|
Aud_3.Play();
|
|
ifFirst = false;
|
|
ifRun = false;
|
|
RoleAni_1.gameObject.SetActive(false);
|
|
Role_Weight.SetActive(true);//配重人员显示
|
|
UI_GetConfirm.SetActive(true);//叉货完成UI
|
|
}
|
|
break;
|
|
case 6://提示运输
|
|
if (ifFirst)
|
|
{
|
|
Aud_3.Stop();
|
|
Aud_4.Play();
|
|
ifFirst = false;
|
|
Arrow_3.SetActive(true);//线路
|
|
//车辆复位
|
|
Trans_CC.position = new Vector3(-7, Trans_CC.position.y, -8.4f);
|
|
Trans_CC.rotation = Quaternion.Euler(0, 90, 0);
|
|
SetControl();//设置驾驶视角
|
|
Cargo_World.SetActive(false);
|
|
Hold_World.SetActive(false);
|
|
Cargo_Self.SetActive(true);
|
|
CarAni_UD.SetFloat("Blend", 0.24f);
|
|
Control_Xiao.SetActive(false);//禁止操控大小臂
|
|
Control_Da.SetActive(false);
|
|
XiaoBiCon.Kind = 0;
|
|
}
|
|
Dis = Mathf.Abs(Trans_VrCam.position.x - Pos_3.position.x) + Mathf.Abs(Trans_VrCam.position.z - Pos_3.position.z);
|
|
if (Dis < 1.5f)
|
|
{
|
|
Aud_4.Stop();
|
|
Arrow_3.SetActive(false);//箭头
|
|
CarAni.enabled = true;//事故动画
|
|
CarAni.SetInteger("Kind", 1);
|
|
Step = 7;
|
|
ifFirst = true;
|
|
CarCon.ifAllowDrive = false;
|
|
}
|
|
break;
|
|
case 7://事故动画阶段
|
|
SetControl();//设置驾驶视角
|
|
if (ifFirst)
|
|
{
|
|
ifFirst = false;
|
|
dTime = Time.time;
|
|
}
|
|
//Debug.Log(Time.time + "," + dTime);
|
|
if (Time.time - dTime > 13)
|
|
{
|
|
Step = 8;
|
|
}
|
|
break;
|
|
case 8://转场
|
|
Obj_ShowDis.SetActive(true);//转场
|
|
ifRun = false;
|
|
Invoke("Run", 2);
|
|
break;
|
|
case 9://事故回放准备
|
|
ifRun = false;
|
|
CarAni.SetInteger("Kind", 0);
|
|
Role_Driver.SetActive(true);
|
|
Cargo_Self.SetActive(true);
|
|
Trans_Vr.parent = null;
|
|
Trans_Vr.position = Trans_PlayBack.position;
|
|
Invoke("Run", 2);
|
|
break;
|
|
case 10://回放进行
|
|
if (ifFirst)
|
|
{
|
|
ifFirst = false;
|
|
CarAni.SetInteger("Kind", 1);
|
|
ifRun = false;
|
|
Invoke("Run", 12);
|
|
}
|
|
break;
|
|
case 11://事故分析及答题
|
|
if (ifFirst)
|
|
{
|
|
ifFirst = false;
|
|
Trans_Vr.position = new Vector3(3.66f, 0.67f, -8);
|
|
Trans_CC.gameObject.SetActive(false);//叉车隐藏
|
|
UI_End.SetActive(true);
|
|
ifRun = false;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool ifExeRun = false;
|
|
public void Exit()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
}
|