Map/Spray.cs
public sealed class Spray : Component
{
Material material { get; set; }
[Property]
GameObject SpraySmoke { get; set; }
protected override void OnStart()
{
if ( IsProxy ) return;
CreateMaterial();
}
[Rpc.Broadcast]
private void CreateMaterial()
{
if ( Application.IsDedicatedServer ) return;
if ( Network.Owner is null ) return;
var decal = Components.Get<Decal>();
decal.Rotation = 0;
decal.LifeTime = 0;
var texture = Texture.Load( $"avatarbig:{Network.Owner.SteamId}" );
decal.Decals.Add( new DecalDefinition()
{
ColorTexture = texture,
Width = 32,
Height = 32,
} );
if ( !SpraySmoke.IsValid() ) return;
var smoke = SpraySmoke.Clone( WorldPosition, Rotation.Identity );
var pe = smoke.GetComponent<ParticleEffect>();
if ( !pe.IsValid() )
return;
var pixel = texture.Height / 2 * texture.Width / 2;
var pix = texture.GetPixels( pixel );
pe.Tint = pix.FirstOrDefault().ToColor();
}
}