コード例 #1
0
ファイル: AudioHTML.cs プロジェクト: spicysoft/h5-count-shape
 protected override void StopSource(Entity e)
 {
     if (EntityManager.HasComponent <AudioHTMLSource>(e))
     {
         AudioHTMLSource audioNativeSource = EntityManager.GetComponentData <AudioHTMLSource>(e);
         if (audioNativeSource.sourceID > 0)
         {
             AudioHTMLNativeCalls.Stop(audioNativeSource.sourceID, true);
         }
     }
 }
コード例 #2
0
ファイル: AudioHTML.cs プロジェクト: spicysoft/h5-count-shape
 protected override bool IsPlaying(Entity e)
 {
     if (EntityManager.HasComponent <AudioHTMLSource>(e))
     {
         AudioHTMLSource audioHtmlSource = EntityManager.GetComponentData <AudioHTMLSource>(e);
         if (audioHtmlSource.sourceID > 0)
         {
             return(AudioHTMLNativeCalls.IsPlaying(audioHtmlSource.sourceID));
         }
     }
     return(false);
 }
コード例 #3
0
ファイル: AudioHTML.cs プロジェクト: spicysoft/h5-count-shape
        protected override bool PlaySource(Entity e)
        {
            var mgr = EntityManager;

            if (mgr.HasComponent <AudioSource>(e))
            {
                AudioSource audioSource = mgr.GetComponentData <AudioSource>(e);

                if (mgr.HasComponent <AudioHTMLSource>(e))
                {
                    // If there is a native source and it is IsPlaying() then
                    // can't play another, but we are done. (So return true.)
                    // Note that IsPlaying() is synchronous (which is what we want)
                    // as opposed to isPlaying which is async.
                    AudioHTMLSource ans = mgr.GetComponentData <AudioHTMLSource>(e);
                    if (AudioHTMLNativeCalls.IsPlaying(ans.sourceID))
                    {
                        return(true);
                    }
                }


                Entity clipEntity = audioSource.clip;
                if (mgr.HasComponent <AudioHTMLClip>(clipEntity))
                {
                    AudioHTMLClip clip = mgr.GetComponentData <AudioHTMLClip>(clipEntity);
                    if (clip.clipID > 0)
                    {
                        if (!unlocked)
                        {
                            AudioHTMLNativeCalls.Unlock();
                            unlocked = AudioHTMLNativeCalls.IsUnlocked();
                            if (unlocked)
                            {
                                TinyEnvironment env = World.TinyEnvironment();
                                AudioConfig     ac  = env.GetConfigData <AudioConfig>();
                                ac.unlocked = unlocked;
                                env.SetConfigData(ac);
                            }
                        }

                        if (unlocked)
                        {
                            int sourceID = ++IDPool.sourceID;
                            AudioHTMLNativeCalls.Play(clip.clipID, sourceID, audioSource.volume, audioSource.loop);
                            AudioHTMLSource audioNativeSource = new AudioHTMLSource()
                            {
                                sourceID = sourceID
                            };
                            // Need a native source as well.
                            if (mgr.HasComponent <AudioHTMLSource>(e))
                            {
                                mgr.SetComponentData(e, audioNativeSource);
                            }
                            else
                            {
                                PostUpdateCommands.AddComponent(e, audioNativeSource);
                            }

                            return(true);
                        }
                    }
                }
            }
            return(false);
        }