Beispiel #1
0
        public static EntityTemplate CreateSpinnerEntityTemplate(Coordinates coords)
        {
            var transform = TransformUtils.CreateTransformSnapshot(coords.ToUnityVector(), Quaternion.identity);

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(coords), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot("Spinner"), 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.BLUE), WorkerUtils.UnityGameLogic);
            template.AddComponent(new SpinnerRotation.Snapshot(), WorkerUtils.UnityGameLogic);

            var query = InterestQuery.Query(Constraint.RelativeCylinder(radius: CheckoutRadius)).FilterResults(new[]
            {
                Position.ComponentId, Metadata.ComponentId, TransformInternal.ComponentId
            });

            var interest = InterestTemplate.Create()
                           .AddQueries <Position.Component>(query);

            template.AddComponent(interest.ToSnapshot());

            template.SetReadAccess(WorkerUtils.MobileClient, WorkerUtils.UnityClient, WorkerUtils.UnityGameLogic);

            return(template);
        }
Beispiel #2
0
        private static void CreateSpinner(Snapshot snapshot, Coordinates coords)
        {
            const string entityType = "Spinner";

            var transform = TransformUtils.CreateTransformSnapshot(coords, Quaternion.identity);

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(coords), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot(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.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);
        }
Beispiel #3
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);
        }