Exemple #1
0
        public void Initialize()
        {
            DontDestroyOnLoad(gameObject);
            Random r = new Random();

            _cachedServerState    = new ServerState();
            _cachedShootData      = new ShootPacket();
            _playerHealthPacket   = new PlayerHealthPacket();
            _userName             = Environment.MachineName + " " + r.Next(100000);
            LogicTimer            = new LogicTimer(OnLogicUpdate);
            _writer               = new NetDataWriter();
            G.ClientPlayerManager = _playerManager = new ClientPlayerManager(this);
            _shootsPool           = new GamePool <ShootEffect>(ShootEffectContructor, 100);

            _netManager      = G.CSEngineApp.LiteNet._netManager;
            _packetProcessor = G.CSEngineApp.LiteNet._packetProcessor;
            //_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
 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
 public ClientPlayer(ClientLogic clientLogic, ClientPlayerManager manager, string name, byte id) : base(manager, name, id)
 {
     _playerManager          = manager;
     _predictionPlayerStates = new LiteRingBuffer <PlayerInputPacket>(MaxStoredCommands);
     _clientLogic            = clientLogic;
 }