FloaterImage.cs
using Sandbox;
using System.Drawing;
public class FloaterImage : Component
{
private TimeSince _timeSinceSpawn;
public float Lifetime { get; set; }
public string Filename { get; set; }
private float _startScale;
private float _endScale;
private Vector2 _velocity;
private float _deceleration;
public float Scale { get; set; }
public float Opacity { get; set; }
public void Init( string filename, float lifetime, Vector2 velocity, float deceleration, float startScale, float endScale )
{
Filename = filename;
Lifetime = lifetime;
_velocity = velocity;
_deceleration = deceleration;
Scale = _startScale = startScale;
_endScale = endScale;
}
protected override void OnStart()
{
base.OnStart();
_timeSinceSpawn = 0f;
}
protected override void OnUpdate()
{
Opacity = Utils.Map( _timeSinceSpawn, 0f, 0.3f, 0f, 1f, EasingType.QuadOut ) * Utils.Map( _timeSinceSpawn, 0f, Lifetime - 0.1f, 1f, 0.1f, EasingType.ExpoIn ) * Utils.Map( _timeSinceSpawn, Lifetime - 0.3f, Lifetime - 0.05f, 1f, 0f, EasingType.Linear );
Scale = Utils.Map( _timeSinceSpawn, 0f, Lifetime, _startScale, _endScale, EasingType.SineOut );
WorldPosition += new Vector3( _velocity.x, _velocity.y, 0f ) * Time.Delta;
_velocity *= (1f - _deceleration * Time.Delta);
if ( _timeSinceSpawn > Lifetime )
{
GameObject.Destroy();
Manager.Instance.NumFloaters--;
}
}
}