少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using UnityEngine;
using System.Collections;
using Snxxz.UI;
using UnityEngine.Video;
using System;
 
public class MoviePlayer : MonoBehaviour
{
    static MoviePlayer m_Instance;
    public static MoviePlayer Instance {
        get {
            if (m_Instance == null)
            {
                var prefab = BuiltInLoader.LoadPrefab("MoviePlayer");
                var go = Instantiate(prefab);
                go.name = "MoviePlayer";
                go.transform.position = new Vector3(1000, 4000, 1000);
                m_Instance = go.GetComponent<MoviePlayer>();
                m_Instance.m_VideoCamera.enabled = false;
            }
 
            return m_Instance;
        }
    }
 
    [SerializeField] VideoPlayer m_VideoPlayer;
    [SerializeField] AudioSource m_AudioSource;
    [SerializeField] Camera m_VideoCamera;
 
    public bool isPlaying { get; private set; }
    Action onComplete;
 
    public void Play(string name, Action onComplete)
    {
        var clip = VideoLoader.Load(name);
        if (clip == null)
        {
            return;
        }
 
        this.onComplete = onComplete;
 
        m_VideoPlayer.aspectRatio = VideoAspectRatio.FitInside;
        m_VideoPlayer.clip = clip;
        m_VideoPlayer.SetTargetAudioSource(0, m_AudioSource);
        m_VideoPlayer.Play();
 
        m_VideoCamera.enabled = true;
        SoundPlayer.Instance.mute = true;
        isPlaying = true;
 
        Clock.AlarmAfter(clip.length, () => { Stop(); });
    }
 
    public void Stop()
    {
        if (!isPlaying)
        {
            return;
        }
 
        isPlaying = false;
        m_VideoCamera.enabled = false;
        SoundPlayer.Instance.mute = false;
        if (m_VideoPlayer.isPlaying)
        {
            m_VideoPlayer.Stop();
            m_VideoPlayer.clip = null;
        }
 
        if (onComplete != null)
        {
            onComplete();
            onComplete = null;
        }
    }
 
 
}