Exemplo n.º 1
0
        public static Entity CreatePlayerEntityTemplate(List <string> clientAttributeSet,
                                                        Generated.Improbable.Vector3f position)
        {
            var clientAttribute = clientAttributeSet.First(attribute => attribute != SystemConfig.UnityClient);

            if (clientAttribute == null)
            {
                throw new InvalidOperationException(
                          "Expected an attribute that is not \"UnityClient\" but none was found.");
            }

            var transform =
                SpatialOSTransform.CreateSchemaComponentData(new Location(),
                                                             new Quaternion {
                W = 1, X = 0, Y = 0, Z = 0
            }, 0);
            var playerInput     = SpatialOSPlayerInput.CreateSchemaComponentData(0, 0, false);
            var prefab          = SpatialOSPrefab.CreateSchemaComponentData(ArchetypeConfig.CharacterArchetype);
            var archetype       = SpatialOSArchetypeComponent.CreateSchemaComponentData(ArchetypeConfig.CharacterArchetype);
            var launcher        = SpatialOSLauncher.CreateSchemaComponentData(100, 0);
            var clientHeartbeat = SpatialOSPlayerHeartbeatClient.CreateSchemaComponentData();
            var serverHeartbeat = SpatialOSPlayerHeartbeatServer.CreateSchemaComponentData();
            var score           = SpatialOSScore.CreateSchemaComponentData(0);

            var entityBuilder = EntityBuilder.Begin()
                                .AddPosition(0, 0, 0, SystemConfig.UnityGameLogic)
                                .AddMetadata(ArchetypeConfig.CharacterArchetype, SystemConfig.UnityGameLogic)
                                .SetPersistence(false)
                                .SetReadAcl(AllWorkerAttributes)
                                .SetEntityAclComponentWriteAccess(SystemConfig.UnityGameLogic)
                                .AddComponent(transform, SystemConfig.UnityGameLogic)
                                .AddComponent(playerInput, clientAttribute)
                                .AddComponent(prefab, SystemConfig.UnityGameLogic)
                                .AddComponent(archetype, SystemConfig.UnityGameLogic)
                                .AddComponent(launcher, SystemConfig.UnityGameLogic)
                                .AddComponent(clientHeartbeat, clientAttribute)
                                .AddComponent(serverHeartbeat, SystemConfig.UnityGameLogic)
                                .AddComponent(score, SystemConfig.UnityGameLogic);

            return(entityBuilder.Build());
        }
Exemplo n.º 2
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;
            const string entityType   = "Cube";

            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 transform = SpatialOSTransform.CreateSchemaComponentData(
                        new Location {
                        X = x, Y = 1, Z = z
                    },
                        new Quaternion {
                        W = 1, X = 0, Y = 0, Z = 0
                    },
                        0
                        );

                    var cubeColor          = SpatialOSCubeColor.CreateSchemaComponentData();
                    var cubeTargetVelocity = SpatialOSCubeTargetVelocity.CreateSchemaComponentData(new Vector3f {
                        X = -2.0f
                    });
                    var prefab             = SpatialOSPrefab.CreateSchemaComponentData(entityType);
                    var launchable         = SpatialOSLaunchable.CreateSchemaComponentData(new EntityId(0));
                    var archetypeComponent = SpatialOSArchetypeComponent.CreateSchemaComponentData(entityType);

                    var entity = EntityBuilder.Begin()
                                 .AddPosition(x, 0, z, SystemConfig.UnityGameLogic)
                                 .AddMetadata(entityType, SystemConfig.UnityGameLogic)
                                 .SetPersistence(true)
                                 .SetReadAcl(UnityWorkers)
                                 .AddComponent(transform, SystemConfig.UnityGameLogic)
                                 .AddComponent(cubeColor, SystemConfig.UnityGameLogic)
                                 .AddComponent(cubeTargetVelocity, SystemConfig.UnityGameLogic)
                                 .AddComponent(prefab, SystemConfig.UnityGameLogic)
                                 .AddComponent(archetypeComponent, SystemConfig.UnityGameLogic)
                                 .AddComponent(launchable, SystemConfig.UnityGameLogic)
                                 .Build();

                    snapshot.AddEntity(entity);
                }
            }
        }