public static void Create( Vector2D sourcePosition, Vector2D targetPosition, double traceStartWorldOffset, ITextureResource texture, double beamWidth, Vector2D originOffset, bool endsWithHit, double fadeInDistance, double fadeOutDistanceHit, double fadeOutDistanceNoHit, BlendMode blendMode, Color beamColor, double inAlpha = 1.0) { var deltaPos = targetPosition - sourcePosition; var length = deltaPos.Length; var fadeInFraction = fadeInDistance / length; var fadeOutFraction = endsWithHit ? fadeOutDistanceHit / length : fadeOutDistanceNoHit / length; if (fadeInFraction > 0.333 || fadeOutFraction > 0.333) { return; } color = inAlpha < 1.0 ? Color.FromArgb((byte)(255 * inAlpha), beamColor.R, beamColor.G, beamColor.B) : beamColor; var sceneObject = Client.Scene.CreateSceneObject(nameof(ComponentTracerBeam)); var component = sceneObject.AddComponent <ComponentTracerBeam>(); ComponentWeaponTrace.CalculateAngleAndDirection(deltaPos, out var angleRad, out var normalizedRay); sourcePosition += normalizedRay * traceStartWorldOffset; sceneObject.Position = sourcePosition; component.spriteRendererLine.Color = color; component.beamOriginOffset = originOffset; component.beamWidth = beamWidth; component.primaryRendererDefaultPositionOffset = Vector2D.Zero; component.spriteRendererLine.TextureResource = texture; component.targetPosition = targetPosition; component.spriteRendererLine.BlendMode = blendMode; component.Update(0); }
public void Refresh( Vector2D sourcePosition, double sourcePositionOffset, Vector2D targetPosition, double beamWidth, Color beamColor, Color spotColor, double beamOpacity, bool hasTarget) { beamColor = Color.FromArgb((byte)(beamOpacity * beamColor.A), beamColor.R, beamColor.G, beamColor.B); this.renderingMaterial.EffectParameters.Set("ColorAdditive", beamColor); this.spriteRendererLine.Color = beamColor; this.spriteRendererSpot.Color = spotColor; var deltaPos = targetPosition - sourcePosition; ComponentWeaponTrace.CalculateAngleAndDirection(deltaPos, out var angleRad, out var normalizedRay); sourcePosition += normalizedRay * sourcePositionOffset; deltaPos = targetPosition - sourcePosition; var sceneObjectPosition = this.spriteRendererLine.SceneObject.Position; this.spriteRendererLine.PositionOffset = sourcePosition - sceneObjectPosition; this.spriteRendererLine.RotationAngleRad = (float)angleRad; this.spriteRendererLine.Size = (ScriptingConstants.TileSizeVirtualPixels * deltaPos.Length, ScriptingConstants.TileSizeVirtualPixels *beamWidth); this.spriteRendererSpot.PositionOffset = targetPosition - sceneObjectPosition; this.spriteRendererSpot.Size = beamWidth * SpotScale * ScriptingConstants.TileSizeVirtualPixels; this.spriteRendererSpot.IsEnabled = hasTarget; }