private Vector2 CalculateCollisionEscapeOffset(OverlayEntity[] movers) { Vector2 escapeOffset = Vector2.zero; for (int index = 0; index < movers.Length; index++) { OverlayEntity other = movers[index]; if (other != this && Overlaps(CornerArray, other.CornerArray)) { if (Vector2.Distance(RectCenter, other.RectCenter) <= 0) { escapeOffset += GetRandomDirection(); } else { escapeOffset += RectCenter - other.RectCenter; } if (_settings.RemainWithinBounds && DistanceFromParentCenter() < other.DistanceFromParentCenter()) { escapeOffset += ParentCenter - RectCenter; } } } return(escapeOffset); }
private void ApplyDistanceScaling(OverlayEntity entity) { if (Settings.UseDistanceScaling == false || entity.Target == null) { return; } var settings = Settings.DistanceScaleSettings; if (settings.Furthest == settings.Closest) { return; } // Calculate the scale with a linear equation. float x = Mathf.Clamp(entity.TargetDistanceFromCamera(), settings.Closest, settings.Furthest); float k = (settings.FurthestScale - settings.ClosestScale) / (settings.Furthest - settings.Closest); float m = settings.FurthestScale - k * settings.Furthest; float scale = k * x + m; entity.transform.localScale = Vector3.one * scale; }
/// <summary> /// Removes an entity from the system. /// </summary> public void UnsubscribeEntity(OverlayEntity entity) { _entities.Remove(entity); }
/// <summary> /// Adds the entity to the system. /// </summary> public void SubscribeEntity(OverlayEntity entity) { _entities.Add(entity); entity.PrepareForPositionUpdate(_cornerArray, UsedCamera, _settings); }