protected void OnSceneGUI() { var t = ((AudioEmitter)target).transform; AudioZone z = null; for (; t != null; t = t.transform.parent) { if ((z = t.GetComponent <AudioZone>()) != null) { break; } } if (z != null) { var v = z.transform.position; AudioZoneEditor.DrawZoneLabelStatic(z, v); // XXX this is drawn multiple times because zone var q = z.transform.parent; if (q != null) { for (int i = 0, n = q.childCount; i < n; ++i) { var u = q.GetChild(i).GetComponents <AudioZone>(); for (int j = 0, m = u.Length; j < m; ++j) { if (u[j] && u[j] != z) { AudioZoneEditor.DrawZoneLabelStatic( u[j], u[j].transform.position); } } } } } }
public override void Update(GameTime gameTime) { if (m_zones != null) { AudioZone sourceZone = new AudioZone(-1); float volume = 0; // Find out if we need to transition to a different audio zone foreach (AudioZone zone in m_zones) { if (zone.ContainsPlayer(World.MainPlayer)) { if (zone is EnemyAudioZone) { EnemyAudioZone enemyZone = zone as EnemyAudioZone; if (enemyZone != null) { float distance = enemyZone.DistanceFromPlayer(World.MainPlayer); float currentVolume = (float)(enemyZone.Radius - distance) / (float)enemyZone.Radius; if (currentVolume > volume) { volume = currentVolume; sourceZone = zone; } } } else if (!(sourceZone is EnemyAudioZone)) { sourceZone = zone; } else { sourceZone = DefaultZone; } } } // If we do, transition to the next audio zone if (sourceZone.SongIndex != -1) { //if (sourceZone != CurrentZone) // FXCollection.Songs[sourceZone.SongIndex].Play(); } //else if (CurrentZone != null && CurrentZone.SongIndex != -1) // FXCollection.Songs[CurrentZone.SongIndex].Stop(); if (CurrentZone != sourceZone) { CurrentZone = sourceZone; } //if (CurrentZone != null && CurrentZone.SongIndex != -1 && FXCollection.Songs[CurrentZone.SongIndex].Volume != volume) // FXCollection.Songs[CurrentZone.SongIndex].Volume = volume; } base.Update(gameTime); }
private AudioZone ToggleMute(IClient client, bool?mute) { Items.AudioZone audioZone = client.GetAudioZone(_id); bool newMute = mute ?? !audioZone.Mute; audioZone.Mute = newMute; return(AudioZone.Create(audioZone).WithIsMuted(newMute)); }
private AudioZone Toggle(IClient client, bool?state) { Items.AudioZone audioZone = client.GetAudioZone(_id); bool newState = state ?? !audioZone.State; audioZone.State = newState; return(AudioZone.Create(audioZone).WithState(newState)); }
public AudioZone SetBass([Service] IClient client, int bass) { if (bass < -12 || bass > 12) { throw new ArgumentOutOfRangeException(nameof(bass), "Value must be in the range [-12, 12]"); } Items.AudioZone audioZone = client.GetAudioZone(_id); audioZone.Bass = bass; return(AudioZone.Create(audioZone).WithBass(bass)); }
public AudioZone SetTreble([Service] IClient client, int treble) { if (treble < -12 || treble > 12) { throw new ArgumentOutOfRangeException(nameof(treble), "Value must be in the range [-12, 12]"); } Items.AudioZone audioZone = client.GetAudioZone(_id); audioZone.Treble = treble; return(AudioZone.Create(audioZone).WithTreble(treble)); }
public AudioZone SetVolume([Service] IClient client, int volume) { if (volume < -80 || volume > 0) { throw new ArgumentOutOfRangeException(nameof(volume), "Value must be in the range [-80, 0]"); } Items.AudioZone audioZone = client.GetAudioZone(_id); audioZone.Volume = volume; return(AudioZone.Create(audioZone).WithVolume(volume)); }
public AudioZone ChangeSource([Service] IClient client, int audioSourceId) { if (audioSourceId < 0 || audioSourceId >= client.AudioSourceCount) { throw new ArgumentOutOfRangeException(nameof(audioSourceId), $"Value must be in the range [0, {client.AudioSourceCount}["); } Items.AudioZone audioZone = client.GetAudioZone(_id); audioZone.Source = (byte)audioSourceId; return(AudioZone.Create(audioZone).WithAudioSourceId(audioSourceId)); }
public override void Update(GameTime gameTime) { if (m_zones != null) { AudioZone sourceZone = new AudioZone(-1); float volume = 0; // Find out if we need to transition to a different audio zone foreach (AudioZone zone in m_zones) { if (zone.ContainsPlayer(World.MainPlayer)) { if (zone is EnemyAudioZone) { EnemyAudioZone enemyZone = zone as EnemyAudioZone; if (enemyZone != null) { float distance = enemyZone.DistanceFromPlayer(World.MainPlayer); float currentVolume = (float)(enemyZone.Radius - distance) / (float)enemyZone.Radius; if (currentVolume > volume) { volume = currentVolume; sourceZone = zone; } } } else if (!(sourceZone is EnemyAudioZone)) sourceZone = zone; else sourceZone = DefaultZone; } } // If we do, transition to the next audio zone if (sourceZone.SongIndex != -1) { //if (sourceZone != CurrentZone) // FXCollection.Songs[sourceZone.SongIndex].Play(); } //else if (CurrentZone != null && CurrentZone.SongIndex != -1) // FXCollection.Songs[CurrentZone.SongIndex].Stop(); if (CurrentZone != sourceZone) CurrentZone = sourceZone; //if (CurrentZone != null && CurrentZone.SongIndex != -1 && FXCollection.Songs[CurrentZone.SongIndex].Volume != volume) // FXCollection.Songs[CurrentZone.SongIndex].Volume = volume; } base.Update(gameTime); }
static void DrawGizmo(AudioZone z, GizmoType t) { InitPrefs(); var c = z.GetGizmoColor(); if ((t & GizmoType.Selected) != 0) { c.a = 0.4f; } else { c.a = 0.1f; } Gizmos.color = c; if (z.peripheralFade.min < 1f) { Gizmos.color *= 0.5f; } if ((t & GizmoType.NotInSelectionHierarchy) == 0 || alwaysShowZoneGizmosPrefs) { DrawZ(z, z.peripheralFade.min, t); } }
/// <summary> /// Invokes the AudioZoneChanged event. /// </summary> /// <param name="audioZone">The audiozone that has been changed.</param> /// <param name="properties">List of propertynames that have been changed.</param> internal void OnAudioZoneChanged(AudioZone audioZone, List <string> properties) { if (ItemChanged != null) { try { ItemChanged(this, new ClientItemChangedEventArgs <NamedItem>(audioZone, properties)); } catch { } } if (AudioZoneChanged != null) { try { AudioZoneChanged(this, new ClientItemChangedEventArgs <AudioZone>(audioZone, properties)); } catch { } } }
/// <summary> /// Parse the content of one update message. /// </summary> /// <param name="message">The update message as received from the Domotech iRemote Server</param> private void ParsePollMessage(string message) { // The update message is a token string with a colon as separator string[] msg = message.Split(':'); // Split the message into tokens int index; try { // The second number mostly represents the item index index = int.Parse(msg[1]); } catch { index = 0; } int stepIndex; List <string> properties = new List <string>(); switch (msg[0]) // The first number always represents the message type { #region ACHANGED case "ACHANGED": { // Alarm parameter(s) changed Alarm alarm = client.lists.alarmList[index]; bool active = (byte.Parse(msg[2]) != 0); bool wasActive = (byte.Parse(msg[3]) != 0); byte timesOn = byte.Parse(msg[4]); if (alarm.active != active) { alarm.active = active; properties.Add("Active"); } if (alarm.wasActive != wasActive) { alarm.wasActive = wasActive; properties.Add("WasActive"); } if (alarm.timesOn != timesOn) { alarm.timesOn = timesOn; properties.Add("TimesOn"); } client.OnAlarmChanged(alarm, properties); } break; #endregion #region AIRCOCHANGED case "AIRCOCHANGED": { // Room airco temperature changed Room room = client.lists.roomList[index]; room.aircoTemp = Core.TempToDegrees(int.Parse(msg[2])); properties.Add("AircoTemp"); client.OnRoomChanged(room, properties); } break; #endregion #region AIRCOONOFFCHANGED case "AIRCOONOFFCHANGED": { // Room airco state changed Room room = client.lists.roomList[index]; room.aircoEnabled = (byte.Parse(msg[2]) != 0); properties.Add("AircoEnabled"); client.OnRoomChanged(room, properties); } break; #endregion #region AIRCOTCHANGED case "AIRCOTCHANGED": { // Room airco type changed Room room = client.lists.roomList[index]; room.aircoType = (RoomAircoType)byte.Parse(msg[2]); properties.Add("AircoType"); client.OnRoomChanged(room, properties); } break; #endregion /*case "ALARMNROK": * break;*/ /*case "ALARMOFF": * break;*/ #region ALARMTEXTUPD case "ALARMTEXTUPD": { // Alarm text changed Alarm alarm = client.lists.alarmList[index]; alarm.name = msg[2]; properties.Add("Name"); client.OnAlarmChanged(alarm, properties); } break; #endregion #region ALLCHANGED case "ALLCHANGED": // Recall init client.OnClientStatus(ClientStatusValue.ConfigChanged); client.Disconnect(); // Thread will reconnect & redownload break; #endregion /*case "ALSIL": * break;*/ /*case "ARESET": * break;*/ #region ASCHANGED case "ASCHANGED": { // Room airco activity changed Room room = client.lists.roomList[index]; room.aircoActive = (byte.Parse(msg[2]) != 0); properties.Add("AircoActive"); client.OnRoomChanged(room, properties); } break; #endregion #region AU_BASCHANGED case "AU_BASCHANGED": { // AudioZone bass value changed AudioZone audioZone = client.lists.audioZoneList[index]; audioZone.bass = Core.ValueToBassTreble(byte.Parse(msg[2])); properties.Add("Bass"); client.OnAudioZoneChanged(audioZone, properties); } break; #endregion #region AU_MUTECHANGED case "AU_MUTECHANGED": { // AudioZone mute value changed AudioZone audioZone = client.lists.audioZoneList[index]; audioZone.mute = (byte.Parse(msg[2]) != 0); properties.Add("Mute"); client.OnAudioZoneChanged(audioZone, properties); } break; #endregion #region AU_ONOFFCHANGED case "AU_ONOFFCHANGED": { // AudioZone state changed AudioZone audioZone = client.lists.audioZoneList[index]; audioZone.state = (byte.Parse(msg[2]) != 0); properties.Add("State"); client.OnAudioZoneChanged(audioZone, properties); } break; #endregion #region AU_SRCCHANGED case "AU_SRCCHANGED": { // AudioZone source changed AudioZone audioZone = client.lists.audioZoneList[index]; audioZone.inputSource = byte.Parse(msg[2]); properties.Add("InputSource"); client.OnAudioZoneChanged(audioZone, properties); } break; #endregion #region AU_TRECHANGED case "AU_TRECHANGED": { // AudioZone treble changed AudioZone audioZone = client.lists.audioZoneList[index]; audioZone.treble = Core.ValueToBassTreble(byte.Parse(msg[2])); properties.Add("Treble"); client.OnAudioZoneChanged(audioZone, properties); } break; #endregion #region AU_VOLCHANGED case "AU_VOLCHANGED": { // AudioZone volume changed AudioZone audioZone = client.lists.audioZoneList[index]; audioZone.volume = Core.ValueToVolume(byte.Parse(msg[2])); properties.Add("Volume"); client.OnAudioZoneChanged(audioZone, properties); } break; #endregion #region AUDIOINIT case "AUDIOINIT": // Return value of AudioInit // 1 when audiocontroller found, 0 when not client.lists.audioInitOk = (byte.Parse(msg[1]) != 0); break; #endregion /*case "AUDIONROK": * break;*/ #region AUSRCTEXTUPD case "AUSRCTEXTUPD": { // AudioSrouce text changed AudioSource audioSource = client.lists.audioSourceList[index]; audioSource.name = msg[2]; properties.Add("Name"); client.OnAudioSourceChanged(audioSource, properties); } break; #endregion #region AUZONTEXTUPD case "AUZONTEXTUPD": { // AudioZone text changed AudioZone audioZone = client.lists.audioZoneList[index]; audioZone.name = msg[2]; properties.Add("Name"); client.OnAudioZoneChanged(audioZone, properties); } break; #endregion #region B case "B": // Broadcast message from broadcastClientName break; #endregion #region CLIENTNAME case "CLIENTNAME": // Set the client name for the next broadcast message broadcastClientName = msg[1]; break; #endregion #region CLKCHANGED case "CLKCHANGED": // Domotech Master clock changed client.lists.clockHour = byte.Parse(msg[1]); client.lists.clockMinute = byte.Parse(msg[2]); break; #endregion #region DCHANGED case "DCHANGED": { // Dimmer parameter(s) changed Dimmer dimmer = client.lists.dimmerList[index]; byte value = byte.Parse(msg[2]); bool state = (byte.Parse(msg[3]) != 0); if (dimmer.value != value) { dimmer.value = value; properties.Add("Value"); } if (dimmer.state != state) { dimmer.state = state; properties.Add("State"); } client.OnDimmerChanged(dimmer, properties); } break; #endregion #region DIMMERTEXTUPD case "DIMMERTEXTUPD": { // Dimmer text changed Dimmer dimmer = client.lists.dimmerList[index]; dimmer.name = msg[2]; properties.Add("Name"); client.OnDimmerChanged(dimmer, properties); } break; #endregion #region GOODBYE case "GOODBYE": // Domotech iRemote Server is shutting down // Stop polling & warn user break; #endregion #region INSTRNROK case "INSTRNROK": break; #endregion #region LCHANGED case "LCHANGED": { // Light state changed Light light = client.lists.lightList[index]; light.state = (byte.Parse(msg[2]) != 0); properties.Add("State"); client.OnLightChanged(light, properties); } break; #endregion #region LIGHTTEXTUPD case "LIGHTTEXTUPD": { // Light text changed Light light = client.lists.lightList[index]; light.name = msg[2]; properties.Add("Name"); client.OnLightChanged(light, properties); } break; #endregion #region LOGVARTEXTUPD case "LOGVARTEXTUPD": { // LogVar text changed LogVar logVar = client.lists.logVarList[index]; logVar.name = msg[2]; properties.Add("Name"); client.OnLogVarChanged(logVar, properties); } break; #endregion #region MASTERINIT case "MASTERINIT": // Domotech iRemote Server started to download the // configuration from the Domotech Master. // Disable GUI until this operation has finished. break; #endregion #region MASTERLOST case "MASTERLOST": // Serial connection between the Domotech iRemote Server and // Domotech Master is lost. // Disable GUI until the connection is fixed. break; #endregion /*case "OK": * break;*/ /*case "ROOMNROK": * break;*/ #region ROOMTEXTUPD case "ROOMTEXTUPD": { // Room text changed Room room = client.lists.roomList[index]; room.name = msg[2]; properties.Add("Name"); client.OnRoomChanged(room, properties); } break; #endregion #region SCENNROK case "SCENNROK": { // Scenario has been executed Scenario scenario = client.lists.scenarioList[index]; scenario.busy = false; properties.Add("Busy"); client.OnScenarioChanged(scenario, properties); } break; #endregion #region SCENTEXTUPD case "SCENTEXTUPD": { // Scenario text changed Scenario scenario = client.lists.scenarioList[index]; scenario.name = msg[2]; properties.Add("Name"); client.OnScenarioChanged(scenario, properties); } break; #endregion #region SCHANGED case "SCHANGED": { // Socket state changed Socket socket = client.lists.socketList[index]; socket.state = (byte.Parse(msg[2]) != 0); properties.Add("State"); client.OnSocketChanged(socket, properties); } break; #endregion #region SHUTTERTEXTUPD case "SHUTTERTEXTUPD": { // Shutter text changed Shutter shutter = client.lists.shutterList[index]; shutter.name = msg[2]; properties.Add("Name"); client.OnShutterChanged(shutter, properties); } break; #endregion #region SOCKETTEXTUPD case "SOCKETTEXTUPD": { // Socket text changed Socket socket = client.lists.socketList[index]; socket.name = msg[2]; properties.Add("Name"); client.OnSocketChanged(socket, properties); } break; #endregion #region TATIMCHANGED case "TATIMCHANGED": { // Time of step in temp curve changed stepIndex = int.Parse(msg[2]); Room room = client.lists.roomList[index]; CurveStep curveStep = room.CurveSteps[stepIndex]; byte hour = byte.Parse(msg[3]); byte minute = byte.Parse(msg[4]); if (curveStep.hour != hour) { curveStep.hour = hour; properties.Add("Hour"); } if (curveStep.minute != minute) { curveStep.minute = minute; properties.Add("Minute"); } client.OnCurveStepChanged(curveStep, properties); } break; #endregion #region TATMPCHANGED case "TATMPCHANGED": { // Temperature of step in temp curve changed stepIndex = int.Parse(msg[2]); Room room = client.lists.roomList[index]; CurveStep curveStep = room.CurveSteps[stepIndex]; curveStep.temperature = Core.TempToDegrees(int.Parse(msg[3])); properties.Add("Temperature"); client.OnCurveStepChanged(curveStep, properties); } break; #endregion #region TCCHANGED case "TCCHANGED": { // Room temperature correction changed Room room = client.lists.roomList[index]; room.tempCorrection = Core.CorrectionToDegrees(byte.Parse(msg[2])); properties.Add("TempCorrection"); client.OnRoomChanged(room, properties); } break; #endregion #region TCHANGED case "TCHANGED": { // Room measured temperature changed Room room = client.lists.roomList[index]; room.measuredTemp = Core.TempToDegrees(int.Parse(msg[2])); properties.Add("MeasuredTemp"); client.OnRoomChanged(room, properties); } break; #endregion #region TDCHANGED case "TDCHANGED": { // Room day temperature changed Room room = client.lists.roomList[index]; room.dayTemp = Core.TempToDegrees(int.Parse(msg[2])); properties.Add("DayTemp"); client.OnRoomChanged(room, properties); } break; #endregion #region TIMCHANGED case "TIMCHANGED": { // Timer parameter(s) changed Timer timer = client.lists.timerList[index]; byte day = byte.Parse(msg[2]); byte hour = byte.Parse(msg[3]); byte minute = byte.Parse(msg[4]); if (timer.day != day) { timer.day = day; properties.Add("Day"); } if (timer.hour != hour) { timer.hour = hour; properties.Add("Hour"); } if (timer.minute != minute) { timer.minute = minute; properties.Add("Minute"); } client.OnTimerChanged(timer, properties); } break; #endregion /*case "TIMERADDED": * break;*/ /*case "TIMERNROK": * break;*/ /*case "TIMERREMOVED": * break;*/ #region TIMONOFFCHANGED case "TIMONOFFCHANGED": { // Timer state changed Timer timer = client.lists.timerList[index]; timer.state = (byte.Parse(msg[2]) != 0); properties.Add("State"); client.OnTimerChanged(timer, properties); } break; #endregion #region TNCHANGED case "TNCHANGED": { // Room night temperature changed Room room = client.lists.roomList[index]; room.nightTemp = Core.TempToDegrees(int.Parse(msg[2])); properties.Add("NightTemp"); client.OnRoomChanged(room, properties); } break; #endregion #region TONOFFCHANGED case "TONOFFCHANGED": { // Room temperature control state changed Room room = client.lists.roomList[index]; room.tempEnabled = (byte.Parse(msg[2]) != 0); properties.Add("TempEnabled"); client.OnRoomChanged(room, properties); } break; #endregion #region TSCHANGED case "TSCHANGED": { // Room temperature control activity changed Room room = client.lists.roomList[index]; room.tempActive = (byte.Parse(msg[2]) != 0); properties.Add("TempActive"); client.OnRoomChanged(room, properties); } break; #endregion #region TTCHANGED case "TTCHANGED": { // Room temperature control type changed Room room = client.lists.roomList[index]; room.tempType = (RoomTempType)byte.Parse(msg[2]); properties.Add("TempType"); client.OnRoomChanged(room, properties); } break; #endregion #region VCHANGED case "VCHANGED": { // LogVar state changed LogVar logVar = client.lists.logVarList[index]; logVar.state = (byte.Parse(msg[2]) != 0); properties.Add("State"); client.OnLogVarChanged(logVar, properties); } break; #endregion } }
public void AddZone(AudioZone zone) { m_zones.Add(zone); }
public static void DrawZoneLabelStatic(Zone z, Vector3 p) { if (z is AudioZone) { var e = AudioZone.FindEmitters((AudioZone)z); if (e.Length > 0) { bool first = true; foreach (var i in e) { if (i.patches != null) { for (int j = 0, k = i.patches.Length; j < k; ++j) { if (i.patches[j]) { if (first) { first = false; builder.Append('\n'); } builder.Append('\n'); builder.Append(i.patches[j].name); } } } } } } var s = builder.ToString(); builder.Length = 0; Handles.BeginGUI(); var c = GUI.color; GUI.color = Color.white; var x = new GUIContent(GetZoneCaption(z)); var y = new GUIContent(s); var l = HandleUtility.WorldPointToSizedRect(p, x, EditorStyles.boldLabel); var m = HandleUtility.WorldPointToSizedRect(p, y, EditorStyles.helpBox); float n = Mathf.Max(l.width, m.width); l.width = n; m.width = n; l.x -= m.width * 1.2f; l.y -= m.height * 0.5f; m.x = l.x - Mathf.Max(0f, m.width - l.width); m.y = l.y + 1f; EditorGUI.HelpBox(m, y.text, MessageType.None); EditorGUI.DropShadowLabel(l, x); GUI.color = c; Handles.EndGUI(); if (z.trigger == null) { EditorGUI.BeginChangeCheck(); float f = Handles.RadiusHandle(z.transform.rotation, p, z.radius); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(z, "Changed Zone Radius"); z.radius = f; } } }