コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (frameCount <= 0)
        {
            frameCount = 1;
        }
        sendFrequency      = 1.0f / frameCount;
        timeSinceLastCall += Time.deltaTime;
        if (serverOrClient == ServerOrClient.Client)
        {
            Vector2 predPos = Prediction.GetQuadratic(timeSinceLastCall);
            ball.position = new Vector3(predPos.x, predPos.y, 0);
            Debug.Log("Pred:" + ball.position.x + "," + ball.position.y + " dt:" + timeSinceLastCall);
        }
        if (RemoteUpdateBall)
        {
            if (serverOrClient == ServerOrClient.Client)
            {
                Prediction.Add(ballpos, timeSinceLastCall);
                timeSinceLastCall = 0;
                ball.position     = new Vector3(ballpos.x, ballpos.y, 0);
            }
            else
            {
                RemoteUpdateBall = false;
            }
        }
        if (RemoteUpdateSliderL)
        {
            if (serverOrClient == ServerOrClient.Server)
            {
                sliderL.position = new Vector3(sliderL.position.x, sliderLY, sliderL.position.z);
            }
            RemoteUpdateSliderL = false;
        }
        if (RemoteUpdateSliderR)
        {
            if (serverOrClient == ServerOrClient.Server)
            {
                sliderR.position = new Vector3(sliderR.position.x, sliderRY, sliderR.position.z);
            }
            RemoteUpdateSliderR = false;
        }

        if (gameEvent == GameEvent.Start)
        {
            if (serverOrClient == ServerOrClient.Client)
            {
                SetStage();
            }
            if (serverOrClient == ServerOrClient.Server)
            {
                UpdateServerStage();
            }
        }
        if (gameEvent == GameEvent.Play)
        {
            if (serverOrClient == ServerOrClient.Server)
            {
                SendBallPos();
                MoveBall.moveable = true;
            }
            else if (serverOrClient == ServerOrClient.Client)
            {
                SendSliderPos();
            }
        }
    }