/// <summary> /// Initialize the subsystem /// </summary> /// <param name="api">Reference to subsystem wrapper</param> /// <returns>True if successful</returns> public bool Initialize(RBAPI api) { mRetroBlitAPI = api; var audioSourceObj = GameObject.Find("RetroBlitAudio"); if (audioSourceObj == null) { Debug.Log("Can't find RetroBlitAudio! Does your RetroBlit object no longer match the RetroBlit prefab?"); return(false); } mAudioListenerObj = GameObject.Find("RetroBlitAudioListener"); if (mAudioListenerObj == null) { Debug.Log("Can't find RetroBlitAudioListener! Does your RetroBlit object no longer match the RetroBlit prefab?"); return(false); } InitializeChannels(); SoundListenerPosSet(Vector2i.zero); previousMusicClip = null; currentMusicClip = null; mPreviousMusicClipVolumeFade = 0; return(true); }
private void A2DPlayerGUI() { Dictionary <int, AudioAsset> bgMusicDic = AudioPlayManager.a2DPlayer.bgMusicDic; EditorGUILayout.Slider("Music Volume : ", AudioPlayManager.a2DPlayer.MusicVolume, 0, 1); EditorGUILayout.Slider("SFX Volume : ", AudioPlayManager.a2DPlayer.SFXVolume, 0, 1); EditorDrawGUIUtil.DrawFoldout(bgMusicDic, "Music Channel Count:" + bgMusicDic.Count, () => { EditorDrawGUIUtil.DrawScrollView(bgMusicDic, () => { foreach (var item in bgMusicDic) { GUILayout.Label("Channel : " + item.Key); ShowAudioAssetGUI(item.Value, false); } }, "box"); }); List <AudioAsset> sfxList = AudioPlayManager.a2DPlayer.sfxList; EditorDrawGUIUtil.DrawFoldout(sfxList, "SFX Count:" + sfxList.Count, () => { EditorDrawGUIUtil.DrawScrollView(sfxList, () => { for (int i = 0; i < sfxList.Count; i++) { AudioAsset au = sfxList[i]; GUILayout.Label("Item : " + i); ShowAudioAssetGUI(au, false); } }, "box"); }); }
private void ClearMoreAudioAsset(GameObject owner) { if (sfxDic.ContainsKey(owner)) { List <AudioAsset> sfxList = sfxDic[owner]; for (int i = 0; i < sfxList.Count; i++) { sfxList[i].CheckState(); if (sfxList[i].PlayState == AudioPlayState.Stop) { tempClearList.Add(sfxList[i]); } } for (int i = 0; i < tempClearList.Count; i++) { AudioAsset asset = tempClearList[i]; Object.Destroy(asset.audioSource); DestroyAudioAssetByPool(asset); sfxList.Remove(asset); } tempClearList.Clear(); } }
private int GetNextShuffled(AudioAsset sound, int index, int length) { if (sound.ShuffleQueue == null) { sound.ShuffleQueue = new Queue <int>(length); } if (sound.ShuffleQueue.Count == 0) { // TODO: infinyte loop if playlist empty? while (index == sound.LastIndex) { index = Random.Range(0, length); } sound.ShuffleQueue.Enqueue(index); // reshuffle while (sound.ShuffleQueue.Count < length) { int num = Random.Range(0, length); if (sound.ShuffleQueue.Contains(num) == false) { sound.ShuffleQueue.Enqueue(num); } } } return(index); }
private int GetNextWeightedRandom(AudioAsset sound) { //TODO: UX issue here that is maybe unintuitive: total values don't always add to 100%, //they can be more or less! //We account for that here by getting a random number using the sum of all weights, //then using each weight value as a threshold for "landing on" the associated clip float sum = 0f; for (int i = 0; i < sound.Weights.Count; i++) { sum += sound.Weights[i]; } float random = Random.Range(0f, sum); float nextThreshold = 0f; int index = 0; for (int i = 0; i < sound.Weights.Count; i++) { nextThreshold += sound.Weights[i]; if (random < nextThreshold) { index = i; break; } } return(index); }
private static void CopyToByteBuffer(AudioAsset src, byte[] dst) { for (var i = 0; i < src.SoundData.Length; i++) { AudioConverter.SetSampleAsFloat(i, src.SoundData[i], dst, src.Format); } }
public void PlaySFX(string name, float volumeScale = 1f, float delay = 0f, float pitch = 1, string flag = "") { AudioAsset au = GetEmptyAudioAssetFromSFXList(); au.flag = flag; PlayClip(au, name, false, volumeScale, delay, pitch); }
public virtual void Play(AudioClip audioClip, out ScriptedAudioSource audioSource) { AudioAsset asset = ScriptableObject.CreateInstance <AudioAsset>(); asset.Clip = audioClip; Play(asset, out audioSource); }
public void PlaySFX(GameObject owner, string name, float volumeScale = 1f, float delay = 0f) { AudioAsset au = GetEmptyAudioAssetFromSFXList(owner); PlayClip(au, name, false, volumeScale, delay); ClearMoreAudioAsset(owner); }
public void ShouldShowAssetsOfParentFolderWhenUpArrowCommandIsExecuted() { VideoAsset videoAsset = new VideoAsset { Title = "VideoAsset" }; AudioAsset audioAsset = new AudioAsset { Title = "AudioAsset" }; FolderAsset folderAsset = new FolderAsset { Title = "ParentFolder" }; folderAsset.AddAssets(new ObservableCollection <Asset> { videoAsset, audioAsset }); var presentationModel = this.CreatePresentationModel(); this.assetsAvailableEvent.SubscribeArgumentAction.Invoke(new Infrastructure.DataEventArgs <List <Asset> >(new List <Asset> { folderAsset })); presentationModel.OnAssetSelected(folderAsset); Assert.AreEqual(2, presentationModel.Assets.Count); presentationModel.UpArrowCommand.Execute(null); Assert.AreEqual(1, presentationModel.Assets.Count); }
public IAsset Load(string name, IRawAsset data) { if (data.IsCompiled) { return(new AudioAsset(name, null, data.GetProperty <PlatformData>("PlatformData"), false)); } PlatformData platformData = null; if (data.GetProperty <PlatformData>("PlatformData") != null) { platformData = new PlatformData { Platform = data.GetProperty <PlatformData>("PlatformData").Platform, Data = data.GetProperty <PlatformData>("PlatformData").Data }; } var audio = new AudioAsset( name, ByteReader.ReadAsByteArray(data.GetProperty <object>("RawData")), platformData, data.GetProperty <bool>("SourcedFromRaw")); return(audio); }
/// <summary> /// The play. /// </summary> /// <param name="asset"> /// The asset. /// </param> /// <returns> /// The <see cref="IAudioHandle"/>. /// </returns> public IAudioHandle Play(AudioAsset asset) { var handle = this.GetHandle(asset); handle.Play(); return(handle); }
/// <summary> /// The loop. /// </summary> /// <param name="asset"> /// The asset. /// </param> /// <returns> /// The <see cref="IAudioHandle"/>. /// </returns> public IAudioHandle Loop(AudioAsset asset) { var handle = this.GetHandle(asset); handle.Loop(); return(handle); }
public void SetTarget(AudioAsset audioAsset) { if (audioAsset == null) { ResetTarget(); return; } _RawTarget = audioAsset; _SerializedTarget = new SerializedObject(_RawTarget); _ClipList = _SerializedTarget.FindProperty("_AudioClips"); _PitchMin = _SerializedTarget.FindProperty("_PitchMin"); _PitchMax = _SerializedTarget.FindProperty("_PitchMax"); _Looped = _SerializedTarget.FindProperty("_Looped"); _MaxDistance = _SerializedTarget.FindProperty("_MaxDistance"); _MinDistance = _SerializedTarget.FindProperty("_MinDistance"); _Pan = _SerializedTarget.FindProperty("_Pan"); _AudioMixerGroup = _SerializedTarget.FindProperty("_AudioMixerGroup"); _Volume = _SerializedTarget.FindProperty("_Volume"); _AvoidRepetition = _SerializedTarget.FindProperty("_AvoidRepetition"); _Doppler = _SerializedTarget.FindProperty("_Doppler"); _SpatialBlend = _SerializedTarget.FindProperty("_SpatialBlend"); _RandomStartPosition = _SerializedTarget.FindProperty("_RandomStartPosition"); _SelectableList.ResetSelection(); }
public IAsset LoadAsset(StagedAsset stagedAsset) { IAsset asset = null; switch (stagedAsset.Type) { case (AssetType.AudioAsset): asset = new AudioAsset(stagedAsset.Id, new AudioFileReader(stagedAsset.FilePath)); break; case (AssetType.SpriteFontAsset): { SpriteFont sf; lock (stagedAsset.Content) sf = stagedAsset.Content.Load <SpriteFont>(stagedAsset.FilePath); asset = new SpriteFontAsset(stagedAsset.Id, sf); } break; case (AssetType.Texture2DAsset): { Texture2D td; lock (stagedAsset.Content) td = stagedAsset.Content.Load <Texture2D>(stagedAsset.FilePath); asset = new Texture2DAsset(stagedAsset.Id, td); } break; } return(asset); }
public void ShouldShowAllAssets() { var imageAsset = new ImageAsset { Title = "Image" }; var videoAsset = new VideoAsset { Title = "Video" }; var audioAsset = new AudioAsset { Title = "Audio" }; var assets = new List <Asset> { imageAsset, videoAsset, audioAsset }; var presentationModel = this.CreatePresentationModel(); this.assetsAvailableEvent.SubscribeArgumentAction.Invoke(new Infrastructure.DataEventArgs <List <Asset> >(assets)); presentationModel.ShowImages = false; presentationModel.ShowVideos = false; presentationModel.ShowAudio = false; Assert.AreEqual(0, presentationModel.Assets.Count); presentationModel.ShowImages = true; presentationModel.ShowVideos = true; presentationModel.ShowAudio = true; Assert.AreEqual(3, presentationModel.Assets.Count); }
protected void PauseMusicControl(AudioAsset au, bool isPause, float fadeTime = 0.5f) { if (isPause) { //Debug.Log("PauseMusicControl Pause : "+ au.PlayState); if (au.PlayState == AudioPlayState.Playing) { au.SetPlayState(AudioPlayState.Pause); //Debug.Log("PauseMusicControl Pause"); AddFade(au, VolumeFadeType.FadeOut, fadeTime, 0, (value) => { //Debug.LogWarning("PauseMusicControl Pause fade CallBack"); value.Pause(); }, null); } } else { //Debug.Log("PauseMusicControl play : "+ au.PlayState); if (au.PlayState == AudioPlayState.Pause) { au.Play(); AddFade(au, VolumeFadeType.FadeIn, fadeTime, 0, null, null); } } }
public void Initialize(AudioAsset asset) { AudioName.Text = asset.AssetName; DefaultLoudness.Text = asset.PresentInDefaultLoudness ? asset.DefaultLoudness.ToString() : "N/A (Defaults to 1)"; FileName.Text = asset.EditorPath.IsPathValid() ? Path.GetFileName(asset.EditorPath) : asset.EditorPath; FileLoudness.Text = asset.Loudness.ToString(); bool startPaused = !Autoplay.IsChecked ?? true; SongSet(asset.EditorPath, (float)Pitch.Value, startPaused); if (Song == null) { return; } ToggleImage.Source = ((Image)Resources[startPaused ? "PlayImage" : "PauseImage"]).Source; Seek.Maximum = Song.PlayLength; Seek.Value = 0; SeekText.Text = $"{EditorUtils.ToTimeString((int)Song.PlayPosition)} / {EditorUtils.ToTimeString((int)Song.PlayLength)}"; PitchText.Text = $"x {Song.PlaybackSpeed:0.00}"; }
protected void PlayMusicControl(AudioAsset au, string audioName, bool isLoop = true, float volumeScale = 1, float delay = 0f, float fadeTime = 0.5f, string flag = "") { au.flag = flag; if (au.assetName == audioName) { if (au.PlayState != AudioPlayState.Playing) { AddFade(au, VolumeFadeType.FadeIn, fadeTime, delay, null, null); au.Play(); } } else { if (au.PlayState == AudioPlayState.Playing) { AddFade(au, VolumeFadeType.FadeOut2In, fadeTime, delay, null, (value) => { PlayClip(value, audioName, isLoop, volumeScale, delay); }); } else { PlayClip(au, audioName, isLoop, volumeScale, delay); AddFade(au, VolumeFadeType.FadeIn, fadeTime, delay, null, null); } } }
public AudioAsset CreateAudioAssetByPool(GameObject gameObject, bool is3D, AudioSourceType sourceType) { AudioAsset au = null; if (audioAssetsPool.Count > 0) { au = audioAssetsPool.Dequeue(); au.ResetData(); } else { au = new AudioAsset(); au.audioSource = gameObject.AddComponent <AudioSource>(); } au.audioSource.spatialBlend = is3D ? 1 : 0; au.sourceType = sourceType; if (sourceType == AudioSourceType.Music) { au.TotleVolume = musicVolume; } else { au.TotleVolume = sfxVolume; } return(au); }
/// <summary> /// Constructor /// </summary> /// <param name="source">Source entity</param> /// <param name="target">Target entity</param> /// <param name="targetPos">Target position</param> /// <param name="projectileSprite">Projectile sprite facing top</param> /// <param name="projecticleSprite45">Projectile sprite facing top-right</param> /// <param name="projecticleColor">Projectile color</param> /// <param name="launchSound">Launching sound</param> /// <param name="landSound">Landing sound</param> public EffectThrow(EntityID source, EntityID target, Vector2i targetPos, PackedSpriteID projectileSprite, PackedSpriteID projecticleSprite45, Color32 projecticleColor, AudioAsset launchSound, AudioAsset landSound) : base(EffectType.Throw) { var game = (RetroDungeoneerGame)RB.Game; mSourcePos = new Vector2i(source.e.pos.x * game.assets.spriteSheet.grid.cellSize.width, source.e.pos.y * game.assets.spriteSheet.grid.cellSize.height); mTargetEntity = target; mProjecticleColor = projecticleColor; mFramesTotal = 10; mFramesRemaining = mFramesTotal; mRotate = true; mProjecticleSprite = projectileSprite; mProjecticleSprite45 = projecticleSprite45; mLaunchSound = launchSound; mLandSound = landSound; mTargetPos = targetPos; if (mLaunchSound != null) { RB.SoundPlay(mLaunchSound); } }
public IEnumerator EaseToChangeVolume(AudioAsset au, string name, bool isLoop, float volumeScale, float delay, float fadeTime) { AudioClip ac = GetAudioClip(name); float oldVolume = au.Volume; float target = au.Volume; if (au.audioSource && au.IsPlay) { while (target > 0f) { float speed = oldVolume / fadeTime; target = target - speed * Time.fixedDeltaTime; au.Volume = target; yield return(new WaitForFixedUpdate()); } au.Stop(); } au.assetName = name; au.audioSource.clip = ac; au.audioSource.loop = isLoop; au.Play(delay); target = 0; yield return(new WaitForSeconds(delay)); while (target < oldVolume) { float speed = oldVolume / fadeTime * 1.2f; target = target + speed * Time.fixedDeltaTime; au.Volume = target; yield return(new WaitForFixedUpdate()); } au.VolumeScale = volumeScale; }
private AudioAsset GetEmptyAudioAssetFromSFXList(GameObject owner) { AudioAsset au = null; List <AudioAsset> sfxList = null; if (sfxDic.ContainsKey(owner)) { sfxList = sfxDic[owner]; if (sfxList.Count > 0) { for (int i = 0; i < sfxList.Count; i++) { if (sfxList[i].PlayState == AudioPlayState.Stop) { au = sfxList[i]; } } } } else { sfxList = new List <AudioAsset>(); sfxDic.Add(owner, sfxList); } if (au == null) { au = CreateAudioAsset(owner, true, false); sfxList.Add(au); } return(au); }
private void ShowAudioAssetGUI(AudioAsset au, bool isShowAudioSource) { Color color = Color.white; switch (au.PlayState) { case AudioPlayState.Playing: color = Color.green; break; case AudioPlayState.Pause: color = Color.yellow; break; case AudioPlayState.Stop: break; } GUI.color = color; GUILayout.BeginVertical("box"); GUILayout.Label("Asset Name : " + au.assetName); GUILayout.Label("Play State : " + au.PlayState); GUILayout.Label("flag : " + au.flag); EditorGUILayout.Slider("VolumeScale : ", au.VolumeScale, 0, 1); //EditorGUILayout.Slider("Volume : ", au.Volume, 0, au.GetMaxRealVolume()); if (isShowAudioSource) { EditorGUILayout.ObjectField("AudioSource : ", au.audioSource, typeof(AudioSource), true); } GUILayout.EndVertical(); GUI.color = Color.white; }
public AudioAssetControl(AudioAsset asset) { InitializeComponent(); Handler = new AudioAssetControlHandler(asset, this); Data.DataContext = asset; }
public void PauseMusic(int channel, bool isPause, float fadeTime = 0.5f) { if (bgMusicDic.ContainsKey(channel)) { AudioAsset au = bgMusicDic[channel]; PauseMusicControl(au, isPause, fadeTime); } }
/// <summary> /// Returns value depending if it contains the audioasset or not /// </summary> /// <returns><c>true</c>, if audio channel contains audioasset, <c>false</c> otherwise.</returns> /// <param name="audioAsset">Audio asset.</param> public bool ContainsAudioAsset(AudioAsset audioAsset) { if (_audioAsset == audioAsset) { return(true); } return(false); }
private AudioAsset FindAudioAsset(string id) { AudioAsset asset = m_audioAssets .Where(x => x.m_ID.Equals(id)) .FirstOrDefault(); return(asset); }
/// <summary> /// Enter the scene /// </summary> /// <param name="parameters">Scene parameters</param> public override void Enter(object parameters) { mGameReady = false; var enterParams = (EnterParameters)parameters; mResultSet = new ResultSet(); mConsole = new Console(new Vector2i((int)(RB.DisplaySize.width * 0.66f), RB.DisplaySize.height / 3)); if (enterParams.testMap) { InitializeNewGame.SetupTestGameVariables(ref mPlayer, ref mGameMap); mGameState = GameState.PLAYER_TURN; mGameReady = true; mSaveOnExit = true; } else if (enterParams.savedFilename == null) { InitializeNewGame.SetupGameVariables(ref mPlayer, ref mGameMap); mGameState = GameState.PLAYER_TURN; mGameReady = true; mSaveOnExit = true; } else { var ret = DataLoaders.LoadGame(enterParams.savedFilename, ref mPlayer, ref mGameMap, ref mGameState, mConsole); if (ret == false) { return; } else { mGameReady = true; mSaveOnExit = true; } } mFOVRecompute = true; mFloodMap = new FloodMap(mGameMap.size); mCamera.SetPos(mPlayer); ChangeState(GameState.PLAYER_TURN); mConsole.Log(C.FSTR.Set("Welcome! Press H for help.")); RB.MusicPlay(mGameMap.music); mCurrentMusic = mGameMap.music; RB.MusicVolumeSet(0.75f); // If some key is down when entering scene then lock input until all keys are up. This prevents // the player accidentally moving if (RB.AnyKeyDown()) { mInputLocked = true; } }
public void UnloadClip(AudioAsset asset) { if (asset.audioSource.clip != null) { string name = asset.assetName; asset.audioSource.clip = null; ResourceManager.DestoryAssetsCounter(name); } }
public AudioChannel PlayAt(AudioAsset audioAsset, Vector3 point, bool loop = false) { AudioChannel channel = Play(audioAsset, loop); if(channel != null) { channel.transform.position = point; } return channel; }
public AudioChannel Play(AudioAsset audioAsset, bool loop = false) { if(audioAsset == null) { return null; } AudioChannel channel = GetAvailableChannel(); if(channel != null) { channel.Play(audioAsset, loop); return channel; } Debug.LogWarning("[AudioManager] No available audio channels for audio asset: " + audioAsset); return null; }
public Player( IPlatforming platforming, IAssetManager assetManager, I2DRenderUtilities renderUtilities, IAudioUtilities audioUtilities) { this.m_Platforming = platforming; this.m_AssetManager = assetManager; this.m_RenderUtilities = renderUtilities; this.m_AudioUtilities = audioUtilities; this.m_Texture = this.m_AssetManager.Get<TextureAsset>("texture.Player"); this.m_JumpSound = this.m_AssetManager.Get<AudioAsset>("audio.Jump"); this.m_JumpHandle = this.m_AudioUtilities.Play(this.m_JumpSound); this.Width = 32; this.Height = 32; }
public void Play(AudioAsset audioAsset, bool loop = false) { if(audioAsset.AudioClip == null) { Debug.LogError("[AudioChannel] " + audioAsset + " has no AudioClip.", audioAsset); return; } AudioSource.clip = audioAsset.AudioClip; AudioSource.outputAudioMixerGroup = audioAsset.AudioMixerGroup; Volume = audioAsset.Volume; Pitch = audioAsset.Pitch; PanStereo = audioAsset.StereoPan; SpatialBlend = audioAsset.SpatialBlend; ReverbZoneMix = audioAsset.ReverbZoneMix; Loop = loop; AudioAsset = audioAsset; AudioSource.Play(); }
/// <summary> /// The handle. /// </summary> /// <param name="assetManager"> /// The asset manager. /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="data"> /// The data. /// </param> /// <returns> /// The <see cref="IAsset"/>. /// </returns> public IAsset Handle(IAssetManager assetManager, string name, IRawAsset data) { if (data.IsCompiled) { return new AudioAsset(name, null, data.GetProperty<PlatformData>("PlatformData"), false); } PlatformData platformData = null; if (data.GetProperty<PlatformData>("PlatformData") != null) { platformData = new PlatformData { Platform = data.GetProperty<PlatformData>("PlatformData").Platform, Data = data.GetProperty<PlatformData>("PlatformData").Data }; } var audio = new AudioAsset( name, ByteReader.ReadAsByteArray(data.GetProperty<object>("RawData")), platformData, data.GetProperty<bool>("SourcedFromRaw")); return audio; }
public void PlayAudio(AudioAsset audio) { audioManager.Play(audio); }
public DefaultAudioHandle(AudioAsset asset) { _instance = asset.Audio.CreateInstance(); }
public IAudioHandle GetHandle(AudioAsset asset) { return new DefaultAudioHandle(asset); }
public IAudioHandle Loop(AudioAsset asset) { var handle = GetHandle(asset); handle.Loop(); return handle; }
///////////// // ASSETS /// ///////////// void AddAssetsFromSelection() { int previousAssetCount = currentConfiguration.assets.Count; Object[] audioSelection = Selection.GetFiltered(typeof(AudioClip), SelectionMode.Assets); Object[] textureSelection = Selection.GetFiltered(typeof(Texture2D), SelectionMode.Assets); for(int i=0; i<audioSelection.Length; i++) { AudioClip clip = audioSelection[i] as AudioClip; string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(clip)); //If the asset doesn't already exist on the assets list, add it if(!currentConfiguration.assets.Exists(x => x.guid == guid)) { AudioAsset audioAsset = new AudioAsset(); audioAsset.ReadFromAsset(clip); currentConfiguration.assets.Add(audioAsset); } else { Debug.Log("Asset " + clip.name + " already exists in the " + currentConfiguration.name + " configuration at path: " + AssetDatabase.GUIDToAssetPath(guid)); } } for(int i=0; i<textureSelection.Length; i++) { Texture2D texture = textureSelection[i] as Texture2D; string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(texture)); //If the asset doesn't already exist on the assets list, add it if(!currentConfiguration.assets.Exists(x => x.guid == guid)) { TextureAsset textureAsset = new TextureAsset(); textureAsset.ReadFromAsset(texture); currentConfiguration.assets.Add(textureAsset); } else { Debug.Log("Asset " + texture.name + " already exists in the " + currentConfiguration.name + " configuration at path: " + AssetDatabase.GUIDToAssetPath(guid)); } } //If assets got added, select the first asset that was added if(currentConfiguration.assets.Count > previousAssetCount) { WriteToFile(); AssetIndex = previousAssetCount; } else { Debug.Log("No new audio or texture assets were added to the " + currentConfiguration.name + " configuration."); } }
public IAudioHandle Play(AudioAsset asset) { var handle = GetHandle(asset); handle.Play(); return handle; }