/// <summary> /// Sound manager weather profile change handler /// </summary> /// <param name="oldProfile">Old profile</param> /// <param name="newProfile">New profile</param> /// <param name="transitionDelay">Transition delay</param> /// <param name="transitionDuration">Transition duration</param> public void WeatherProfileChanged(WeatherMakerProfileScript oldProfile, WeatherMakerProfileScript newProfile, float transitionDelay, float transitionDuration) { // override sound zones if (WeatherProfileSoundFadeOutMultiplier > 0.0f) { foreach (Camera camera in Camera.allCameras) { if (WeatherMakerScript.IsLocalPlayer(camera.transform)) { WeatherMakerSoundZoneScript soundZone = camera.GetComponentInChildren <WeatherMakerSoundZoneScript>(); if (soundZone != null && soundZone.enabled) { float stopSeconds = transitionDuration * WeatherProfileSoundFadeOutMultiplier; soundZone.StopSounds(stopSeconds, true); // add new sounds if (newProfile.SoundProfile != null) { foreach (WeatherMakerSoundGroupScript soundScript in newProfile.SoundProfile.Sounds) { soundZone.AddSound(soundScript, true); } } } } } } }
private void NotifyThoseInZoneOfProfileChange(WeatherMakerProfileScript oldProfile, WeatherMakerProfileScript newProfile, float transitionDuration) { // anyone in this zone gets a new profile List <Transform> playersInZone; if (!zonesAndPlayers.TryGetValue(this, out playersInZone) || !PruneNulls(playersInZone)) { // no players in zone, we are done return; } List <string> connectionIds = new List <string>(); bool hasLocalPlayer = false; for (int i = 0; i < playersInZone.Count; i++) { Transform player = playersInZone[i]; hasLocalPlayer = WeatherMakerScript.IsLocalPlayer(player); connectionIds.Add(WeatherMakerScript.Instance.NetworkConnection.GetConnectionId(player)); } if (hasLocalPlayer) { WeatherMakerScript.Instance.LastLocalProfile = newProfile; } // send notification that those in this zone need a new weather profile WeatherMakerScript.Instance.RaiseWeatherProfileChanged(oldProfile, newProfile, secondsRemainingTransition, secondsRemainingHold, false, connectionIds.ToArray()); }
private void OnTriggerExit(Collider other) { if (!WeatherMakerScript.IsLocalPlayer(other.transform)) { return; } StopSounds(); soundZoneStack.Remove(this); // the next item on the stack can play if (soundZoneStack.Count != 0) { int index = soundZoneStack.Count - 1; WeatherMakerSoundZoneScript script = soundZoneStack[index]; if (script == null) { soundZoneStack.RemoveAt(index); } else { script.StartSounds(); } } }
private void Update() { // only take input from local player if (!WeatherMakerScript.IsLocalPlayer(transform)) { return; } UpdateMovement(); UpdateMouseLook(); if (Flashlight != null && WeatherMakerLightManagerScript.Instance != null) { if (Input.GetKeyDown(KeyCode.F)) { // hack: Bug in Unity, doesn't recognize that the light was enabled unless we rotate the camera transform.Rotate(0.0f, 0.01f, 0.0f); transform.Rotate(0.0f, -0.01f, 0.0f); Flashlight.enabled = !Flashlight.enabled; GameObject toggleObj = GameObject.Find("FlashlightCheckbox"); if (toggleObj != null) { UnityEngine.UI.Toggle toggle = toggleObj.GetComponent <UnityEngine.UI.Toggle>(); if (toggle != null) { toggle.isOn = !toggle.isOn; } } } WeatherMakerLightManagerScript.Instance.AddLight(Flashlight); } }
private void OnTriggerEnter(Collider other) { if (gameObject.activeInHierarchy && enabled && WeatherMakerScript.IsLocalPlayer(other.transform) && ++triggers == 1) { // if this is the first trigger entered, run it TweenFactory.Tween("WeatherMakerDampeningZoneScript", 0.0f, 1.0f, TransitionDuration, TweenScaleFunctions.Linear, (t) => { if (WeatherMakerAudioManagerScript.Instance != null) { float currentValue; if (!WeatherMakerAudioManagerScript.Instance.VolumeModifierDictionary.TryGetValue("WeatherMakerDampeningZoneScript", out currentValue)) { currentValue = 1.0f; } WeatherMakerAudioManagerScript.Instance.VolumeModifierDictionary["WeatherMakerDampeningZoneScript"] = Mathf.Lerp(currentValue, SoundDampening, t.CurrentValue); } if (WeatherMakerScript.Instance != null) { float currentValue; if (!WeatherMakerScript.Instance.IntensityModifierDictionary.TryGetValue("WeatherMakerDampeningZoneScript", out currentValue)) { currentValue = 1.0f; } WeatherMakerScript.Instance.IntensityModifierDictionary["WeatherMakerDampeningZoneScript"] = Mathf.Lerp(currentValue, IntensityDampening, t.CurrentValue); } if (WeatherMakerThunderAndLightningScript.Instance != null) { WeatherMakerThunderAndLightningScript.Instance.LightningBoltScript.LightParameters.LightIntensityMultiplier = Mathf.Lerp(WeatherMakerThunderAndLightningScript.Instance.LightningBoltScript.LightParameters.LightIntensityMultiplier, LightDampening, t.CurrentValue); } }); } }
private void OnTriggerExit(Collider other) { if (WeatherMakerScript.IsLocalPlayer(other.transform)) { HasEntered = false; } }
/// <summary> /// Mouse look value change /// </summary> /// <param name="val">New value</param> public void MouseLookEnabledChanged(bool val) { MouseLookEnabledCheckBox.isOn = val; foreach (GameObject obj in GameObject.FindGameObjectsWithTag("Player")) { if (WeatherMakerScript.IsLocalPlayer(obj.transform)) { WeatherMakerPlayerControllerScript controller = obj.GetComponent <WeatherMakerPlayerControllerScript>(); if (controller != null && controller.enabled) { controller.EnableMouseLook = val; break; } } } }
private void OnTriggerExit(Collider other) { // if this is the last trigger exited, run it if (gameObject.activeInHierarchy && enabled && WeatherMakerScript.IsLocalPlayer(other.transform) && --triggers == 0) { TweenFactory.Tween("WeatherMakerDampeningZoneScript", 0.0f, 1.0f, TransitionDuration, TweenScaleFunctions.Linear, (t) => { if (WeatherMakerAudioManagerScript.Instance != null) { float currentValue; if (WeatherMakerAudioManagerScript.Instance.VolumeModifierDictionary.TryGetValue("WeatherMakerDampeningZoneScript", out currentValue)) { WeatherMakerAudioManagerScript.Instance.VolumeModifierDictionary["WeatherMakerDampeningZoneScript"] = Mathf.Lerp(currentValue, 1.0f, t.CurrentValue); } } if (WeatherMakerScript.Instance != null) { float currentValue; if (WeatherMakerScript.Instance.IntensityModifierDictionary.TryGetValue("WeatherMakerDampeningZoneScript", out currentValue)) { WeatherMakerScript.Instance.IntensityModifierDictionary["WeatherMakerDampeningZoneScript"] = Mathf.Lerp(currentValue, 1.0f, t.CurrentValue); } } if (WeatherMakerThunderAndLightningScript.Instance != null) { WeatherMakerThunderAndLightningScript.Instance.LightningBoltScript.LightParameters.LightIntensity = Mathf.Lerp(WeatherMakerThunderAndLightningScript.Instance.LightningBoltScript.LightParameters.LightIntensity, 1.0f, t.CurrentValue); } }, (t) => { if (WeatherMakerAudioManagerScript.Instance != null) { WeatherMakerAudioManagerScript.Instance.VolumeModifierDictionary.Remove("WeatherMakerSoundDamperZoneScript"); } if (WeatherMakerScript.Instance != null) { WeatherMakerScript.Instance.IntensityModifierDictionary.Remove("WeatherMakerIntensityDamperZoneScript"); } }); } }
/// <summary> /// Flashlight value change /// </summary> /// <param name="val">New value</param> public void FlashlightChanged(bool val) { foreach (GameObject obj in GameObject.FindGameObjectsWithTag("Player")) { if (WeatherMakerScript.IsLocalPlayer(obj.transform)) { Light[] lights = obj.GetComponentsInChildren <Light>(); foreach (Light light in lights) { if (light.name == "Flashlight") { light.enabled = val; break; } } break; } } if (FlashlightToggle != null) { FlashlightToggle.isOn = val; } }
private void OnTriggerEnter(Collider other) { if (!WeatherMakerScript.IsLocalPlayer(other.transform)) { return; } // entered the trigger, can play StartSounds(); // stop previous sound zones even if they were not exited for (int i = 0; i < soundZoneStack.Count; i++) { if (soundZoneStack[i] == null) { soundZoneStack.RemoveAt(i--); } else { soundZoneStack[i].StopSounds(); } } soundZoneStack.Add(this); }
private void OnTriggerExit(Collider other) { if (SingleProfile == null && ProfileGroup == null) { return; } bool isServer = WeatherMakerScript.Instance != null && WeatherMakerScript.Instance.NetworkConnection.IsServer; if (isServer && gameObject.activeInHierarchy && enabled && WeatherMakerScript.IsPlayer(other.transform)) { List <WeatherMakerWeatherZoneScript> playerZones; if (!playersAndZones.TryGetValue(other.transform, out playerZones)) { playersAndZones[other.transform] = playerZones = new List <WeatherMakerWeatherZoneScript>(); } if (!playerZones.Contains(this)) { // not in this zone, exit out - sometimes OnTriggerExit is called twice in a row return; } List <Transform> zonePlayers; if (!zonesAndPlayers.TryGetValue(this, out zonePlayers)) { zonesAndPlayers[this] = zonePlayers = new List <Transform>(); } // if entering a new zone, begin transition to the new zone's current weather WeatherMakerProfileScript previousProfile = (playerZones.Count == 0 ? null : playerZones[playerZones.Count - 1].currentProfile); WeatherMakerProfileScript newProfile = null; // remove zone from the player zone stack playerZones.Remove(this); // remove player from the zone player list zonePlayers.Remove(other.transform); float transitionDuration = 0.0f; // add the player to the previous weather zone if any WeatherMakerWeatherZoneScript newZone = null; if (playerZones.Count != 0) { newZone = playerZones[playerZones.Count - 1]; if (!zonesAndPlayers.TryGetValue(newZone, out zonePlayers)) { zonePlayers = new List <Transform>(); } zonePlayers.Add(other.transform); // pick a new duration for the transition if (newZone.currentProfile != null) { transitionDuration = newZone.currentProfile.RandomTransitionDuration(); newProfile = newZone.currentProfile; } } else { Debug.LogError("Exited weather zone into no more zones, please add a global weather zone as a catch all zone"); return; } if (WeatherMakerScript.IsLocalPlayer(other.transform)) { WeatherMakerScript.Instance.LastLocalProfile = newProfile; WeatherMakerScript.Instance.WeatherZoneChanged.Invoke(newZone); } string connectionId = WeatherMakerScript.Instance.NetworkConnection.GetConnectionId(other.transform); // transition to new weather zone // if transition from another zone, multiply the transition duration so we get to the new weather zone weather more quickly WeatherMakerScript.Instance.RaiseWeatherProfileChanged(previousProfile, newProfile, transitionDuration * (previousProfile == null ? 1.0f : TransitionDurationMultiplier), secondsRemainingHold, false, (connectionId == null ? null : new string[1] { connectionId })); } }
private void OnTriggerEnter(Collider other) { if (SingleProfile == null && ProfileGroup == null) { return; } bool isServer = WeatherMakerScript.Instance != null && WeatherMakerScript.Instance.NetworkConnection.IsServer; if (isServer && gameObject.activeInHierarchy && enabled && WeatherMakerScript.IsPlayer(other.transform)) { // ensure we have player zones and zone players lists List <WeatherMakerWeatherZoneScript> playerZones; if (!playersAndZones.TryGetValue(other.transform, out playerZones)) { playersAndZones[other.transform] = playerZones = new List <WeatherMakerWeatherZoneScript>(); } if (playerZones.Contains(this)) { // already in the zone, don't re-process, sometimes OnTriggerEnter is called twice in a row return; } List <Transform> zonePlayers; if (!zonesAndPlayers.TryGetValue(this, out zonePlayers)) { zonesAndPlayers[this] = zonePlayers = new List <Transform>(); } // remove player from their previous zone WeatherMakerWeatherZoneScript prevZone = null; if (playerZones.Count != 0) { // remove player from previous weather zone prevZone = playerZones[playerZones.Count - 1]; List <Transform> prevZonePlayers; if (zonesAndPlayers.TryGetValue(prevZone, out prevZonePlayers)) { prevZonePlayers.Remove(other.transform); } } // see if we have a previous zone, if so we have a previous profile to transition from WeatherMakerProfileScript previousProfile = (playerZones.Count == 0 ? null : playerZones[playerZones.Count - 1].currentProfile); float transitionDuration = (previousProfile == null ? 0.001f : currentProfile.RandomTransitionDuration()); // add zone to the player zone stack playerZones.Add(this); // add player to the zone player list zonePlayers.Add(other.transform); if (WeatherMakerScript.IsLocalPlayer(other.transform)) { WeatherMakerScript.Instance.LastLocalProfile = currentProfile; if (prevZone != this) { WeatherMakerScript.Instance.WeatherZoneChanged.Invoke(this); } } // pick a new duration for the transition string connectionId = WeatherMakerScript.Instance.NetworkConnection.GetConnectionId(other.transform); // transition to new weather zone // if transition from another zone, multiply the transition duration so we get to the new weather zone weather more quickly WeatherMakerScript.Instance.RaiseWeatherProfileChanged(previousProfile, currentProfile, transitionDuration * (previousProfile == null ? 1.0f : TransitionDurationMultiplier), secondsRemainingHold, false, (connectionId == null ? null : new string[1] { connectionId })); } }
private void CameraPreCull(Camera camera) { if (!Application.isPlaying || !ShouldProcessCamera(camera)) { return; } bool intersectsCamera = false; bool hasWaterNullZone = false; if (WeatherMakerScript.IsLocalPlayer(camera.transform)) { int hits = Physics.OverlapSphereNonAlloc(camera.transform.position, 0.001f, WeatherMakerScript.tempColliders); for (int i = 0; i < hits; i++) { if (WeatherMakerScript.tempColliders[i] == waterCollider) { intersectsCamera = true; } else { WeatherMakerNullZoneScript script = WeatherMakerScript.tempColliders[i].GetComponent <WeatherMakerNullZoneScript>(); hasWaterNullZone |= (script != null && script.CurrentState != null && (script.CurrentState.RenderMask & NullZoneRenderMask.Water) != NullZoneRenderMask.Water); } } } if (intersectsCamera && !hasWaterNullZone) { if (underwaterCameras.Add(camera)) { // transition to being underwater //Debug.Log("Went underwater: " + camera.name); PlayUnderwaterSound(); PlaySplashSound(); if (UnderwaterCallback != null) { UnderwaterCallback.Invoke(this, camera, true); } // TODO: Activate any post processing volume } // render surface after precipitation and other alpha effects if under water MeshRenderer.sharedMaterial.renderQueue = 3000; isUnderwater = true; // reduce sun light as camera goes further down in the water if (WeatherMakerLightManagerScript.Instance != null) { float density = MeshRenderer.sharedMaterial.GetFloat(WMS._WaterFogDensity); float depth = Mathf.Max(0.0f, transform.position.y - camera.transform.position.y); float atten = (1.0f / (density * density * depth * depth)); atten = Mathf.Clamp(atten, 0.0f, 1.0f); WeatherMakerLightManagerScript.Instance.DirectionalLightIntensityMultipliers["WeatherMakerWaterScript" + GetInstanceID()] = atten; } } else { if (underwaterCameras.Contains(camera)) { // transition away from being underwater //Debug.Log("No longer underwater: " + camera.name); underwaterCameras.Remove(camera); if (UnderwaterAudioSource != null) { UnderwaterAudioSource.Stop(); } PlaySplashSound(); if (UnderwaterCallback != null) { UnderwaterCallback.Invoke(this, camera, false); } if (WeatherMakerLightManagerScript.Instance != null) { WeatherMakerLightManagerScript.Instance.DirectionalLightIntensityMultipliers.Remove("WeatherMakerWaterScript" + GetInstanceID()); } // TODO: Deactivate any post processing volume } #if UNITY_LWRP // can't use alpha test trick, so just render just before transparent MeshRenderer.sharedMaterial.renderQueue = 2998; #else // default render queue if above water MeshRenderer.sharedMaterial.renderQueue = -1; #endif isUnderwater = false; } }
private bool ShouldProcessCamera(Camera camera) { return(camera != null && waterCollider != null && waterCollider.enabled && !WeatherMakerScript.ShouldIgnoreCamera(this, camera) && WeatherMakerScript.IsLocalPlayer(camera.transform)); }