void Start() { // Cache variables l = light; m = renderer.material; e = GetComponent<SoundEntity> (); }
public AudioSource Play(SoundEntity soundEntity, float volumeMultiplier, float pitchMultiplier, PlayMode playMode, Transform targetTransform, Vector3 targetPosition, Action <GameSound> callback = null) { _currentSound = soundEntity.soundType; _currentCallback = callback; var waitingTime = Play_Internal(soundEntity, volumeMultiplier, pitchMultiplier); switch (playMode) { case PlayMode.Simple: // Vanilla waiter _currentCoroutine = _coroutines.StartCoroutine( PlaybackWaiter(waitingTime)); break; case PlayMode.Positioned: // Positioned waiter _currentCoroutine = _coroutines.StartCoroutine( PlaybackWaiter_Positioned(waitingTime, targetPosition)); break; case PlayMode.Tracking: // Tracking waiter _currentCoroutine = _coroutines.StartCoroutine( PlaybackWaiter_Tracking(waitingTime, targetTransform)); break; default: throw new InvalidOperationException($"Cannot process unknown {nameof(PlayMode)} '{playMode}'."); } return(_audioSource); }
public void CleanUpWithParent(SoundEntity soundEntity) { if (!soundEntity.hasParent) { Logger.Error("sound entity has no parent"); return; } var parentKey = soundEntity.parent.Value; switch ((EEntityType)parentKey.EntityType) { case EEntityType.Player: var player = _contexts.GetEntityWithEntityKey(parentKey); if (null == player) { soundEntity.isFlagDestroy = true; } break; case EEntityType.Bullet: var bullet = _contexts.GetEntityWithEntityKey(parentKey); if (null == bullet) { soundEntity.isFlagDestroy = true; } break; } }
private void Play_Button_Click(object sender, EventArgs e) { if (this.Sound_Combo.SelectedItem != null) { SoundEntity m_Entity = this.Sound_Combo.SelectedItem as SoundEntity; SoundPlayer m_Player = new SoundPlayer(m_Entity.FilePath); m_Player.Play(); } }
public void AttachParent(SoundEntity soundEntity) { if (!soundEntity.hasParent) { Logger.Error("sound entity has no parent"); return; } if (!soundEntity.hasUnityObj) { Logger.Error("sound entity has no unity obj "); return; } var go = soundEntity.unityObj.UnityObject.AsGameObject; if (null == go) { Logger.Error("unity obj of sound entity is null "); return; } var parentKey = soundEntity.parent.Value; switch ((EEntityType)parentKey.EntityType) { case EEntityType.Player: var player = _contexts.player.GetEntityWithEntityKey(parentKey); if (player.hasCharacterContoller) { if (null != player && null != player.characterContoller.Value.gameObject) { go.transform.parent = player.characterContoller.Value.gameObject.transform; } else { Logger.Error("player's gameobject is null"); } } break; case EEntityType.Bullet: var bullet = _contexts.bullet.GetEntityWithEntityKey(parentKey); if (null != bullet && bullet.hasBulletGameObject) { if (null != bullet.bulletGameObject.UnityObject) { go.transform.parent = bullet.bulletGameObject.UnityObject.AsGameObject.transform; } else { Logger.Error("bullet's gameobject is null"); } } break; } go.transform.localPosition = Vector3.zero; }
public bool Play(int soundId, float offset) { if (soundId > (int)EVehicleSoundId.Invalid) { //mute other sounds MuteSoundExcept(soundId); // if it is the first time audio-play then create the specified sound entity. SoundEntity soundEntity = null; if (!_soundEntityCache.ContainsKey(soundId)) { soundEntity = CreateSoundEntity(soundId); _soundEntityCache[soundId] = soundEntity; } soundEntity = _soundEntityCache[soundId]; if (soundEntity == null) { return(true); } //play the speicified sound if (soundEntity.hasAudioSourceKey) { var soundKey = soundEntity.audioSourceKey.Value; if (_soundPlayer.IsPlaying(soundKey)) { _soundPlayer.Mute(soundKey, false); } else { var isLoopSound = _soundConfigManager.IsLoopSound(soundId); if (isLoopSound && offset > 0) { var clipLength = _soundPlayer.GetLength(soundKey); if (clipLength > 0) { offset %= clipLength; } } _soundPlayer.Play(soundKey, offset, isLoopSound); } return(true); } return(false); } //mute all sound if try play Invalid Sound MuteSoundExcept((int)EVehicleSoundId.Invalid); return(true); }
public SoundEntity Play(string path) { SoundEntity entity = Get(path); if (entity == null) { return(null); } entity.OnFinished += OnEffectEnded; return(entity); }
public void Beep(string id) { try { SoundEntity chosenOne = Array.Find(sounds, sounds => sounds.identifier == id); chosenOne.source.Play(); } catch (Exception ex) { Debug.Log("error" + ex.Message); } }
void Awake() { se = GetComponent <SoundEntity>(); AffichePanelControle.SetActive(false); AffichePanelMenuPrincipal.SetActive(true); InControlePanel = false; Cursor.visible = true; PlayerPrefs.SetString("SceneToLoad", null); }
private SoundEntity Get(string path) { if (_pools.ContainsKey(path) == false) { _pools.Add(path, new SimplePool <SoundEntity>(() => Instantiate(Resources.Load <GameObject>(path)).GetComponent <SoundEntity>())); } SoundEntity entity = _pools[path].Get(); entity.Path = path; return(entity); }
// Use this for initialization void Start() { se = GetComponent <SoundEntity>(); SonPicPrepareReplay = SonPicPrepare; SonPicSortieReplay = SonPicSortie; SonPicRangeReplay = SonPicRange; anim = gameObject.GetComponent <Animator> (); anim.SetBool("CanUp", false); anim.speed *= SpeedMultiplier; ActivationTime = Time.time + TimeRepos + TimeBegin; }
public void PlaySoundAtNode(SceneNode node, string soundID) { if (hasSound) { SoundEntity entity = null; string soundFile = findSoundFileByID(soundID); if (!string.IsNullOrEmpty(soundFile)) { entity = soundEngine.CreateSoundEntity(findSoundFileByID(soundID), node, "", false, false); entity.Play(); entities.Add(entity); } } }
void Awake() { nav = this.GetComponent <NavMeshAgent>(); anim = GetComponent <Animator>(); rb = GetComponent <Rigidbody> (); princesse = GameObject.FindGameObjectWithTag("Player"); princesseVie = princesse.GetComponent <PrincesseVie>(); princesseArme = princesse.GetComponent <PrincesseArme>(); pointsInteret = GameObject.FindObjectsOfType <IA_PointInteret>(); mobVie = GetComponent <IA_MobVie> (); se = GetComponent <SoundEntity> (); me = GameObject.FindGameObjectWithTag("MobManager").GetComponent <MobManager> (); perception = GetComponent <IA_Perception> (); etatCourant = etatInitial; }
/// <summary> /// Preps the AudioSource and plays the specified sound. /// </summary> private float Play_Internal(SoundEntity sound, float volumeMultiplier, float pitchMultiplier) { // Prepare audio source var pitch = Random.Range(sound.pitchLow, sound.pitchHigh) * pitchMultiplier; _audioSource.volume = Random.Range(sound.volumeLow, sound.volumeHigh) * volumeMultiplier; _audioSource.pitch = pitch; _audioSource.clip = sound.audioClip; // Calculate actual time length of sound playback var playTime = Mathf.Abs(sound.audioClip.length / pitch); // Abs() is to support negative pitch // Start actual playback _audioSource.Play(); return(playTime); }
void Update() { if (sources.Count == 0) return; if (entities.Count == 0) return; if (currentClosest == null) currentClosest = entities[0]; // Find the closest Vector3 playerPos = Player.Instance.transform.position; SoundEntity closest = currentClosest; float distSq = Vector3.SqrMagnitude (currentClosest.transform.position - playerPos); for (int i = 0; i < entities.Count; i++) { SoundEntity e = entities[i]; float d = Vector3.SqrMagnitude (e.transform.position - playerPos); if (d < distSq) { closest = e; distSq = d; } } currentClosest = closest; int mode = currentClosest.mode; if (mode < 0 || mode > sources.Count - 1) { mode = 0; } for (int i = 0; i < sources.Count; i++) { sources[i].volume = 0f; } if (distSq < outerRadius * outerRadius) { if (distSq <= innerRadius * innerRadius) { sources[mode].volume = maxVolume * currentClosest.strength; } else { float d = Vector3.Distance(closest.transform.position, playerPos); float v = 1f - (d - innerRadius) / (outerRadius - innerRadius); // 1 when close, 0 when far v = Mathf.Lerp(minVolume, maxVolume, v); sources[mode].volume = v * currentClosest.strength; } } else { sources[mode].volume = minVolume; } }
public void Play(string name, float volume, bool isLoop = false, bool isSTGSound = true) { #if SoundEnable int i; for (i = 0; i < _toPlayListCount; i++) { if (_toPlayList[i].soundName == name) { return; } } //Logger.Log("PlaySound \"" + name + "\" PoolCount = " + _pool.Count); SoundEntity entity = GetAtPool(); entity.soundName = name; entity.volume = Mathf.Clamp01(volume); entity.isLoop = isLoop; entity.isSTGSound = isSTGSound; _toPlayList.Add(entity); _toPlayListCount++; #endif }
private void Options_Mdi_Load(object sender, EventArgs e) { Properties.Settings.Default.Reload(); if (AutoStarter.IsAutoStartEnabled) { this.Startup_Check.Checked = true; } if (GuiManipulator.CanShowStatistics) { this.ShowStats_Check.Checked = true; } if (Properties.Settings.Default.AlertForLowAmountItems) { this.AlertForAmount_Check.Checked = true; } if (Properties.Settings.Default.AlertForUnpricedItems) { this.AlertForUnpriced_Check.Checked = true; } this.LowAmountColor_Preview_Label.BackColor = Properties.Settings.Default.LowAmountAlertColor; this.LowAmountTheresold_Num.Value = Properties.Settings.Default.LowAmountTheresold; this.groupBox1.Enabled = this.AlertForAmount_Check.Checked; this.Unpriced_Color_Preview_Label.BackColor = Properties.Settings.Default.UnpricedAlertColor; this.groupBox2.Enabled = this.AlertForUnpriced_Check.Checked; string m_SoundPath = Path.Combine(Application.StartupPath, "Sounds"); List <string> m_Files = Directory.EnumerateFiles(m_SoundPath, "*.wav", SearchOption.AllDirectories).ToList(); List <SoundEntity> m_Source = new List <SoundEntity>(); m_Files.All(delegate(string m_FilePath) { SoundEntity m_Entity = new SoundEntity(m_FilePath, Path.GetFileName(m_FilePath)); m_Source.Add(m_Entity); return(true); }); this.Sound_Combo.DataSource = m_Source; this.Sound_Combo.DisplayMember = "Name"; this.Sound_Combo.ValueMember = "FilePath"; this.Sound_Combo.Invalidate(); this.Sound_Check.Checked = Properties.Settings.Default.PlaySoundOnScanned; this.groupBox3.Enabled = this.Sound_Check.Checked; if (Properties.Settings.Default.SoundFileLocation.Length > 0) { this.Sound_Combo.SelectedValue = Properties.Settings.Default.SoundFileLocation; } using (MuhasebeEntities m_Context = new MuhasebeEntities()) { if (Program.User.Position != null && Program.User.PositionID == 1) // Is owner ? { this.ShowStats_Check.Visible = true; } else { this.ShowStats_Check.Visible = false; } } }
// Sound ParticuleWall // 0 - Pied de lit / bois private void Start() { soundGenerator = gameObject.GetComponent <SoundEntity>(); }
/// <summary> /// Function that handles tasks that trigger when a key is pressed. /// </summary> /// <param name="e">Data passed by the event handler that calls the function.</param> /// <returns></returns> public bool KeyPressed(MOIS.KeyEvent e) { switch (e.key) { case MOIS.KeyCode.KC_LEFT: case MOIS.KeyCode.KC_A: position--; if (position < -1) { position = -1; } break; case MOIS.KeyCode.KC_RIGHT: case MOIS.KeyCode.KC_D: position++; if (position > 1) { position = 1; } break; case MOIS.KeyCode.KC_SPACE: switch (position) { case -1: running = false; break; case 0: if (soundEntity != null) { if (soundEntity.IsPlaying()) { soundEntity.Stop(); } else { soundEntity.Play(); } break; } soundEntity = smgr.CreateSoundEntity("Assets/Sounds/DrumMono.ogg", mgr.GetSceneNode("Drum"), "Drum", false, false); soundEntity.SetReferenceDistance(.5f); soundEntity.SetMaxDistance(5); soundEntity.Play(); break; case 1: if (ambientSound != null) { if (ambientSound.IsPlaying()) { ambientSound.Stop(); } else { ambientSound.Play(); } break; } ambientSound = smgr.CreateAmbientSound("Assets/Sounds/Tune.ogg", "Tune", false, false); ambientSound.Play(); break; } break; case MOIS.KeyCode.KC_ESCAPE: running = false; break; } return(true); }
void Start() { se = GetComponent <SoundEntity>(); se.playOneShot(0); }
private void RestoreToPool(SoundEntity entity) { //Logger.Log("Restore \"" + entity.soundName + "\" to Pool ,PoolCount = " + (_pool.Count+1)); entity.Clear(); _pool.Push(entity); }
private void OnEffectEnded(SoundEntity entity) { entity.OnFinished -= OnEffectEnded; _pools[entity.Path].Release(entity); }
void Awake() { se = GetComponent <SoundEntity> (); }