예제 #1
0
 MusicObject Borrow()
 {
     if (m_Pool.Count > 0)
     {
         return(m_Pool.Pop());
     }
     else
     {
         return(MusicObject.Create(m_Root));
     }
 }
예제 #2
0
 void Return(MusicObject obj)
 {
     //再生中のメイン分は引いておく
     if (m_Pool.Count < MaxPoolCount)
     {
         m_Pool.Push(obj);
     }
     else
     {
         obj.Destroy();
     }
 }
예제 #3
0
        public static MusicObject Create(Transform parent)
        {
            MusicObject ret = new MusicObject();
            var         obj = new GameObject(nameof(MusicObject));

            obj.hideFlags = parent.hideFlags;
            obj.transform.SetParent(parent);
            var source = obj.AddComponent <AudioSource>();

            source.playOnAwake   = false;
            source.priority      = 0;
            source.loop          = true;
            ret.m_Object         = obj;
            ret.m_Source         = source;
            ret.m_TransformCache = source.transform;
            obj.SetActive(false);
            return(ret);
        }