示例#1
0
        void Awake()
        {
            m_serverScene      = SceneManager.LoadScene("server_scene", Constants.DefaultSceneParams);
            m_ServerSimulation = m_serverScene.GetPhysicsScene();
            SceneManager.MoveGameObjectToScene(m_ServerSharedPlayer.gameObject, m_serverScene);

            m_LogicLoop = new GameLoop(OnNetworkUpdate);

            m_Inputs = new RingBuffer <InputMessage>(Constants.SNAPSHOT_RATE);

            m_PacketProcessor = new NetPacketProcessor();
            m_PacketProcessor.RegisterNestedType <EntityState>();
            m_PacketProcessor.RegisterNestedType <InputData>();
            m_PacketProcessor.SubscribeNetSerializable <InputMessage, NetPeer>(OnPlayerInput);

            m_Manager = new NetManager(this);

            m_LogicLoop.Start();

            if (m_Manager.Start(5000))
            {
                print("SERVER NET MANAGER STARTED!");
            }
            else
            {
                print("SERVER NET MANAGER FAILED!");
            }
        }
示例#2
0
文件: Client.cs 项目: Adevien/Netcode
        void Awake()
        {
            m_ClientScene      = SceneManager.LoadScene("client_scene", Constants.DefaultSceneParams);
            m_ClientSimulation = m_ClientScene.GetPhysicsScene();
            SceneManager.MoveGameObjectToScene(m_GetPlayer.gameObject, m_ClientScene);

            m_LogicLoop  = new GameLoop(OnNetworkUpdate);
            m_Simulation = new SimulationStep[Constants.SNAPSHOT_RATE];
            m_Snapshots  = new RingBuffer <Snapshot>(Constants.SNAPSHOT_RATE);
            m_Input      = new InputMessage(0, 0, new List <InputData>());

            m_PacketProcessor = new NetPacketProcessor();
            m_PacketProcessor.RegisterNestedType <EntityState>();
            m_PacketProcessor.SubscribeNetSerializable <Snapshot>(OnStateMessage);

            m_Manager = new NetManager(this);

            m_LogicLoop.Start();

            if (m_Manager.Start())
            {
                m_Manager.Connect("127.0.0.1", 5000, "key");
                print("CLIENT NET MANAGER STARTED!");
            }
            else
            {
                print("CLIENT NET MANAGER FAILED!");
            }

            m_Poller = GetComponent <InputPoller>();

            UI_Handler.instance.TurnOn();
            UIControl.instance.TurnOff();
        }