208 lines
5.8 KiB
C#
208 lines
5.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
using UnityEngine.Video;
|
|
|
|
/// <summary>
|
|
/// 叉车屏幕控制(场景跳转、视频播放)
|
|
/// </summary>
|
|
public class ForkliftScreenController : MonoBehaviour
|
|
{
|
|
[Header("模式界面")]
|
|
public GameObject[] AllRawImage;
|
|
|
|
public Button CZMNBtn; //模拟操作按钮
|
|
public Button SGMNBtn; //事故模拟按钮
|
|
public Button SGAlBtn; //事故案例按钮
|
|
|
|
[Header("事故案例界面")]
|
|
public Button SGANRetrueBtn; //事故案例返回按钮
|
|
public VideoPlayer player; //播放控件
|
|
private bool isMute = false; //是否静音
|
|
public List<Sprite> sprites; //用到的精灵图片
|
|
public Button SoundBtn; //音量按钮图标
|
|
public bool Ismute //是否静音
|
|
{
|
|
get => isMute;
|
|
set
|
|
{
|
|
isMute = value;
|
|
SoundBtn.GetComponent<Image>().sprite = isMute ? sprites[0] : sprites[1];
|
|
player.GetTargetAudioSource(0).mute = isMute;
|
|
}
|
|
}
|
|
public Button MidlePlayBtn; //中间暂停按钮
|
|
public Button PlayBtn; //中间暂停按钮
|
|
private bool isPause = false; //是否暂停
|
|
public bool IsPause //是否暂停
|
|
{
|
|
get => isPause;
|
|
set
|
|
{
|
|
isPause = value;
|
|
PlayBtn.GetComponent<Image>().sprite = isPause ? sprites[2] : sprites[3];
|
|
if (isPause)
|
|
{
|
|
player.Pause();
|
|
MidlePlayBtn.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
player.Play();
|
|
MidlePlayBtn.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
[Header("叉车操作模拟")]
|
|
public GameObject CCCZMNCanvas;
|
|
public Button CCCZMNBtn; //叉车模拟返回按钮
|
|
public GameObject CCMNAllObj; //叉车模拟所有物体
|
|
|
|
[Header("叉车事故模拟-撞车")]
|
|
public GameObject SGMNMNCanvas; //模拟事故界面
|
|
public Button SGMNMNRetrueBtn; //模拟事故返回按钮
|
|
public Animator[] mnsgcar;
|
|
public GameObject SGMNCar_AllObj; //模拟事故-车所有物体
|
|
public Button[] SGYbTN; //事故右上角按钮
|
|
public Texture[] SGTexture; //事故画面
|
|
|
|
[Header("叉车事故模拟-撞人")]
|
|
public Transform person; //被撞人
|
|
public Transform Forklift; //叉车
|
|
private void Awake()
|
|
{
|
|
Init();
|
|
}
|
|
public void Init()
|
|
{
|
|
for (int i = 0; i < AllRawImage.Length; i++)
|
|
{
|
|
AllRawImage[i].SetActive(i == 0);
|
|
}
|
|
|
|
for (int i = 0; i < mnsgcar.Length; i++)
|
|
{
|
|
mnsgcar[i].speed = 0;
|
|
}
|
|
SGMNCar_AllObj.SetActive(false);
|
|
}
|
|
void Start()
|
|
{
|
|
//叉车模拟按钮
|
|
CZMNBtn.onClick.AddListener(() =>
|
|
{
|
|
Debug.Log("CZMNBtn");
|
|
for (int i = 0; i < AllRawImage.Length; i++)
|
|
{
|
|
AllRawImage[i].SetActive(i == 1);
|
|
}
|
|
CCCZMNCanvas.SetActive(true);
|
|
CCMNAllObj.SetActive(true);
|
|
SGMNCar_AllObj.SetActive(false);
|
|
});
|
|
//事故模拟按钮
|
|
SGMNBtn.onClick.AddListener(() =>
|
|
{
|
|
Debug.Log("SGMNBtn");
|
|
for (int i = 0; i < AllRawImage.Length; i++)
|
|
{
|
|
AllRawImage[i].SetActive(i == 2);
|
|
}
|
|
});
|
|
//事故案例按钮
|
|
SGAlBtn.onClick.AddListener(() =>
|
|
{
|
|
Debug.Log("SGAlBtn");
|
|
for (int i = 0; i < AllRawImage.Length; i++)
|
|
{
|
|
AllRawImage[i].SetActive(i == 3);
|
|
}
|
|
});
|
|
//事故案例返回按钮
|
|
SGANRetrueBtn.onClick.AddListener(() =>
|
|
{
|
|
Debug.Log("事故案例返回按钮");
|
|
for (int i = 0; i < AllRawImage.Length; i++)
|
|
{
|
|
AllRawImage[i].SetActive(i == 0);
|
|
}
|
|
});
|
|
PlayBtn.onClick.AddListener(() =>
|
|
{
|
|
IsPause = !IsPause;
|
|
});
|
|
MidlePlayBtn.onClick.AddListener(() =>
|
|
{
|
|
IsPause = !IsPause;
|
|
});
|
|
SoundBtn.onClick.AddListener(() =>
|
|
{
|
|
Ismute = !Ismute;
|
|
});
|
|
|
|
//叉车模拟返回按钮
|
|
CCCZMNBtn.onClick.AddListener(() =>
|
|
{
|
|
Debug.Log("叉车模拟返回按钮");
|
|
for (int i = 0; i < AllRawImage.Length; i++)
|
|
{
|
|
AllRawImage[i].SetActive(i == 0);
|
|
}
|
|
CCCZMNCanvas.SetActive(false);
|
|
CCMNAllObj.SetActive(false);
|
|
});
|
|
|
|
//模拟事故事故一按钮
|
|
SGYbTN[0].onClick.AddListener(() =>
|
|
{
|
|
RawImage rawImage0 = AllRawImage[2].GetComponent<RawImage>();
|
|
if (rawImage0 == null)
|
|
{
|
|
Debug.Log("rawImage0为null");
|
|
}
|
|
else
|
|
{
|
|
rawImage0.texture = SGTexture[0];
|
|
for (int i = 0; i < mnsgcar.Length; i++)
|
|
{
|
|
mnsgcar[i].speed = 1;
|
|
}
|
|
SGMNMNCanvas.SetActive(true);
|
|
SGMNCar_AllObj.SetActive(true);
|
|
Debug.Log("事故一");
|
|
}
|
|
});
|
|
//模拟事故事故二按钮
|
|
SGYbTN[1].onClick.AddListener(() =>
|
|
{
|
|
RawImage rawImage1 = AllRawImage[2].GetComponent<RawImage>();
|
|
if (rawImage1 == null)
|
|
{
|
|
Debug.Log("rawImage1为null");
|
|
}
|
|
else
|
|
{
|
|
rawImage1.texture = SGTexture[1];
|
|
Forklift.transform.DOMove(new Vector3(823.72f,9.48f,343.11f), 4f);
|
|
person.transform.DOMove(new Vector3(823.58f,9.493f,341.27f), 5f);
|
|
Debug.Log("事故二");
|
|
}
|
|
});
|
|
|
|
//模拟事故返回按钮
|
|
SGMNMNRetrueBtn.onClick.AddListener(() =>
|
|
{
|
|
Debug.Log("模拟事故返回按钮");
|
|
for (int i = 0; i < AllRawImage.Length; i++)
|
|
{
|
|
AllRawImage[i].SetActive(i == 0);
|
|
}
|
|
SGMNMNCanvas.SetActive(false);
|
|
});
|
|
}
|
|
}
|