private static void CreateSpinner(Snapshot snapshot, Coordinates coords) { const string entityType = "Spinner"; var transform = new TransformInternal.Snapshot { Location = new Location((float)coords.X, (float)coords.Y, (float)coords.Z), Rotation = new Quaternion(1, 0, 0, 0), TicksPerSecond = 1f / Time.fixedDeltaTime }; var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot { Coords = coords }, WorkerUtils.UnityGameLogic); template.AddComponent(new Metadata.Snapshot { EntityType = entityType }, WorkerUtils.UnityGameLogic); template.AddComponent(transform, WorkerUtils.UnityGameLogic); template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic); template.AddComponent(new Collisions.Snapshot(), WorkerUtils.UnityGameLogic); template.AddComponent(new SpinnerColor.Snapshot { Color = Color.BLUE }, WorkerUtils.UnityGameLogic); template.AddComponent(new SpinnerRotation.Snapshot(), WorkerUtils.UnityGameLogic); template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient, WorkerUtils.MobileClient); template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic); snapshot.AddEntity(template); }
public static void AddTransformSynchronizationComponents(EntityTemplate template, string writeAccess, Quaternion rotation, Vector3 location = default(Vector3), Vector3 velocity = default(Vector3)) { var transform = new TransformInternal.Snapshot { Location = location.ToImprobableLocation(), Rotation = rotation.ToImprobableQuaternion(), Velocity = velocity.ToImprobableVelocity(), TicksPerSecond = 1f / Time.fixedDeltaTime }; template.AddComponent(transform, writeAccess); }
private static void AddCubeGrid(Snapshot snapshot, int cubeCount) { var cubeTemplate = CubeTemplate.CreateCubeEntityTemplate(); // Calculate grid size var gridLength = (int)Math.Ceiling(Math.Sqrt(cubeCount)); if (gridLength % 2 == 1) // To make sure nothing is in (0, 0) { gridLength += 1; } var cubesToSpawn = cubeCount; for (var x = -gridLength + 1; x <= gridLength - 1; x += 2) { for (var z = -gridLength + 1; z <= gridLength - 1; z += 2) { // Leave the centre empty if (x == 0 && z == 0) { continue; } // Exit when we've hit our cube limit if (cubesToSpawn-- <= 0) { return; } var positionSnapshot = new Position.Snapshot { Coords = new Coordinates(x, 1, z) }; var transformSnapshot = new TransformInternal.Snapshot { Location = new Location(x, 1, z), Rotation = new Quaternion(1, 0, 0, 0), TicksPerSecond = 1f / Time.fixedDeltaTime }; cubeTemplate.SetComponent(positionSnapshot); cubeTemplate.SetComponent(transformSnapshot); snapshot.AddEntity(cubeTemplate); } } }