private void CalculateActiveZone() { int num = int.MinValue; AmbienceZone ambienceZone = null; if (forcedZone != null) { ambienceZone = forcedZone; } else { Vector3 position = Listener.instance.transform.position; if (zones == null) { zones = GetComponentsInChildren <AmbienceZone>(); } for (int i = 0; i < zones.Length; i++) { if (zones[i].GetComponent <Collider>().bounds.Contains(position) && zones[i].priority > num) { ambienceZone = zones[i]; num = zones[i].priority; } } } if (!(ambienceZone == null) && !(activeZone == ambienceZone)) { TransitionToZone(ambienceZone, ambienceZone.transitionDuration); } }
public void EnterZone(AmbienceZone trigger) { if (!activeZones.Contains(trigger)) { activeZones.Add(trigger); CalculateActiveZoneTrigger(); } }
public void LeaveZone(AmbienceZone trigger) { if (activeZones.Contains(trigger)) { activeZones.Remove(trigger); CalculateActiveZoneTrigger(); } }
private void DrawSlider(Rect rect, AmbienceZone zone, AmbienceSource source) { float level = zone.GetLevel(source); float num = AudioUI.DrawHorizontalSlider(rect, 0f, 1f, 0f, level, AudioSliderType.Volume); if (level == num) { return; } if (zone.sources != null && zone.sources.Length > 0) { for (int i = 0; i < zone.sources.Length; i++) { if (zone.sources[i] == source) { if (num == 0f) { zone.sources[i] = zone.sources[zone.sources.Length - 1]; zone.volumes[i] = zone.volumes[zone.sources.Length - 1]; Array.Resize(ref zone.volumes, zone.sources.Length - 1); Array.Resize(ref zone.sources, zone.sources.Length - 1); } else { zone.volumes[i] = num; } if (activeAmbience.activeZone != null) { activeAmbience.TransitionToZone(activeAmbience.activeZone, 0.1f); } return; } } } if (zone.sources != null) { Array.Resize(ref zone.volumes, zone.sources.Length + 1); Array.Resize(ref zone.sources, zone.sources.Length + 1); } else { zone.volumes = new float[1]; zone.sources = new AmbienceSource[1]; } zone.sources[zone.sources.Length - 1] = source; zone.volumes[zone.sources.Length - 1] = num; if (activeAmbience.activeZone != null) { activeAmbience.TransitionToZone(activeAmbience.activeZone, 0.1f); } }
private void DrawMixer(AmbienceZone zone, Func <AmbienceZone, float> get, Action <AmbienceZone, float> set) { Rect rect = GUILayoutUtility.GetRect(75f, 20f, GUILayout.ExpandWidth(expand: false)); float num = get(zone); float num2 = AudioUI.DrawHorizontalSlider(rect, -24f, 24f, 0f, get(zone), AudioSliderType.Level); if (num != num2) { set(zone, num2); if (activeAmbience.activeZone != null) { activeAmbience.TransitionToZone(activeAmbience.activeZone, 0.1f); } } }
public void TransitionToZone(AmbienceZone zone, float duration) { activeZone = zone; for (int i = 0; i < sources.Length; i++) { float volume = 0f; for (int j = 0; j < zone.sources.Length; j++) { if (zone.sources[j] == sources[i]) { volume = zone.volumes[j]; } } sources[i].FadeVolume(volume, duration); } GameAudio.instance.SetAmbienceZoneMix(zone, duration); }
private void CalculateActiveZoneTrigger() { if (activeZones.Count == 0) { return; } AmbienceZone ambienceZone = activeZones[0]; for (int i = 1; i < activeZones.Count; i++) { if (activeZones[i].priority < ambienceZone.priority) { ambienceZone = activeZones[i]; } } if (!(activeZone == ambienceZone)) { TransitionToZone(ambienceZone, ambienceZone.transitionDuration); } }
public void Save() { AmbienceSource[] componentsInChildren = GetComponentsInChildren <AmbienceSource>(); AmbienceZone[] componentsInChildren2 = GetComponentsInChildren <AmbienceZone>(); AmbienceState ambienceState = new AmbienceState(); ambienceState.zones = new AmbienceZoneState[componentsInChildren2.Length]; AmbienceState ambienceState2 = ambienceState; for (int i = 0; i < componentsInChildren2.Length; i++) { AmbienceZone ambienceZone = componentsInChildren2[i]; ambienceState2.zones[i] = new AmbienceZoneState { name = ambienceZone.name, sources = new AmbienceZoneSourceState[ambienceZone.volumes.Length], mainVerbLevel = ambienceZone.mainVerbLevel, musicLevel = ambienceZone.musicLevel, ambienceLevel = ambienceZone.ambienceLevel, effectsLevel = ambienceZone.effectsLevel, physicsLevel = ambienceZone.physicsLevel, characterLevel = ambienceZone.characterLevel, ambienceFxLevel = ambienceZone.ambienceFxLevel }; for (int j = 0; j < ambienceZone.volumes.Length; j++) { ambienceState2.zones[i].sources[j] = new AmbienceZoneSourceState { source = ambienceZone.sources[j].name, volume = ambienceZone.volumes[j] }; } } string contents = JsonUtility.ToJson(ambienceState2, prettyPrint: true); string path = GetPath(); File.WriteAllText(path, contents); }
public void ForceZone(AmbienceZone zone) { forcedZone = zone; CalculateActiveZone(); }