void SpawnPlayer(PlayerSettings settings) { var entity = EntityManager.CreateEntity(playerArchetype); EntityManager.SetComponentData(entity, new Translation { Value = new float3(0, 0, 0) }); EntityManager.SetComponentData(entity, new Velocity { value = Unity.Mathematics.float2.zero }); EntityManager.SetComponentData(entity, new Speed { value = settings.speed }); EntityManager.SetComponentData(entity, new Faction() { value = FactionUtil.PLAYER_FACTION }); EntityManager.SetComponentData(entity, ColliderHelper.MakeBoxCollider(new Unity.Mathematics.float3(settings.colliderSize.x, settings.colliderSize.y, settings.colliderSize.z), false)); EntityManager.SetComponentData(entity, new Health() { current = settings.health, max = settings.health }); EntityManager.SetComponentData(entity, new Cooldown() { cd = settings.cd }); EntityManager.SetComponentData(entity, new Player() { bulletPrefab = 0 }); EntityManager.SetSharedComponentData(entity, new RenderMesh() { mesh = settings.mesh, material = settings.material }); EntityManager.AddBuffer <CollisionResult>(entity); EntityManager.AddBuffer <DamageEvent>(entity); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponent <PhysicsBody>(entity); if (dynamic) { dstManager.AddComponent <Dynamic>(entity); } if (useGravity) { dstManager.AddComponent <Gravity>(entity); dstManager.SetComponentData(entity, new Gravity() { value = gravityAcceleration }); } var sphereCollider = GetComponent <SphereCollider>(); if (sphereCollider) { dstManager.AddComponent <ColliderComponent>(entity); dstManager.SetComponentData(entity, ColliderHelper.MakeSphereCollider(sphereCollider.radius, trigger)); dstManager.SetComponentData(entity, new PhysicsBody() { elasticity = elasticity, inertiaTensorInv = Bootstrap.CalculateBoxInverseInertaTensor(sphereCollider.radius, sphereCollider.radius, sphereCollider.radius, mass) }); } var boxCollider = GetComponent <BoxCollider>(); if (boxCollider) { dstManager.AddComponent <ColliderComponent>(entity); var box = new Vector3(transform.localScale.x * boxCollider.size.x * 0.5f, transform.localScale.y * boxCollider.size.y * 0.5f, transform.localScale.z * boxCollider.size.z * 0.5f); dstManager.SetComponentData(entity, ColliderHelper.MakeBoxCollider(box, trigger)); dstManager.SetComponentData(entity, new PhysicsBody() { elasticity = elasticity, inertiaTensorInv = Bootstrap.CalculateBoxInverseInertaTensor(box.x, box.y, box.z, mass) }); } if (!sphereCollider && !boxCollider) { //todo: Warning } dstManager.AddComponent <AngularVelocity>(entity); dstManager.SetComponentData(entity, new AngularVelocity() { value = initialAngularVelocity }); dstManager.AddComponent <Velocity>(entity); dstManager.SetComponentData(entity, new Velocity() { value = initialLinearVelocity }); dstManager.AddComponent <Impulse>(entity); dstManager.SetComponentData(entity, new Impulse() { angularImpulse = float3.zero, impulse = float3.zero }); dstManager.AddComponent <Mass>(entity); dstManager.SetComponentData(entity, new Mass() { value = mass }); dstManager.AddBuffer <CollisionResult>(entity); }