protected override bool IsPlaying(Entity e) { if (EntityManager.HasComponent <AudioNativeSource>(e)) { AudioNativeSource audioNativeSource = EntityManager.GetComponentData <AudioNativeSource>(e); if (audioNativeSource.sourceID > 0) { return(AudioNativeCalls.IsPlaying(audioNativeSource.sourceID)); } } return(false); }
protected static int IsPlaying(EntityManager mgr, Entity e) { if (mgr.HasComponent <AudioSourceID>(e)) { AudioSourceID audioSourceID = mgr.GetComponentData <AudioSourceID>(e); if (audioSourceID.sourceID > 0) { return(AudioNativeCalls.IsPlaying(audioSourceID.sourceID)); } } return(0); }
protected override bool PlaySource(Entity e) { var mgr = EntityManager; if (mgr.HasComponent <AudioSource>(e)) { AudioSource audioSource = mgr.GetComponentData <AudioSource>(e); if (mgr.HasComponent <AudioNativeSource>(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. AudioNativeSource ans = mgr.GetComponentData <AudioNativeSource>(e); if (AudioNativeCalls.IsPlaying(ans.sourceID)) { return(true); } } Entity clipEntity = audioSource.clip; if (mgr.HasComponent <AudioNativeClip>(clipEntity)) { AudioNativeClip clip = mgr.GetComponentData <AudioNativeClip>(clipEntity); if (clip.clipID > 0) { uint sourceID = AudioNativeCalls.Play(clip.clipID, audioSource.volume, audioSource.loop); AudioNativeSource audioNativeSource = new AudioNativeSource() { sourceID = sourceID }; if (mgr.HasComponent <AudioNativeSource>(e)) { mgr.SetComponentData(e, audioNativeSource); } else { PostUpdateCommands.AddComponent(e, audioNativeSource); } return(true); } } } return(false); }