public static void SpawnIsland(float3 pos) { var entityManager = World.Active.GetOrCreateManager <EntityManager>(); float radius = 5; Entity island = entityManager.CreateEntity(IslandArchetype); entityManager.AddSharedComponentData(island, IslandLook); entityManager.SetComponentData(island, new Scale { Value = new float3(10.0f, 5.0f, 10.0f) }); pos.y = UnityEngine.Random.Range(-radius * 0.3f, 0f); entityManager.SetComponentData(island, new Position { Value = pos }); entityManager.SetComponentData(island, new Rotation { Value = quaternion.identity }); VectorField.Get().AddIsland(pos, radius, 3.5f); var debugMesh = CreateCircleMesh(radius, 100, 0.25f); var debugMaterial = new Material(Shader.Find("Unlit/DebugShader")); var debugRender = new DebugRenderComponent { Mesh = debugMesh, Material = debugMaterial }; entityManager.AddSharedComponentData(island, debugRender); entityManager.SetComponentData(island, new RadiusComponent { Value = radius }); }
public static void SpawnGoal(float3 pos, int type = 0) { var entityManager = World.Active.GetOrCreateManager <EntityManager>(); Entity goal = entityManager.CreateEntity(GoalArchetype); if (type == 0) { entityManager.AddSharedComponentData(goal, FoxLook); entityManager.SetComponentData(goal, new Scale { Value = new float3(1700.0f, 1700.0f, 1700.0f) }); } else { entityManager.AddSharedComponentData(goal, BunnyLook); entityManager.SetComponentData(goal, new Scale { Value = new float3(50.0f, 50.0f, 50.0f) }); } entityManager.SetComponentData(goal, new Position { Value = pos }); entityManager.SetComponentData(goal, new Rotation { Value = quaternion.identity }); float radius = 3; entityManager.SetComponentData(goal, new RadiusComponent { Value = radius }); var debugMesh = CreateCircleMesh(radius, 100, 0.25f); var debugMaterial = new Material(Shader.Find("Unlit/DebugShader")); var debugRender = new DebugRenderComponent { Mesh = debugMesh, Material = debugMaterial }; entityManager.AddSharedComponentData(goal, debugRender); }
public static void SpawnBoat(float3 pos) { var entityManager = World.Active.GetOrCreateManager <EntityManager>(); Entity boat = entityManager.CreateEntity(BoatArchetype); entityManager.AddSharedComponentData(boat, BoatLook); entityManager.SetComponentData(boat, new Scale { Value = new float3(100.0f, 100.0f, 100.0f) }); pos.y = 0.5f; //Make it float entityManager.SetComponentData(boat, new Position { Value = pos }); entityManager.SetComponentData(boat, new Rotation { Value = quaternion.identity }); entityManager.SetComponentData(boat, new TurnRateComponent { TurnRate = 10 }); entityManager.SetComponentData(boat, new VelocityComponent { Value = new float3(0, 0, 8) }); float radius = 4; entityManager.SetComponentData(boat, new RadiusComponent { Value = radius }); var debugMesh = CreateCircleMesh(radius, 100, 0.25f); var debugMaterial = new Material(Shader.Find("Unlit/DebugShader")); var debugRender = new DebugRenderComponent { Mesh = debugMesh, Material = debugMaterial }; entityManager.AddSharedComponentData(boat, debugRender); }
public static void SpawnRandomMeteorites(int amount) { var entityManager = World.Active.GetOrCreateManager <EntityManager>(); var random = new Unity.Mathematics.Random(835483957); /* Spawn a lot of meteorites */ for (int i = 0; i < amount; i++) { Entity meteorite = entityManager.CreateEntity(MeteoriteArchetype); entityManager.AddSharedComponentData(meteorite, MeteoriteLook); entityManager.SetComponentData(meteorite, new Scale { Value = new float3(0.02f, 0.02f, 0.02f) }); entityManager.SetComponentData(meteorite, new Position { Value = new float3(0f, -30f, 0f) }); entityManager.SetComponentData(meteorite, new VelocityComponent { Value = new float3(0f, 0f, 0f) }); entityManager.SetComponentData(meteorite, new Rotation { Value = Quaternion.identity }); entityManager.SetComponentData(meteorite, new RotationVelocity { Value = random.NextFloat3() * 300 * new float3(0f, 1f, 0f) - new float3(0f, 150f, 0f) }); float radius = 2; var debugMesh = CreateCircleMesh(radius, 100, 0.25f); var debugMaterial = new Material(Shader.Find("Unlit/DebugShader")); var debugRender = new DebugRenderComponent { Mesh = debugMesh, Material = debugMaterial }; entityManager.AddSharedComponentData(meteorite, debugRender); entityManager.SetComponentData(meteorite, new RadiusComponent { Value = radius }); } }