示例#1
0
        protected override void OnUpdate()
        {
            for (var i = 0; i < playerInputData.Length; i++)
            {
                var cameraTransform = playerInputData.CameraTransform[i];
                var forward         = cameraTransform.Rotation * Vector3.up;
                var right           = cameraTransform.Rotation * Vector3.right;
                var input           = Input.GetAxisRaw("Horizontal") * right + Input.GetAxisRaw("Vertical") * forward;

                var newPlayerInput = new SpatialOSPlayerInput
                {
                    Horizontal = input.x,
                    Vertical   = input.z,
                    Running    = Input.GetKey(KeyCode.LeftShift)
                };

                playerInputData.PlayerInput[i] = newPlayerInput;
            }
        }
示例#2
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());
        }