private void DrawContactSymbol(DrawingContext drawingContext, RadarContact contact, bool primary) { switch (contact.Symbol) { case RadarSymbols.NONE: break; case RadarSymbols.UNKNOWN: _format.RenderText(drawingContext, _scopeBrush, "U", _symbolBounds); break; case RadarSymbols.ADVANCED_INTERCEPTOR: break; case RadarSymbols.BASIC_INTERCEPTOR: break; case RadarSymbols.ACTIVE_MISSILE: _format.RenderText(drawingContext, _scopeBrush, "M", _symbolBounds); break; case RadarSymbols.HAWK: _format.RenderText(drawingContext, _scopeBrush, "H", _symbolBounds); break; case RadarSymbols.PATRIOT: _format.RenderText(drawingContext, _scopeBrush, "P", _symbolBounds); break; case RadarSymbols.SA2: _format.RenderText(drawingContext, _scopeBrush, "2", _symbolBounds); break; case RadarSymbols.SA3: _format.RenderText(drawingContext, _scopeBrush, "3", _symbolBounds); break; case RadarSymbols.SA4: _format.RenderText(drawingContext, _scopeBrush, "4", _symbolBounds); break; case RadarSymbols.SA5: _format.RenderText(drawingContext, _scopeBrush, "5", _symbolBounds); break; case RadarSymbols.SA6: _format.RenderText(drawingContext, _scopeBrush, "6", _symbolBounds); break; case RadarSymbols.SA8: _format.RenderText(drawingContext, _scopeBrush, "8", _symbolBounds); break; case RadarSymbols.SA9: _format.RenderText(drawingContext, _scopeBrush, "9", _symbolBounds); break; case RadarSymbols.SA10: _format.RenderText(drawingContext, _scopeBrush, "10", _symbolBounds); break; case RadarSymbols.SA13: _format.RenderText(drawingContext, _scopeBrush, "13", _symbolBounds); break; case RadarSymbols.AAA: if (primary) { _format.RenderText(drawingContext, _scopeBrush, "A", _symbolBounds); } else { _format.RenderText(drawingContext, _scopeBrush, "S", _symbolBounds); } break; case RadarSymbols.NAVAL: break; case RadarSymbols.CHAPARAL: _format.RenderText(drawingContext, _scopeBrush, "C", _symbolBounds); break; case RadarSymbols.SA15: if (primary) { _format.RenderText(drawingContext, _scopeBrush, "15", _symbolBounds); } else { _format.RenderText(drawingContext, _scopeBrush, "M", _symbolBounds); } break; case RadarSymbols.NIKE: _format.RenderText(drawingContext, _scopeBrush, "N", _symbolBounds); break; case RadarSymbols.A1: _format.RenderText(drawingContext, _scopeBrush, "A", _symbolBounds); _format.RenderText(drawingContext, _scopeBrush, ".", _symbolSecondBounds); break; case RadarSymbols.A2: _format.RenderText(drawingContext, _scopeBrush, "A", _symbolBounds); _format.RenderText(drawingContext, _scopeBrush, "..", _symbolSecondBounds); break; case RadarSymbols.A3: _format.RenderText(drawingContext, _scopeBrush, "A", _symbolBounds); _format.RenderText(drawingContext, _scopeBrush, "...", _symbolSecondBounds); break; case RadarSymbols.PDOT: _format.RenderText(drawingContext, _scopeBrush, "P", _symbolBounds); _format.RenderText(drawingContext, _scopeBrush, ".", _symbolSecondBounds); break; case RadarSymbols.PSLASH: _format.RenderText(drawingContext, _scopeBrush, "P|", _symbolBounds); break; case RadarSymbols.UNK1: _format.RenderText(drawingContext, _scopeBrush, "U", _symbolBounds); _format.RenderText(drawingContext, _scopeBrush, ".", _symbolSecondBounds); break; case RadarSymbols.UNK2: _format.RenderText(drawingContext, _scopeBrush, "U", _symbolBounds); _format.RenderText(drawingContext, _scopeBrush, "..", _symbolSecondBounds); break; case RadarSymbols.UNK3: _format.RenderText(drawingContext, _scopeBrush, "U", _symbolBounds); _format.RenderText(drawingContext, _scopeBrush, "...", _symbolSecondBounds); break; case RadarSymbols.KSAM: _format.RenderText(drawingContext, _scopeBrush, "C", _symbolBounds); break; case RadarSymbols.V1: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "1", _symbolBounds); break; case RadarSymbols.V4: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "4", _symbolBounds); break; case RadarSymbols.V5: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "5", _symbolBounds); break; case RadarSymbols.V6: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "6", _symbolBounds); break; case RadarSymbols.V14: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "14", _symbolBounds); break; case RadarSymbols.V15: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "15", _symbolBounds); break; case RadarSymbols.V16: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "16", _symbolBounds); break; case RadarSymbols.V18: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "18", _symbolBounds); break; case RadarSymbols.V19: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "19", _symbolBounds); break; case RadarSymbols.V20: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "20", _symbolBounds); break; case RadarSymbols.V21: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "21", _symbolBounds); break; case RadarSymbols.V22: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "22", _symbolBounds); break; case RadarSymbols.V23: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "23", _symbolBounds); break; case RadarSymbols.V25: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "25", _symbolBounds); break; case RadarSymbols.V27: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "27", _symbolBounds); break; case RadarSymbols.V29: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "29", _symbolBounds); break; case RadarSymbols.V30: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "30", _symbolBounds); break; case RadarSymbols.V31: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "31", _symbolBounds); break; case RadarSymbols.VP: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "P", _symbolBounds); break; case RadarSymbols.VPD: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "PD", _symbolBounds); break; case RadarSymbols.VA: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "A", _symbolBounds); break; case RadarSymbols.VB: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "B", _symbolBounds); break; case RadarSymbols.VS: DrawCarret(drawingContext); _format.RenderText(drawingContext, _scopeBrush, "S", _symbolBounds); break; case RadarSymbols.SEARCH: _format.RenderText(drawingContext, _scopeBrush, "S", _symbolBounds); break; case RadarSymbols.Aa: _format.RenderText(drawingContext, _scopeBrush, "A|", _symbolBounds); break; case RadarSymbols.Ab: _format.RenderText(drawingContext, _scopeBrush, "|A|", _symbolBounds); break; case RadarSymbols.Ac: _format.RenderText(drawingContext, _scopeBrush, "|U|", _symbolBounds); _format.RenderText(drawingContext, _scopeBrush, "|", _symbolBounds); break; case RadarSymbols.MIB_F_S: if (primary) { _format.RenderText(drawingContext, _scopeBrush, "F", _symbolBounds); } else { _format.RenderText(drawingContext, _scopeBrush, "S", _symbolBounds); } break; case RadarSymbols.MIB_F_A: if (primary) { _format.RenderText(drawingContext, _scopeBrush, "F", _symbolBounds); } else { _format.RenderText(drawingContext, _scopeBrush, "A", _symbolBounds); } break; case RadarSymbols.MIB_F_M: if (primary) { _format.RenderText(drawingContext, _scopeBrush, "F", _symbolBounds); } else { _format.RenderText(drawingContext, _scopeBrush, "M", _symbolBounds); } break; case RadarSymbols.MIB_F_U: if (primary) { _format.RenderText(drawingContext, _scopeBrush, "F", _symbolBounds); } else { _format.RenderText(drawingContext, _scopeBrush, "U", _symbolBounds); } break; case RadarSymbols.MIB_F_BW: break; case RadarSymbols.MIB_BW_S: break; case RadarSymbols.MIB_BW_A: break; case RadarSymbols.MIB_BW_M: break; default: break; } }
public void Update() { float radarRange = _longRange ? LongRangeRadius : ShortRangeRadius; Vector3 pos = _car.transform.position; List <Car> cars = EntityManager.Instance.Cars; int carCount = cars.Count; for (int i = 0; i < carCount; ++i) { Car car = cars[i]; if (car == _car) { continue; } Vector3 carPos = car.transform.position; float distance = Vector3.Distance(carPos, pos); if (distance < radarRange) { Vector2 normal; normal.x = pos.x - carPos.x; normal.y = pos.z - carPos.z; normal.Normalize(); if (!_radarContacts.TryGetValue(car, out RadarContact contact)) { if (!_radarAudio.isPlaying || _radarAudio.clip != _newContact) { _radarAudio.clip = _newContact; _radarAudio.Play(); } contact = new RadarContact { TimeSinceSweep = 0f, Distance = distance, Normal = normal }; _radarContacts.Add(car, contact); } else { contact.Distance = distance; contact.Normal = normal; } } else { if (_target == car) { _target = null; } _radarContacts.Remove(car); } } if (_target == null) { _sweepTick += Time.deltaTime; if (_sweepTick > FrameTime) { _radarImageIndex = ++_radarImageIndex % SpriteFrames; ReferenceImage.ApplySprite(null, _sweepSprites[_radarImageIndex], false); _sweepTick -= FrameTime; } } Texture2D radarTexture = ReferenceImage.MainTexture; float pixelFactor = RadarTextureRadius / radarRange; // Process radar contacts. float deltaTime = Time.deltaTime; foreach (KeyValuePair <Car, RadarContact> radarContact in _radarContacts) { RadarContact contact = radarContact.Value; // Rotate radar contact points based on car's facing direction. contact.Normal = Utils.RotateVector(contact.Normal, _car.transform.eulerAngles.y + 180f); Vector2 radarOffset; radarOffset.x = RadarCenre.x + contact.Normal.x * contact.Distance * pixelFactor; radarOffset.y = RadarCenre.y + contact.Normal.y * contact.Distance * pixelFactor; float angle = Vector2.Angle(contact.Normal, Vector2.up); angle = Mathf.Sign(Vector3.Cross(contact.Normal, Vector2.up).z) < 0 ? (360 - angle) % 360 : angle; int sweepIndex = Mathf.Clamp(Mathf.CeilToInt(angle / DegreesPerSweep), 0, _targetSprites.Length); if (_target == radarContact.Key) { ReferenceImage.ApplySprite(null, _targetSprites[sweepIndex], false); } if (_target == null) { if (sweepIndex == _radarImageIndex) { _radarAudio.PlayIfNotAlreadyPlaying(_sweepContact); contact.TimeSinceSweep = 0f; } else { contact.TimeSinceSweep += deltaTime; } } else { // When we have a target, just use the same colour for all radar contacts. contact.TimeSinceSweep = 0f; } // Colours here aren't the same as original game - try and determine colour pattern. Color32 radarColour = Color32.Lerp(RadarContactNewColour, RadarContactOldColour, contact.TimeSinceSweep / 5f); for (int i = 0; i < 4; ++i) { _blipPixels[i] = radarColour; } radarTexture.SetPixels32((int)radarOffset.x, (int)radarOffset.y, 2, 2, _blipPixels); } bool hasRadarContacts = _radarContacts.Count > 0; ReferenceImage.ApplySprite("range_pos", _rangeSprites[_longRange ? 2 : 0], false); ReferenceImage.ApplySprite("led_pos", _ledSprites[hasRadarContacts ? 0 : 1], true); }