Files
doom-dm/DoomDeathmatch/src/Scene/Play/Prefab/ConsumablePrefab.cs
2025-01-06 22:36:52 +03:00

51 lines
1.6 KiB
C#

using DoomDeathmatch.Component;
using DoomDeathmatch.Component.MVC;
using DoomDeathmatch.Component.Physics;
using DoomDeathmatch.Component.Physics.Collision;
using DoomDeathmatch.Component.Util;
using DoomDeathmatch.Script.Collision;
using DoomDeathmatch.Script.Consumable;
using Engine.Scene;
using Engine.Scene.Component.BuiltIn;
using Engine.Scene.Component.BuiltIn.Renderer;
using OpenTK.Mathematics;
namespace DoomDeathmatch.Scene.Play.Prefab;
public static class ConsumablePrefab
{
public static GameObject Create(Engine.Scene.Scene parScene,
IConsumable parConsumable, Transform? parBillboardTarget = null)
{
var box2DRenderer = new Box2DRenderer();
var collider = new AABBColliderComponent
{
Collider = new AABBCollider { Size = new Vector3(1f) },
Offset = new Vector3(0, 0f, 0.5f),
ColliderGroups = { "consumable" },
ExcludeColliderCollideGroups = { "enemy" }
};
var consumableObject = GameObjectUtil.CreateGameObject(parScene,
[
new ConsumableComponent(parConsumable, collider, box2DRenderer),
new RigidbodyComponent(),
new DragComponent { Drag = 10f, Multiplier = new Vector3(1, 1, 0) },
new MovementController { Speed = 10f },
collider
]
);
var innerObject = GameObjectUtil.CreateGameObject(parScene,
new Transform { Translation = new Vector3(0, 0f, 0.5f), Size = new Vector3(1f) }, [
box2DRenderer,
new BillboardComponent { Target = parBillboardTarget }
]
);
parScene.AddChild(consumableObject, innerObject);
return consumableObject;
}
}