summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/Video/XVideo.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/Video/XVideo.cs
+scripts
Diffstat (limited to 'Client/Assets/Scripts/Video/XVideo.cs')
-rw-r--r--Client/Assets/Scripts/Video/XVideo.cs90
1 files changed, 90 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/Video/XVideo.cs b/Client/Assets/Scripts/Video/XVideo.cs
new file mode 100644
index 00000000..10251b00
--- /dev/null
+++ b/Client/Assets/Scripts/Video/XVideo.cs
@@ -0,0 +1,90 @@
+using UnityEngine;
+using System.Collections;
+using XUtliPoolLib;
+
+public class XVideo : MonoBehaviour
+{
+ //// Use this for initialization
+ //void Start()
+ //{
+
+ //}
+
+ //// Update is called once per frame
+ //void Update()
+ //{
+
+ //}
+
+#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
+ private MovieTexture _movieTexture = null;
+ private AudioSource _audio = null;
+
+ private bool _avoid_serialize_bug = false;
+ private bool _is_waiting = false;
+
+ public bool isPlaying { get { return _is_waiting || (_movieTexture != null && _movieTexture.isPlaying); } }
+
+ public void Stop()
+ {
+ if (_movieTexture.isPlaying)
+ {
+ _movieTexture.Stop();
+ if (_audio != null)
+ _audio.Stop();
+ }
+
+ _is_waiting = false;
+
+ _movieTexture = null;
+ _audio = null;
+ }
+
+ public void Play(MovieTexture movie, AudioSource audio, bool loop)
+ {
+ _movieTexture = movie;
+ if (_movieTexture != null)
+ {
+ _movieTexture.loop = loop;
+ _audio = audio;
+
+ _avoid_serialize_bug = false;
+ _is_waiting = true;
+
+ StartCoroutine(StartStream());
+ }
+
+ }
+
+ protected IEnumerator StartStream()
+ {
+ if (_movieTexture != null)
+ {
+ _movieTexture.Stop();
+ _movieTexture.Play();
+
+ if (_movieTexture.audioClip != null)
+ {
+ _audio.clip = _movieTexture.audioClip;
+ _audio.Play();
+ }
+
+ yield return null;
+
+ _avoid_serialize_bug = true;
+ }
+ }
+
+ void OnGUI()
+ {
+ if (_movieTexture != null && _movieTexture.isPlaying && _avoid_serialize_bug)
+ {
+ _is_waiting = false;
+ GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), _movieTexture, ScaleMode.ScaleToFit);
+ }
+ }
+#else
+ public bool isDownloading { get { return false; } }
+ public bool isPlaying { get { return false; } }
+#endif
+}