Exemple #1
0
    protected override void OnUpdate()
    {
        // Get all entities with the ReceiveRpc's component (and without the SendRpc's component),
        // and which also have a GoInGameRequest component indicating they wish to join the game.
        Entities.WithNone <SendRpcCommandRequestComponent>().ForEach((Entity reqEnt, ref GoInGameRequest req, ref ReceiveRpcCommandRequestComponent reqSrc) =>
        {
            // Mark that entity as in game
            PostUpdateCommands.AddComponent <NetworkStreamInGame>(reqSrc.SourceConnection);
            UnityEngine.Debug.Log(String.Format("Server setting connection {0} to in game", EntityManager.GetComponentData <NetworkIdComponent>(reqSrc.SourceConnection).Value));

            // Generate a controllable cube for this newly connected player with an input buffer
            // See CubeInput.cs
            var ghostCollection = GetSingleton <GhostPrefabCollectionComponent>();
            var ghostId         = NetCubeGhostSerializerCollection.FindGhostType <CubeSnapshotData>();
            var prefab          = EntityManager.GetBuffer <GhostPrefabBuffer>(ghostCollection.serverPrefabs)[ghostId].Value;
            var player          = EntityManager.Instantiate(prefab);
            EntityManager.SetComponentData(player, new MovableCubeComponent {
                PlayerId = EntityManager.GetComponentData <NetworkIdComponent>(reqSrc.SourceConnection).Value
            });

            PostUpdateCommands.AddBuffer <CubeInput>(player);
            PostUpdateCommands.SetComponent(reqSrc.SourceConnection, new CommandTargetComponent {
                targetEntity = player
            });

            // We don't need that request any more, destroy it.
            PostUpdateCommands.DestroyEntity(reqEnt);
        });
    }
Exemple #2
0
    protected override void OnUpdate()
    {
        Entities.WithNone <SendRpcCommandRequestComponent>().ForEach((Entity reqEnt, ref GoInGameRequest req, ref ReceiveRpcCommandRequestComponent reqSrc) =>
        {
            PostUpdateCommands.AddComponent <NetworkStreamInGame>(reqSrc.SourceConnection);
            UnityEngine.Debug.Log(String.Format("Server setting connection {0} to in game", EntityManager.GetComponentData <NetworkIdComponent>(reqSrc.SourceConnection).Value));
#if true
            var ghostCollection = GetSingleton <GhostPrefabCollectionComponent>();
            var ghostId         = NetCubeGhostSerializerCollection.FindGhostType <CubeSnapshotData>();
            var prefab          = EntityManager.GetBuffer <GhostPrefabBuffer>(ghostCollection.serverPrefabs)[ghostId].Value;
            var player          = EntityManager.Instantiate(prefab);
            EntityManager.SetComponentData(player, new MovableCubeComponent {
                PlayerId = EntityManager.GetComponentData <NetworkIdComponent>(reqSrc.SourceConnection).Value
            });

            PostUpdateCommands.AddBuffer <CubeInput>(player);
            PostUpdateCommands.SetComponent(reqSrc.SourceConnection, new CommandTargetComponent {
                targetEntity = player
            });
#endif


            PostUpdateCommands.DestroyEntity(reqEnt);
        });
    }
    protected override void OnUpdate()
    {
        Entities.WithNone <SendRpcCommandRequestComponent> ().ForEach((Entity reqEnt, ref ProjectileRequest request, ref ReceiveRpcCommandRequestComponent reqSrc) => {
            PostUpdateCommands.AddComponent <NetworkStreamInGame> (reqSrc.SourceConnection);

            var ghostCollection = GetSingleton <GhostPrefabCollectionComponent> ();
            var ghostId         = NetCubeGhostSerializerCollection.FindGhostType <SphereSnapshotData> ();
            var prefab          = EntityManager.GetBuffer <GhostPrefabBuffer> (ghostCollection.serverPrefabs) [ghostId].Value;

            var projectile = EntityManager.Instantiate(prefab);
            PostUpdateCommands.AddComponent(projectile, new InitProjectileComponent {
                origin = new float3(request.ox, request.oy, request.oz)
            });
            PostUpdateCommands.AddComponent(projectile, new ProjectileComponent {
                playerId = request.playerId,
                vector   = new float3(request.vx, request.vy, request.vz),
            });

            PostUpdateCommands.DestroyEntity(reqEnt);
        });
    }
Exemple #4
0
    protected override void OnUpdate()
    {
        Entities.ForEach((Entity reqEnt, ref FireBulletRequest req, ref ReceiveRpcCommandRequestComponent reqSrc) =>
        {
            PostUpdateCommands.AddComponent <NetworkStreamInGame>(reqSrc.SourceConnection);
#if true
            var ghostCollection = GetSingleton <GhostPrefabCollectionComponent>();
            var ghostId         = NetCubeGhostSerializerCollection.FindGhostType <CubeSnapshotData>();
            var prefab          = EntityManager.GetBuffer <GhostPrefabBuffer>(ghostCollection.serverPrefabs)[ghostId].Value;
            var bullet          = EntityManager.Instantiate(prefab);

            var p = UnityEngine.Random.insideUnitSphere;
            PostUpdateCommands.SetComponent(bullet, new Translation()
            {
                Value = new float3(p.x, p.y, p.z)
            });
#endif

            PostUpdateCommands.DestroyEntity(reqEnt);
        });
    }