// Update is called once per frame
    void Update()
    {
        input.Clear();
        inputProc.UpdateInput(ref input, this);

        UpdateState();
        SmoothOrientation(); //角色朝向平滑过渡

        if (input.lockTarget && player.playerType == PlayerType.Local)
        {
            TimeSpan span = DateTime.Now - lastLockTime;
            if (span.TotalMilliseconds > 500)
            {
                lastLockTime = DateTime.Now;
                if (player.targetId > 0)
                {  //有目标,则取消
                    ClearTarget();
                }
                else
                {     //锁定目标
                    if (!LockTarget())
                    { //没有目标可以锁定,就重置视角
                        CameraControl cameraControl = GameObject.FindWithTag("MainCamera").GetComponent <CameraControl>();
                        cameraControl.ResetCamera(faceYaw);
                    }
                }
            }
        }
    }
Exemple #2
0
    public void UpdateInput(ref GameInput input, LocalPlayerController controller)
    {
        input.Clear();

        CameraControl cameraControl = GameObject.FindWithTag("MainCamera").GetComponent <CameraControl>();

        input.aimAngle.x = cameraControl.cameraPitch;
        input.aimAngle.y = cameraControl.cameraYaw;

        if (Application.platform == RuntimePlatform.Android || GlobalVariables.mobileUIOnPC)
        {
            UpdateInputOnMobile(ref input);
        }
        else
        {
            UpdateInputOnPC(ref input);
        }
    }
Exemple #3
0
        protected bool OnInput(NetworkMessage msg)
        {
            var inputMsg = msg as InputMessage;

            Log($"[OnInput] Processing sequence {msg.SequenceNumber}");

            // If a disconnect is requested, go ahead and disconnect now.
            bool disconnectRequested = inputMsg.DisconnectRequested;

            if (disconnectRequested)
            {
                if (currentState != State.Disconnected && !disconnectEventSent)
                {
                    Log("Disconnecting endpoint on remote request.");
                    QueueEvent(new UdpProtocolEvent(UdpProtocolEvent.Type.Disconnected));
                    disconnectEventSent = true;
                }
            }
            else
            {
                // Update the peer connection status if this peer is still considered to be part
                // of the network.
                NetworkConnectStatus[] remoteStatus = inputMsg.PeerConnectStatus;
                for (int i = 0; i < peerConnectStatus.Length; i++)
                {
                    if (remoteStatus[i] != null && peerConnectStatus[i] != null)
                    {
                        Debug.Assert(remoteStatus[i].LastFrame >= peerConnectStatus[i].LastFrame);
                        peerConnectStatus[i].Disconnected = peerConnectStatus[i].Disconnected || remoteStatus[i].Disconnected;
                        peerConnectStatus[i].LastFrame    = Math.Max(peerConnectStatus[i].LastFrame, remoteStatus[i].LastFrame);
                    }
                }
            }

            // Decompress the input.
            int lastReceivedFrameNumber = lastReceivedInput.frame;

            if (inputMsg.NumBits > 0)
            {
                int  offset       = 0;
                uint currentFrame = inputMsg.StartFrame;

                lastReceivedInput.size = inputMsg.InputSize;
                if (lastReceivedInput.frame < 0)
                {
                    lastReceivedInput.frame = (int)(inputMsg.StartFrame - 1);
                }

                while (offset < inputMsg.NumBits)
                {
                    // Keep walking through the frames (parsing bits) until we reach
                    // the inputs for the frame right after the one we're on.
                    Debug.Assert(currentFrame <= lastReceivedInput.frame + 1,
                                 $"currentFrame is {currentFrame} and lastRecievedInput.frame is {lastReceivedInput.frame} from sequence {inputMsg.SequenceNumber}");
                    bool useInputs = currentFrame == (lastReceivedInput.frame + 1);

                    while (Bitvector.ReadBit(inputMsg.Bits, ref offset) > 0)
                    {
                        bool on     = Bitvector.ReadBit(inputMsg.Bits, ref offset) > 0;
                        int  button = Bitvector.ReadNibblet(inputMsg.Bits, ref offset);

                        if (useInputs)
                        {
                            if (on)
                            {
                                lastReceivedInput.Set(button);
                            }
                            else
                            {
                                lastReceivedInput.Clear(button);
                            }
                        }
                    }
                    Debug.Assert(offset <= inputMsg.NumBits);

                    // Now if we want to use these inputs, go ahead and send them to
                    // the emulator.
                    if (useInputs)
                    {
                        // Move forward 1 frame in the stream.
                        Debug.Assert(currentFrame == lastReceivedInput.frame + 1,
                                     $"currentFrame is {currentFrame} and lastRecievedInput.frame is {lastReceivedInput.frame} from sequence {inputMsg.SequenceNumber}");
                        lastReceivedInput.frame = (int)currentFrame;

                        // Send the event to the emulator
                        var evt = new InputEvent
                        {
                            Input = lastReceivedInput,
                        };

                        runningState.lastInputPacketReceiveTime = Utility.GetCurrentTime();
                        Log($"Sending frame {lastReceivedInput.frame} to emu queue {queue} ({lastReceivedInput.ToString()}).");
                        QueueEvent(evt);
                    }
                    else
                    {
                        Log($"Skipping past frame:({currentFrame}) current is {lastReceivedInput.frame}.");
                    }

                    // Move forward 1 frame in the input stream.
                    currentFrame++;
                }
            }

            Debug.Assert(lastReceivedInput.frame >= lastReceivedFrameNumber);

            // Get rid of our buffered input
            while (!pendingOutput.IsEmpty && pendingOutput.Front().frame < inputMsg.AckFrame)
            {
                Log($"Throwing away pending output frame {pendingOutput.Front().frame}");
                lastAckedInput = pendingOutput.Front();
                pendingOutput.Pop();
            }

            Log($"[OnInput] Completed sequence {msg.SequenceNumber}");
            return(true);
        }