https://www.bilibili.com/video/BV1Hy4y1S78b/
定制访问
https://item.taobao.com/item.htm?spm=a2oq0.12575281.0.0.50111debJplIKu&ft=t&id=616168034838
主场景代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameChoose : MonoBehaviour
{
private void Awake()
{
Application.runInBackground = true;
Screen.SetResolution(1920, 1080, true);
}
public void ChooseFangkong()
{
SceneManager.LoadScene("fangkong");
}
public void ChooseDiZhen()
{
SceneManager.LoadScene("dizheng");
}
}
using RenderHeads.Media.AVProVideo;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class FangKongUIManager : MonoBehaviour
{
/// <summary>
/// 选择界面
/// </summary>
public GameObject Image_FangKongChooseobj;
/// <summary>
/// 视频界面
/// </summary>
public GameObject Image_video_obj;
/// <summary>
/// 视频播放插件
/// </summary>
public MediaPlayer mediaPlayer;
/// <summary>
/// 视频播放路径
/// </summary>
string strVideoPath;
private void Awake()
{
Application.runInBackground = true;
Screen.SetResolution(1920, 1080, true);
strVideoPath = Application.streamingAssetsPath + "/防空视频/";
}
/// <summary>
/// 点击在防空警报响起如何正确处理
/// </summary>
public void OnClickfangkongjinbaoxiangqizhengquechuli()
{
PlayMediaByPath("防空警报响时正确处理方式", 1180, 699.4f, -25f, 0f);
}
/// <summary>
/// 点击在防空警报知识讲解
/// </summary>
public void OnClickfangkongjingbaozhishijiangjie()
{
PlayMediaByPath("防空警报知识讲解", 1193.9f, 1080, -23.3f, 0);
}
/// <summary>
/// 点击在防空知识讲解
/// </summary>
public void OnClickfangkongzhishijiangjie()
{
PlayMediaByPath("防空知识讲解", 1382, 653, -19, 0);
}
/// <summary>
/// 点击在防空导弹
/// </summary>
public void OnClickfangkongdaodan()
{
PlayMediaByPath("防空导弹", 1170, 1080, -20, 0);
}
/// <summary>
/// 点击在防空洞
/// </summary>
public void OnClickfangkongdong()
{
PlayMediaByPath("防空洞", 1180, 1080, -14);
}
void PlayMediaByPath(string path, float width = 1920, float height = 1080, float posx = 0, float posy = 0)
{
Image_video_obj.SetActive(true);
Image_FangKongChooseobj.SetActive(false);
Image_video_obj.GetComponent<RectTransform>().sizeDelta = new Vector2(width, height);
Image_video_obj.GetComponent<RectTransform>().localPosition = new Vector2(posx, posy);
mediaPlayer.CloseVideo();
mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, strVideoPath + path + ".mp4", true);
mediaPlayer.m_Loop = false;
mediaPlayer.Play();
}
/// <summary>
/// 点击在返回按钮上面
/// </summary>
public void OnClickBack()
{
Image_FangKongChooseobj.SetActive(true);
Image_video_obj.SetActive(false);
mediaPlayer.Stop();
}
public void OnClcikBackToMain()
{
SceneManager.LoadScene("Main");
Resources.UnloadUnusedAssets();
GC.Collect();
}
}
using RenderHeads.Media.AVProVideo;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class DiZhenUIManger : MonoBehaviour
{
public GameObject backobj;
/// <summary>
/// 选择界面
/// </summary>
public GameObject Image_DiZhenChooseobj;
/// <summary>
/// 视频界面
/// </summary>
public GameObject Image_videoBJ_obj;
/// <summary>
/// 视频播放插件
/// </summary>
public MediaPlayer mediaPlayer;
/// <summary>
/// 视频播放路径
/// </summary>
string strVideoPath;
private void Awake()
{
Application.runInBackground = true;
Screen.SetResolution(1920, 1080, true);
strVideoPath = Application.streamingAssetsPath + "/地震视频/";
}
/// <summary>
/// 点击在防空警报响起如何正确处理
/// </summary>
public void OnClicktangshan()
{
PlayMediaByPath("唐山大地震");
}
/// <summary>
/// 点击在防空警报知识讲解
/// </summary>
public void OnClickRiBenShenHu()
{
PlayMediaByPath("日本神户地震");
}
/// <summary>
/// 点击在防空知识讲解
/// </summary>
public void OnClickMiLu()
{
PlayMediaByPath("秘鲁地震");
}
/// <summary>
/// 点击在防空导弹
/// </summary>
public void OnClickyilang()
{
PlayMediaByPath("伊朗地震");
}
/// <summary>
/// 点击在防空洞
/// </summary>
public void OnClickjiujinshan()
{
PlayMediaByPath("旧金山地震");
}
public void OnClickWenChuan()
{
PlayMediaByPath("汶川地震");
}
public void OnClickYuSHu()
{
PlayMediaByPath("玉树地震");
}
public void OnClickHeZe()
{
PlayMediaByPath("菏泽地震");
}
void PlayMediaByPath(string path, float width = 1920, float height = 1080, float posx = 0, float posy = 0)
{
backobj.SetActive(false);
Image_videoBJ_obj.SetActive(true);
Image_DiZhenChooseobj.SetActive(false);
//Image_videoBJ_obj.transform.GetChild(0).GetComponent<RectTransform>().sizeDelta = new Vector2(width, height);
Image_videoBJ_obj.GetComponent<RectTransform>().localPosition = new Vector2(posx, posy);
mediaPlayer.CloseVideo();
mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, strVideoPath + path + ".mp4", true);
mediaPlayer.m_Loop = false;
mediaPlayer.Play();
}
/// <summary>
/// 点击在返回按钮上面
/// </summary>
public void OnClickBack()
{
backobj.SetActive(true);
Image_DiZhenChooseobj.SetActive(true);
Image_videoBJ_obj.SetActive(false);
mediaPlayer.Stop();
}
public void OnClickBackToMian()
{
SceneManager.LoadScene("Main");
Resources.UnloadUnusedAssets();
GC.Collect();
}
}