diff options
author | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
commit | 6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch) | |
tree | 7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/Video |
+scripts
Diffstat (limited to 'Client/Assets/Scripts/Video')
-rw-r--r-- | Client/Assets/Scripts/Video/XVideo.cs | 90 | ||||
-rw-r--r-- | Client/Assets/Scripts/Video/XVideo.cs.meta | 8 | ||||
-rw-r--r-- | Client/Assets/Scripts/Video/XVideoMgr.cs | 62 | ||||
-rw-r--r-- | Client/Assets/Scripts/Video/XVideoMgr.cs.meta | 8 |
4 files changed, 168 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
+}
diff --git a/Client/Assets/Scripts/Video/XVideo.cs.meta b/Client/Assets/Scripts/Video/XVideo.cs.meta new file mode 100644 index 00000000..4c543144 --- /dev/null +++ b/Client/Assets/Scripts/Video/XVideo.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2
+guid: f03e436b095cc8440919d5e981747ede
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/Client/Assets/Scripts/Video/XVideoMgr.cs b/Client/Assets/Scripts/Video/XVideoMgr.cs new file mode 100644 index 00000000..a8a5f0cf --- /dev/null +++ b/Client/Assets/Scripts/Video/XVideoMgr.cs @@ -0,0 +1,62 @@ +using UnityEngine;
+using XUtliPoolLib;
+using System.Collections;
+using System;
+
+public class XVideoMgr : MonoBehaviour, IXVideo
+{
+#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
+ public MovieTexture Movie;
+#endif
+
+ private XVideo _video = null;
+ private AudioSource _audio = null;
+
+ public bool isPlaying { get { return _video != null && _video.isPlaying; } }
+
+ void Start()
+ {
+#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
+ GameObject root = GameObject.Find(@"XGamePoint");
+
+ _video = root.AddComponent<XVideo>();
+ _audio = root.AddComponent<AudioSource>();
+#endif
+ }
+
+ public void Play(bool loop = false)
+ {
+#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
+ {
+ _video.Play(Movie, _audio, loop);
+ }
+#else
+ {
+ Handheld.PlayFullScreenMovie("CG.mp4", Color.black, FullScreenMovieControlMode.CancelOnInput, FullScreenMovieScalingMode.AspectFit);
+ }
+#endif
+ }
+#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
+ void Update()
+ {
+ if (_video.isPlaying && Input.GetMouseButtonUp(0))
+ {
+ _video.Stop();
+ }
+ }
+#endif
+ public void Stop()
+ {
+#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
+ {
+ if (_video != null) _video.Stop();
+ }
+#endif
+ }
+
+ public bool Deprecated
+ {
+ get;
+ set;
+ }
+}
diff --git a/Client/Assets/Scripts/Video/XVideoMgr.cs.meta b/Client/Assets/Scripts/Video/XVideoMgr.cs.meta new file mode 100644 index 00000000..5baef78f --- /dev/null +++ b/Client/Assets/Scripts/Video/XVideoMgr.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2
+guid: 73d2da2a0c8ae0744b020149741199d5
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
|