Init repository
This commit is contained in:
Executable file
+34
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class AudioBundleLoader : MonoBehaviour
|
||||
{
|
||||
public string AudioAssetBundleName = "AudioAssets.bunl";
|
||||
public AssetBundle AudioAssetBundle;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SceneManager.activeSceneChanged += delegate
|
||||
{
|
||||
if (AudioAssetBundle)
|
||||
AudioAssetBundle.Unload(true);
|
||||
};
|
||||
InitializeAudioAssetBundle();
|
||||
}
|
||||
public void InitializeAudioAssetBundle()
|
||||
{
|
||||
Debug.Log("Setting asset bundles... (1)");
|
||||
AudioAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "Audio", "AudioAssets.bunl"));
|
||||
}
|
||||
public AssetBundle GetAudioAssetBundle()
|
||||
{
|
||||
return AudioAssetBundle;
|
||||
}
|
||||
public AudioClip GetAudioClipFromAssetBundle(string AudioFileName)
|
||||
{
|
||||
return AudioAssetBundle.LoadAsset<AudioClip>(AudioFileName);
|
||||
}
|
||||
|
||||
}
|
||||
Executable file
+21
@@ -0,0 +1,21 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LoadImageFromStreamingAssets : MonoBehaviour
|
||||
{
|
||||
public Image LoadToObject;
|
||||
public string ImagePathFromStreamingAssets;
|
||||
void Start()
|
||||
{
|
||||
Texture2D texture = new(2,2);
|
||||
texture.LoadImage(File.ReadAllBytes(Path.Combine(Application.streamingAssetsPath, ImagePathFromStreamingAssets)));
|
||||
|
||||
Debug.Log("Loaded texture " + texture.name);
|
||||
|
||||
if (LoadToObject)
|
||||
{
|
||||
LoadToObject.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable file
+15
@@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Video;
|
||||
public class LoadVideoFromStreamingAssets : MonoBehaviour
|
||||
{
|
||||
|
||||
public VideoPlayer videoPlayer;
|
||||
public string VideoPathFromStreamingAssets;
|
||||
void Start()
|
||||
{
|
||||
videoPlayer.url = Path.Combine(Application.streamingAssetsPath, VideoPathFromStreamingAssets);
|
||||
}
|
||||
}
|
||||
Executable file
+26
@@ -0,0 +1,26 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.Video;
|
||||
|
||||
public class VideoBundleLoader : MonoBehaviour
|
||||
{
|
||||
public AssetBundle VideoAssetBundle;
|
||||
public string VideoAssetBundleName = "VideoAssets.bunl";
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SceneManager.activeSceneChanged += delegate
|
||||
{
|
||||
if (VideoAssetBundle)
|
||||
VideoAssetBundle.Unload(true);
|
||||
};
|
||||
VideoAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "Video", VideoAssetBundleName));
|
||||
}
|
||||
|
||||
public VideoClip GetVideoClipFromAssetBundle(AssetBundle VideoAssetBundle, string VideoFileName)
|
||||
{
|
||||
return VideoAssetBundle.LoadAsset<VideoClip>(VideoFileName);
|
||||
}
|
||||
|
||||
}
|
||||
Executable file
+99
@@ -0,0 +1,99 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Video;
|
||||
|
||||
public class VideoTest : MonoBehaviour
|
||||
{
|
||||
public GameObject VideoPlayerObject;
|
||||
VideoPlayer videoPlayer;
|
||||
public string VideoFileName = "test1.mp4";
|
||||
|
||||
public bool ScriptPlaysVideoOnMouseDown = false;
|
||||
public bool ScriptStopsVideoOnMouseDown = false;
|
||||
public RawImage UIViewport;
|
||||
public bool UseAssetBundles = false;
|
||||
public AssetBundle VideoBundle;
|
||||
public VideoBundleLoader BundleLoader;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
videoPlayer = VideoPlayerObject.GetComponent<VideoPlayer>();
|
||||
if (UseAssetBundles && BundleLoader)
|
||||
VideoBundle = BundleLoader.VideoAssetBundle;
|
||||
}
|
||||
|
||||
public void SetVideoFileName(string filename)
|
||||
{
|
||||
VideoFileName = filename;
|
||||
}
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
if (ScriptPlaysVideoOnMouseDown)
|
||||
{
|
||||
PlayVideo();
|
||||
}
|
||||
else if (ScriptStopsVideoOnMouseDown)
|
||||
{
|
||||
StopVideo();
|
||||
}
|
||||
else
|
||||
{
|
||||
SetVideoUrlFromBundle();
|
||||
}
|
||||
}
|
||||
public void SetVideoUrl()
|
||||
{
|
||||
VideoFileName = Path.Combine(Application.streamingAssetsPath, "Video", VideoFileName);
|
||||
if (!File.Exists(VideoFileName))
|
||||
{
|
||||
Debug.LogError("Video not found: " + VideoFileName);
|
||||
VideoFileName = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
videoPlayer.url = VideoFileName;
|
||||
videoPlayer.Stop();
|
||||
Debug.LogError("Set videoPlayer URL to " + VideoFileName);
|
||||
}
|
||||
//VideoPlayerObject.transform.localScale = new Vector3(videoPlayer.clip.width / 16 / 4, videoPlayer.clip.height / 16 / 4);
|
||||
}
|
||||
|
||||
public void SetVideoUrlFromBundle()
|
||||
{
|
||||
if (VideoBundle == null)
|
||||
{
|
||||
Debug.Log("Failed to load VideoBundle!");
|
||||
return;
|
||||
}
|
||||
VideoClip clip = VideoBundle.LoadAsset<VideoClip>(VideoFileName);
|
||||
videoPlayer.clip = clip;
|
||||
videoPlayer.Stop();
|
||||
Debug.LogError("Loaded video from assetbundle: " + VideoBundle.name + " " + clip.name);
|
||||
}
|
||||
|
||||
public void PlayVideo()
|
||||
{
|
||||
Debug.Log("Tried playing " + VideoFileName);
|
||||
videoPlayer.Play();
|
||||
}
|
||||
public void PlayUIVideo()
|
||||
{
|
||||
if (UIViewport)
|
||||
{
|
||||
videoPlayer.renderMode = VideoRenderMode.RenderTexture;
|
||||
//videoPlayer.Prepare();
|
||||
|
||||
UIViewport.texture = videoPlayer.texture;
|
||||
videoPlayer.Play();
|
||||
}
|
||||
}
|
||||
public void StopVideo()
|
||||
{
|
||||
Debug.Log("Tried stopping playback of " + VideoFileName);
|
||||
if (videoPlayer.isPaused)
|
||||
videoPlayer.Stop();
|
||||
videoPlayer.Pause();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user