public override void OnStart(StartState state) { base.OnStart(state); _audioSource = gameObject.AddComponent <AudioSource> (); if (blipSound != null && blipSound.sound == null) { blipSound = part.partInfo.partPrefab.Modules.GetModules <ModuleTerrainRadar> ()[0].blipSound; } _audioSource.dopplerLevel = 0.0f; _audioSource.panLevel = 0.0f; _audioSource.enabled = true; _audioSource.Stop(); _transform = part.transform; if (scanTransform.Length > 0) { Transform tempTransform = part.FindModelTransform(scanTransform); if (tempTransform != null) { _transform = tempTransform; } } GroundReference(); _activeRadar = null; }
public override void OnInactive() { base.OnInactive(); _activeRadar = null; }
public void Update() { if (vessel == null) { return; } if (_dirty) { for (int y = 0; y < _terrain.height; y++) { for (int x = 0; x < _terrain.width; x++) { _terrain.SetPixel(x, y, Color.black); } } foreach (KeyValuePair <Vector2, float> kvp in _radarSamples) { SetPixel(kvp.Key.x, kvp.Key.y, kvp.Value, scanRadius); } _terrain.Apply(); float prevDist = 0f; for (int y = 0; y < _scaleGraph.height; y++) { float eqDist = _scale * (float)y / _scaleGraph.height; for (int x = 0; x < _scaleGraph.width; x++) { _scaleGraph.SetPixel(x, y, GetColorForDistance(_reference - eqDist)); } if (Math.Floor(prevDist) != Math.Floor(eqDist)) { for (int x = 0; x < _scaleGraph.width / 2; x++) { _scaleGraph.SetPixel(x, y, Color.black); _scaleGraph.SetPixel(x, y - 1, Color.black); } } prevDist = eqDist; } _scaleGraph.Apply(); for (int y = 0; y < _terrainLateral.height; y++) { for (int x = 0; x < _terrainLateral.width; x++) { _terrainLateral.SetPixel(x, y, Color.black); } } float radiusInc = scanRadius / 10f; Vector2 start = _minCoord.normalized * scanRadius; Vector2 end = -_minCoord.normalized * scanRadius; for (int x = 0; x < _terrainLateral.width; x++) { Vector2 lateralCoord = Vector2.Lerp(start, end, (float)x / _terrainLateral.width); foreach (KeyValuePair <Vector2, float> kvp in _radarSamples) { if (Math.Abs(kvp.Key.x - lateralCoord.x) < radiusInc && Math.Abs(kvp.Key.y - lateralCoord.y) < radiusInc) { if (kvp.Value < _reference - _scale) { _terrainLateral.SetPixel(x, _terrainLateral.height - 1, GetColorForDistance(kvp.Value)); continue; } if (kvp.Value > _reference) { _terrainLateral.SetPixel(x, 0, GetColorForDistance(kvp.Value)); continue; } float adjustedY = -(kvp.Value - _reference); int y = (int)(adjustedY * (float)_terrainLateral.height / _scale); _terrainLateral.SetPixel(x, y, GetColorForDistance(kvp.Value)); break; } } } _terrainLateral.Apply(); _dirty = false; } double ut = Planetarium.GetUniversalTime(); if (audioOutput && vessel.heightFromTerrain > 0f && vessel.heightFromTerrain < 1000f && vessel.situation != Vessel.Situations.LANDED) { if (ut - _blipTime > (double)altitudeCurve.Evaluate(vessel.heightFromTerrain) && !_audioSource.isPlaying) { if (_activeRadar == this || _activeRadar == null || !_activeRadar.isActiveAndEnabled || _activeRadar.vessel != FlightGlobals.ActiveVessel && vessel == FlightGlobals.ActiveVessel) { _activeRadar = this; if (!_audioSource.isPlaying && blipSound != null) { if (_playing == null) { _playing = blipSound; } if (_playing.sound != null) { _audioSource.clip = _playing.sound; _audioSource.Play(); } if (_playing != null) { _playing = _playing.next; } } } _blipTime = ut; } } else if (_activeRadar == this) { _activeRadar = null; } }
public override void OnStart(StartState state) { base.OnStart (state); _audioSource = gameObject.AddComponent<AudioSource> (); if (blipSound != null && blipSound.sound == null) { blipSound = part.partInfo.partPrefab.Modules.GetModules<ModuleTerrainRadar> ()[0].blipSound; } _audioSource.dopplerLevel = 0.0f; _audioSource.panLevel = 0.0f; _audioSource.enabled = true; _audioSource.Stop (); _transform = part.transform; if (scanTransform.Length > 0) { Transform tempTransform = part.FindModelTransform (scanTransform); if (tempTransform != null) { _transform = tempTransform; } } GroundReference (); _activeRadar = null; }
public override void OnInactive() { base.OnInactive (); _activeRadar = null; }
public void Update() { if (vessel == null) return; if (_dirty) { for (int y = 0; y < _terrain.height; y++) { for (int x = 0; x < _terrain.width; x++) { _terrain.SetPixel (x, y, Color.black); } } foreach (KeyValuePair<Vector2,float> kvp in _radarSamples) { SetPixel (kvp.Key.x, kvp.Key.y, kvp.Value, scanRadius); } _terrain.Apply (); float prevDist = 0f; for (int y = 0; y < _scaleGraph.height; y++) { float eqDist = _scale * (float)y / _scaleGraph.height; for (int x = 0; x < _scaleGraph.width; x++) { _scaleGraph.SetPixel (x, y, GetColorForDistance (_reference - eqDist)); } if (Math.Floor (prevDist) != Math.Floor (eqDist)) { for (int x = 0; x < _scaleGraph.width / 2; x++) { _scaleGraph.SetPixel (x, y, Color.black); _scaleGraph.SetPixel (x, y - 1, Color.black); } } prevDist = eqDist; } _scaleGraph.Apply (); for (int y = 0; y < _terrainLateral.height; y++) { for (int x = 0; x < _terrainLateral.width; x++) { _terrainLateral.SetPixel (x, y, Color.black); } } float radiusInc = scanRadius / 10f; Vector2 start = _minCoord.normalized * scanRadius; Vector2 end = -_minCoord.normalized * scanRadius; for (int x = 0; x < _terrainLateral.width; x++) { Vector2 lateralCoord = Vector2.Lerp (start, end, (float)x / _terrainLateral.width); foreach (KeyValuePair<Vector2,float> kvp in _radarSamples) { if (Math.Abs (kvp.Key.x - lateralCoord.x) < radiusInc && Math.Abs (kvp.Key.y - lateralCoord.y) < radiusInc) { if (kvp.Value < _reference - _scale) { _terrainLateral.SetPixel (x, _terrainLateral.height - 1, GetColorForDistance (kvp.Value)); continue; } if (kvp.Value > _reference) { _terrainLateral.SetPixel (x, 0, GetColorForDistance (kvp.Value)); continue; } float adjustedY = -(kvp.Value - _reference); int y = (int)(adjustedY * (float)_terrainLateral.height / _scale); _terrainLateral.SetPixel (x, y, GetColorForDistance (kvp.Value)); break; } } } _terrainLateral.Apply (); _dirty = false; } double ut = Planetarium.GetUniversalTime (); if (audioOutput && vessel.heightFromTerrain > 0f && vessel.heightFromTerrain < 1000f && vessel.situation != Vessel.Situations.LANDED) { if (ut - _blipTime > (double)altitudeCurve.Evaluate (vessel.heightFromTerrain) && !_audioSource.isPlaying) { if (_activeRadar == this || _activeRadar == null || !_activeRadar.isActiveAndEnabled || _activeRadar.vessel != FlightGlobals.ActiveVessel && vessel == FlightGlobals.ActiveVessel) { _activeRadar = this; if (!_audioSource.isPlaying && blipSound != null) { if (_playing == null) { _playing = blipSound; } if (_playing.sound != null) { _audioSource.clip = _playing.sound; _audioSource.Play (); } if (_playing != null) { _playing = _playing.next; } } } _blipTime = ut; } } else if (_activeRadar == this) { _activeRadar = null; } }