示例#1
0
        public static SnapshotEntity CreateArmchairEntityTemplate(Coordinates spawnPosition, float rotation)
        {
            var entityTemplate = new SnapshotEntity {
                Prefab = SimulationSettings.ArmchairPrefabName
            };

            entityTemplate.Add(new WorldTransform.Data(spawnPosition, MathUtils.ToNativeQuaternion(UnityEngine.Quaternion.Euler(0, rotation, 0))));
            entityTemplate.Add(new Grabbable.Data(new Option <CurrentGrabberInfo>()));

            var acl = Acl.GenerateServerAuthoritativeAcl(entityTemplate);

            entityTemplate.SetAcl(acl);

            return(entityTemplate);
        }
示例#2
0
        public static SnapshotEntity CreateCubeEntityTemplate(Coordinates spawnPosition)
        {
            var entityTemplate = new SnapshotEntity {
                Prefab = SimulationSettings.CubePrefabName
            };

            entityTemplate.Add(new WorldTransform.Data(spawnPosition, new Quaternion(0, 0, 0, 0)));
            entityTemplate.Add(new Grabbable.Data(new Option <CurrentGrabberInfo>()));

            var acl = Acl.GenerateServerAuthoritativeAcl(entityTemplate);

            entityTemplate.SetAcl(acl);

            return(entityTemplate);
        }
示例#3
0
        public static SnapshotEntity CreatePlayerCreatorTemplate()
        {
            var entityTemplate = new SnapshotEntity {
                Prefab = SimulationSettings.PlayerCreatorPrefabName
            };

            entityTemplate.Add(new WorldTransform.Data(Coordinates.ZERO, new Quaternion(0, 0, 0, 0)));
            entityTemplate.Add(new PlayerCreation.Data());

            var acl = Acl.GenerateServerAuthoritativeAcl(entityTemplate);

            entityTemplate.SetAcl(acl);

            return(entityTemplate);
        }
示例#4
0
    // Template definition for a Terrain entity
    public static SnapshotEntity GenerateTerrainSnapshotEntityTemplate()
    {
        // Set name of Unity prefab associated with this entity
        var terrain = new SnapshotEntity {
            Prefab = "Terrain"
        };

        // Define components attached to snapshot entity
        terrain.Add(new Terrain.Data(new TerrainData()));
        terrain.Add(new WorldTransform.Data(new WorldTransformData(new Coordinates(5, 0, 0), 0)));

        // Grant FSim workers write-access over all of this entity's components, read-access for visual (e.g. client) workers
        var acl = Acl.GenerateServerAuthoritativeAcl(terrain);

        terrain.SetAcl(acl);

        return(terrain);
    }
示例#5
0
        // Template definition for a PlayerSpawner entity
        public static SnapshotEntity GeneratePlayerSpawnerSnapshotEntityTemplate()
        {
            // Set name of Unity prefab associated with this entity
            var playerSpawner = new SnapshotEntity {
                Prefab = "PlayerSpawner"
            };

            // Define components attached to snapshot entity
            playerSpawner.Add(new WorldTransform.Data(new WorldTransformData(new Coordinates(0, 5, 0), new Vector3f(), 0.0f)));
            playerSpawner.Add(new Spawner.Data(new SpawnerData()));

            // Grant FSim (server-side) workers write-access over all of this entity's components, read-access for visual (e.g. client) workers
            var acl = Acl.GenerateServerAuthoritativeAcl(playerSpawner);

            playerSpawner.SetAcl(acl);

            return(playerSpawner);
        }
示例#6
0
        // Template definition for a Fish entity
        public static SnapshotEntity GenerateFishSnapshotEntityTemplate()
        {
            //Spawn to a random position
            Coordinates fishInitialCoordinates = new Coordinates(Random.Range(-tankSize, tankSize),
                                                                 Random.Range(0.0f, tankHeight),
                                                                 Random.Range(-tankSize, tankSize));

            Vector3f fishInitialRotation = new Vector3f(Random.Range(-30, 30),
                                                        Random.Range(-30, 30),
                                                        Random.value * 360);            //roll, pitch, yaw

            float speed = Random.Range(initialSpeed / 2.0f, initialSpeed);

            //float fishInitialSpeed = Random.Range (initialSpeed / 2.0f, initialSpeed);

            // Set name of Unity prefab associated with this entity
            var FishEntity = new SnapshotEntity {
                Prefab = "Fish"
            };


            // Define components attached to snapshot entity
            FishEntity.Add(new WorldTransform.Data(new WorldTransformData(fishInitialCoordinates, fishInitialRotation, speed)));
            FishEntity.Add(new FishParameters.Data(new FishParametersData(numFish, initialSpeed, tankSize, tankHeight)));

            // Grant UnityWorker (server-side) workers write-access over all of this entity's components, read-access for visual (e.g. client) workers
            var acl = Acl.GenerateServerAuthoritativeAcl(FishEntity);

            //Alastair's recommendation: seems to have an issue

            /*var acl = Acl.Build()
             *      .SetReadAccess(CommonRequirementSets.PhysicsOrVisual)
             *      .SetWriteAccess<WorldTransform>(CommonRequirementSets.PhysicsOnly)
             *      .SetWriteAccess<FishParameters>(CommonRequirementSets.PhysicsOnly);*/

            FishEntity.SetAcl(acl);

            return(FishEntity);
        }