Exemple #1
0
        private void Awake()
        {
            DontDestroyOnLoad(gameObject);
            Random r = new Random();

            _cachedServerState = new ServerState();
            _cachedShootData   = new ShootPacket();
            _userName          = Environment.MachineName + " " + r.Next(100000);
            LogicTimer         = new LogicTimer(OnLogicUpdate);
            _writer            = new NetDataWriter();
            _playerManager     = new ClientPlayerManager(this);
            _shootsPool        = new GamePool <ShootEffect>(ShootEffectContructor, 100);
            _packetProcessor   = new NetPacketProcessor();
            _packetProcessor.RegisterNestedType((w, v) => w.Put(v), reader => reader.GetVector2());
            _packetProcessor.RegisterNestedType <PlayerState>();
            _packetProcessor.SubscribeReusable <PlayerJoinedPacket>(OnPlayerJoined);
            _packetProcessor.SubscribeReusable <JoinAcceptPacket>(OnJoinAccept);
            _packetProcessor.SubscribeReusable <PlayerLeavedPacket>(OnPlayerLeaved);
            _netManager = new NetManager(this)
            {
                AutoRecycle = true,
                IPv6Enabled = IPv6Mode.Disabled
            };
            _netManager.Start();
        }
Exemple #2
0
        private const float BufferTime = 0.1f; //100 milliseconds

        public RemotePlayer(ClientPlayerManager manager, string name, PlayerJoinedPacket pjPacket) : base(manager, name, pjPacket.InitialPlayerState.Id)
        {
            _position = pjPacket.InitialPlayerState.Position;
            _health   = pjPacket.Health;
            _rotation = pjPacket.InitialPlayerState.Rotation;
            _buffer.Add(pjPacket.InitialPlayerState);
        }
Exemple #3
0
        private const float BufferTime = 0.1f; //100 milliseconds

        public RemotePlayer(ClientPlayerManager manager, string name, RemotePlayerLoginPacket remotePlayerPacket) : base(manager, name, remotePlayerPacket.InitialPlayerState.Id)
        {
            _position  = remotePlayerPacket.InitialPlayerState.Position;
            _maxHealth = remotePlayerPacket.Health;
            _rotation  = remotePlayerPacket.InitialPlayerState.Rotation;
            _buffer.Add(remotePlayerPacket.InitialPlayerState);
        }
Exemple #4
0
        public ClientPlayer(ClientLogic clientLogic, ClientPlayerManager manager, string name, byte id) : base(manager, name, id)
        {
            _clientLogic            = clientLogic;
            playerManager           = manager;
            _predictionPlayerStates = new LiteRingBuffer <PlayerInputPacket>(MaxStoredCommands);
            PlayerName   = name;
            PlayerCombat = new ClientPlayerCombat(this);

            SubscribePacketListener();
        }
Exemple #5
0
        public ClientPacketHandler(ClientLogic clientLogic, NetPacketProcessor packetProcessor, ClientPlayerManager playerManager)
        {
            Instance = this;

            _writer          = new NetDataWriter();
            _clientLogic     = clientLogic;
            _packetProcessor = packetProcessor;
            _playerManager   = playerManager;

            SetListeners();
        }
        public ClientPlayer(ClientLogic clientLogic, ClientPlayerManager manager, string name, byte id) : base(manager, name, id)
        {
            _playerManager          = manager;
            _predictionPlayerStates = new LiteRingBuffer <PlayerInputPacket>(MaxStoredCommands);
            _clientLogic            = clientLogic;

            _predictionPlayerStates.FastClear();
            _predictionPlayerStates.Add(new PlayerInputPacket {
                Id = 0
            });
        }