Ejemplo n.º 1
0
    protected override void OnStartRunning()
    {
        GameData data = GameObject.FindObjectOfType <GameData>();

        // TODO: Figure out how to do this completely in code. As in add a new ghost by code. Is this even possible?
        var ghostCollection = GetSingleton <GhostPrefabCollectionComponent>();
        var ghostId         = SelfDev_NetcodeGhostSerializerCollection.FindGhostType <PuckSnapshotData>();
        var prefab          = EntityManager.GetBuffer <GhostPrefabBuffer>(ghostCollection.serverPrefabs)[ghostId].Value;
        var puck            = EntityManager.Instantiate(prefab);

#if UNITY_EDITOR
        EntityManager.SetName(puck, "Puck");
#endif

        Vector2 vel = Random.insideUnitCircle * LimitPuckVelocitySystem.SPEED;
        EntityManager.SetComponentData(puck, new PhysicsVelocity()
        {
            Linear  = new float3(vel.x, 0f, vel.y),
            Angular = float3.zero
        });

        EntityManager.AddComponent <ServerPuckData>(puck);

        Debug.Log($"Server creating game entities {puck}...");
    }
Ejemplo n.º 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));

            var ghostCollection = GetSingleton <GhostPrefabCollectionComponent>();
            var ghostId         = SelfDev_NetcodeGhostSerializerCollection.FindGhostType <PlayerSnapshotData>();
            var prefab          = EntityManager.GetBuffer <GhostPrefabBuffer>(ghostCollection.serverPrefabs)[ghostId].Value;
            var playerEntity    = EntityManager.Instantiate(prefab);

            int playerId = EntityManager.GetComponentData <NetworkIdComponent>(reqSrc.SourceConnection).Value;
            EntityManager.AddComponentData(playerEntity, new MovableCubeComponent {
                PlayerId = playerId
            });
            PostUpdateCommands.AddBuffer <CubeInput>(playerEntity);

            EntityManager.AddComponentData(playerEntity, new MainPlayerData {
                teamID = playerId
            });
            TeamData teamData = new TeamData()
            {
                teamID = playerId
            };

            bool up = (playerId % 2) == 0;
            EntityManager.SetComponentData(playerEntity, new Translation {
                Value = up ?
                        new float3(0f, 0f, POS) : new float3(0f, 0f, -POS)
            });

            AddExtraBlock(playerEntity, 1f, teamData, playerId);
            AddExtraBlock(playerEntity, 2f, teamData, playerId);
            AddExtraBlock(playerEntity, -1f, teamData, playerId);
            AddExtraBlock(playerEntity, -2f, teamData, playerId);

            Debug.Log($"Creating input buffer {playerEntity}");

            PostUpdateCommands.SetComponent(reqSrc.SourceConnection, new CommandTargetComponent {
                targetEntity = playerEntity
            });

            PostUpdateCommands.DestroyEntity(reqEnt);
        });
    }