148 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			148 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| using UnityEngine.UI;
 | |
| using UnityEngine.Video;
 | |
| 
 | |
| /// <summary>
 | |
| /// 起重机屏幕控制(场景跳转、视频播放)
 | |
| /// </summary>
 | |
| public class DisplayScreenController : MonoBehaviour
 | |
| {
 | |
|     public GameObject[] AllRawImage;
 | |
|     [Header("视频播放")]
 | |
|     public Button SPBFRetrueBtn; //视频播放返回按钮
 | |
|     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 Button JGZCBtn; // 结构组成
 | |
|     public Button GNYLBtn; // 功能原理
 | |
|     public Button MNCZBtn; // 模拟操作
 | |
| 
 | |
|     [Header("设备拆解返回按钮")]
 | |
|     public Button SBCJRetrueBtn; //设备拆解返回按钮
 | |
| 
 | |
|     [Header("操作界面")]
 | |
|     public GameObject CZJMCanvas; //起重机操作界面
 | |
|     public Button CZJMRetrueBtn; //起重机操作界面返回按钮
 | |
| 
 | |
|     public void Init()
 | |
|     {
 | |
|         for (int i = 0; i < AllRawImage.Length; i++)
 | |
|         {
 | |
|             AllRawImage[i].SetActive(i == 0);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void Awake()
 | |
|     {
 | |
|         Init();
 | |
|     }
 | |
|     void Start()
 | |
|     {
 | |
|         JGZCBtn.onClick.AddListener(() =>
 | |
|         {
 | |
|             Debug.Log("JGZCBtn");
 | |
|             for (int i = 0; i < AllRawImage.Length; i++)
 | |
|             {
 | |
|                 AllRawImage[i].SetActive(i == 3);
 | |
|             }
 | |
|         });
 | |
|         GNYLBtn.onClick.AddListener(() =>
 | |
|         {
 | |
|             Debug.Log("GNYLBtn");
 | |
|             for (int i = 0; i < AllRawImage.Length; i++)
 | |
|             {
 | |
|                 AllRawImage[i].SetActive(i == 1);
 | |
|             }
 | |
|         });
 | |
|         MNCZBtn.onClick.AddListener(() =>
 | |
|         {
 | |
|             Debug.Log("模拟操作");
 | |
|             for (int i = 0; i < AllRawImage.Length; i++)
 | |
|             {
 | |
|                 AllRawImage[i].SetActive(i == 2);
 | |
|             }
 | |
|             CZJMCanvas.SetActive(true);
 | |
|         });
 | |
|         SBCJRetrueBtn.onClick.AddListener(() =>
 | |
|         {
 | |
|             Debug.Log("设备拆解返回按钮");
 | |
|             for (int i = 0; i < AllRawImage.Length; i++)
 | |
|             {
 | |
|                 AllRawImage[i].SetActive(i == 0);
 | |
|             }
 | |
|         });
 | |
|         CZJMRetrueBtn.onClick.AddListener(() =>
 | |
|         {
 | |
|             Debug.Log("起重机操作界面返回按钮");
 | |
|             for (int i = 0; i < AllRawImage.Length; i++)
 | |
|             {
 | |
|                 AllRawImage[i].SetActive(i == 0);
 | |
|             }
 | |
|             CZJMCanvas.SetActive(false);
 | |
|         });
 | |
|         SPBFRetrueBtn.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;
 | |
|         });
 | |
|     }
 | |
| 
 | |
|     // Update is called once per frame
 | |
|     void Update()
 | |
|     {
 | |
|         
 | |
|     }
 | |
| }
 |