Beispiel #1
0
        private static void AddCubeGrid(Snapshot snapshot, int cubeCount)
        {
            // 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 entityTemplate = CubeTemplate.CreateCubeEntityTemplate(new Coordinates(x, 1, z));
                    snapshot.AddEntity(entityTemplate);
                }
            }
        }
Beispiel #2
0
        private void OnEntityIdsReserved(WorldCommands.ReserveEntityIds.ReceivedResponse response)
        {
            if (response.StatusCode != StatusCode.Success)
            {
                logDispatcher.HandleLog(LogType.Error,
                                        new LogEvent("ReserveEntityIds failed.").WithField("Reason", response.Message));

                return;
            }

            var location           = transformReader.Data.Location;
            var cubeEntityTemplate = CubeTemplate.CreateCubeEntityTemplate();

            cubeEntityTemplate.SetComponent(new Position.Snapshot
            {
                Coords = new Coordinates(location.X, location.Y + 2, location.Z)
            });
            cubeEntityTemplate.SetComponent(new TransformInternal.Snapshot
            {
                Location = new Location(location.X, location.Y + 2, location.Z),
                Rotation = new Quaternion(1, 0, 0, 0)
            });
            var expectedEntityId = response.FirstEntityId.Value;

            worldCommandRequestSender.SendCreateEntityCommand(
                new WorldCommands.CreateEntity.Request(cubeEntityTemplate, expectedEntityId), OnEntityCreated);
        }
Beispiel #3
0
        private void OnEntityIdsReserved(WorldCommands.ReserveEntityIds.ReceivedResponse response)
        {
            if (!ReferenceEquals(this, response.Context))
            {
                // This response was not for a command from this behaviour.
                return;
            }

            if (response.StatusCode != StatusCode.Success)
            {
                logDispatcher.HandleLog(LogType.Error,
                                        new LogEvent("ReserveEntityIds failed.")
                                        .WithField("Reason", response.Message));

                return;
            }

            var location           = transformReader.Data.Location;
            var cubeEntityTemplate = CubeTemplate.CreateCubeEntityTemplate();

            cubeEntityTemplate.SetComponent(new Position.Snapshot
            {
                Coords = new Coordinates(location.X, location.Y + 2, location.Z)
            });
            cubeEntityTemplate.SetComponent(new TransformInternal.Snapshot
            {
                Location = new Location(location.X, location.Y + 2, location.Z),
                Rotation = new Quaternion(1, 0, 0, 0)
            });
            var expectedEntityId = response.FirstEntityId.Value;

            worldCommandRequestSender.CreateEntity(cubeEntityTemplate, expectedEntityId, context: this);
        }
        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);
                }
            }
        }
Beispiel #5
0
        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 location          = new Vector3(x, 1, z);
                    var positionSnapshot  = new Position.Snapshot(location.ToCoordinates());
                    var transformSnapshot = TransformUtils.CreateTransformSnapshot(location, Quaternion.identity);

                    cubeTemplate.SetComponent(positionSnapshot);
                    cubeTemplate.SetComponent(transformSnapshot);
                    snapshot.AddEntity(cubeTemplate);
                }
            }
        }
        private void OnEntityIdsReserved(WorldCommands.ReserveEntityIds.ReceivedResponse response)
        {
            if (response.StatusCode != StatusCode.Success)
            {
                logDispatcher.HandleLog(LogType.Error,
                                        new LogEvent("ReserveEntityIds failed.").WithField("Reason", response.Message));

                return;
            }

            var location = gameObject.transform.position;

            location.y += 2;

            var cubeEntityTemplate = CubeTemplate.CreateCubeEntityTemplate();

            cubeEntityTemplate.SetComponent(new Position.Snapshot(location.ToCoordinates()));
            cubeEntityTemplate.SetComponent(TransformUtils.CreateTransformSnapshot(location, Quaternion.identity));

            var expectedEntityId = response.FirstEntityId.Value;

            worldCommandRequestSender.SendCreateEntityCommand(
                new WorldCommands.CreateEntity.Request(cubeEntityTemplate, expectedEntityId), OnEntityCreated);
        }