Component that, on awake, spawns a child plane with the shadow catcher model and material plus a directional light with pitch 90 under itself, then disables its own GameObject. Used as a temporary setup helper for entity shadows.
public class EntityShadows : Component {
[Property, ReadOnly] public GameObject ShadowCatcher {get; set;}
[Property, ReadOnly] public GameObject SunLight {get; set;}
protected override void OnAwake() {
Tags.Add("entity_shadows");
GameObject.Name = "ENTITY_SHADOWS";
GameObject.Enabled = false;
ShadowCatcher = Scene.CreateObject();
ShadowCatcher.SetParent(GameObject);
ShadowCatcher.Name = "plane";
var model = ShadowCatcher.Components.Create<ModelRenderer>();
model.Model = Model.Load("models/dev/plane.vmdl");
model.MaterialOverride = Material.Load("materials/shadow_catcher.vmat");
ShadowCatcher.WorldScale = 100f;
SunLight = Scene.CreateObject();
SunLight.SetParent(GameObject);
SunLight.Name = "sun";
SunLight.Components.Create<DirectionalLight>();
SunLight.WorldRotation = Rotation.FromPitch(90);
base.OnAwake();
}
}