Пример #1
0
        void SendInputs(Inputs inp, Results res)
        {
                #else
        void SendInputs(Inputs inp)
        {
                #endif

            if (!isLocalPlayer || isServer)
            {
                return;
            }

            if (inputWriter == null)
            {
                inputWriter = new NetworkWriter();
            }
            if (inpSend == null)
            {
                inpSend = new InputSend();
            }

            inputWriter.SeekZero();
            inputWriter.StartMessage(inputMessage);
                        #if (CLIENT_TRUST)
            inpRes     = new InputResult();
            inpRes.inp = inp;
            inpRes.res = res;
            inputWriter.Write(inpRes);
                        #else
            inpSend.inp = inp;
            inputWriter.Write(inpSend);
                        #endif
            inputWriter.FinishMessage();

            myClient.SendWriter(inputWriter, GetNetworkChannel());
        }

        void OnSendInputs(NetworkMessage msg)
        {
                        #if (CLIENT_TRUST)
            inpRes = msg.ReadMessage <InputResult> ();
            Inputs  inp = inpRes.inp;
            Results res = inpRes.res;
                        #else
            Inputs inp = msg.ReadMessage <InputSend> ().inp;
                        #endif

                        #if (SIMULATE)
                        #if (CLIENT_TRUST)
            StartCoroutine(SendInputsC(inp, res));
                        #else
            StartCoroutine(SendInputsC(inp));
                        #endif
        }

                #if (CLIENT_TRUST)
        IEnumerator SendInputsC(Inputs inp, Results res)
        {
                #else
        IEnumerator SendInputsC(Inputs inp)
        {
                #endif
            yield return(new WaitForSeconds(UnityEngine.Random.Range(0.21f, 0.28f)));
                        #endif

            if (!isLocalPlayer)
            {
                if (clientInputs.Count > data.clientInputsBuffer)
                {
                    clientInputs.RemoveAt(0);
                }

                if (!ClientInputsContainTimestamp(inp.timestamp))
                {
                    clientInputs.Add(inp);
                }

                                #if (CLIENT_TRUST)
                tempResults = res;
                                #endif

                currentTFixedUpdates += sendUpdates;

                if (data.debug && lastTick + 1 != inp.timestamp && lastTick != -1)
                {
                    Debug.Log("Missing tick " + lastTick + 1);
                }
                lastTick = inp.timestamp;
            }
        }

        //Results part
        public override void OnDeserialize(NetworkReader reader, bool initialState)