Пример #1
0
        protected override bool PlaySource(Entity e)
        {
            var mgr = EntityManager;

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

                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)
                        {
                            // If there is an existing source, it should re-start.
                            // Do this with a Stop() and let it play below.
                            if (mgr.HasComponent <AudioHTMLSource>(e))
                            {
                                AudioHTMLSource ans = mgr.GetComponentData <AudioHTMLSource>(e);
                                AudioHTMLNativeCalls.Stop(ans.sourceID, true);
                            }

                            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);
        }
Пример #2
0
        protected override void OnStartRunning()
        {
            AudioHTMLNativeCalls.Unlock();
            unlocked = AudioHTMLNativeCalls.IsUnlocked();
            //Console.WriteLine("(re) checking un-locked: ");
            //Console.WriteLine(unlocked ? "true" : "false");

            AudioConfig ac = GetSingleton <AudioConfig>();

            ac.initialized = true;
            ac.unlocked    = unlocked;
            SetSingleton <AudioConfig>(ac);
        }