示例#1
0
        public void copyFromSmoothSync(SmoothSyncPUN2 smoothSyncScript)
        {
            ownerTimestamp = smoothSyncScript.localTime;
            position       = smoothSyncScript.getPosition();
            rotation       = smoothSyncScript.getRotation();
            scale          = smoothSyncScript.getScale();

            if (smoothSyncScript.hasRigidbody)
            {
                velocity        = smoothSyncScript.rb.velocity;
                angularVelocity = smoothSyncScript.rb.angularVelocity * Mathf.Rad2Deg;
            }
            else if (smoothSyncScript.hasRigidbody2D)
            {
                velocity          = smoothSyncScript.rb2D.velocity;
                angularVelocity.x = 0;
                angularVelocity.y = 0;
                angularVelocity.z = smoothSyncScript.rb2D.angularVelocity;
            }
            else
            {
                velocity        = Vector3.zero;
                angularVelocity = Vector3.zero;
            }
            localTimeResetIndicator = smoothSyncScript.localTimeResetIndicator;
            //atPositionalRest = smoothSyncScript.sendAtPositionalRestMessage;
            //atRotationalRest = smoothSyncScript.sendAtRotationalRestMessage;
        }
    /// <summary>
    /// Cache a reference to the rigidbody component and Smooth Sync scripts.
    /// </summary>
    void Start()
    {
        rb              = GetComponent <Rigidbody>();
        rb2D            = GetComponent <Rigidbody2D>();
        smoothSync      = GetComponent <SmoothSyncPUN2>();
        childSmoothSync = transform.GetChild(0).GetComponent <SmoothSyncPUN2>();

        if (smoothSync)
        {
            // Set up a validation method to check incoming States to see if cheating may be happening.
            smoothSync.validateStateMethod = validateStateOfPlayer;
        }
    }
示例#3
0
    // Start is called before the first frame update
    void Start()
    {
        //  RPS_Storage storageScript = GameObject.Find("RPS_Storage").GetComponent<RPS_Storage>();
        storageScript    = GameObject.Find("RPS_Storage").GetComponent <RPS_Storage>();
        knockOutManager  = GameObject.Find("KnockOutManager");
        knockManagerList = GameObject.Find("KnockOutManager").GetComponent <KnockoutModeManager>();

        if (!GetComponent <PhotonView>().IsMine)
        {
            Destroy(GetComponent <SplineFollower>());
            Destroy(GetComponent <BicyclePowerSim>());
            Destroy(GetComponent <BicycleSplineController>());
            Destroy(GetComponent <WaypointProgressTracker>());
            Destroy(GetComponent <EVP.VehicleCameraController>());
            Destroy(GetComponent <BikeFrontLight>());
            Destroy(GetComponent <AzureAudioDayNightController>());
            //  Destroy(GetComponent<RPS_Inspector>());
            //  Destroy(GetComponent<RPS_Position>());
            //  Destroy(GetComponent<RPS_Lap>());
            //  Destroy(GetComponent<RPS_LapUI>());
            //  Destroy(GetComponent<EndOfRace>());
            Destroy(GetComponent <RPS_ScreenUI>());

            tag = "OtherPlayer";

            for (int i = 0; i < localScripts.Length; i++)
            {
                localScripts[i].enabled = false;
            }
            for (int i = 0; i < localObject.Length; i++)
            {
                localObject[i].SetActive(false);
            }

            smoothSync = GetComponent <SmoothSyncPUN2>();

            if (smoothSync)
            {
                // Set up a validation method to check incoming States to see if cheating may be happening.
                smoothSync.validateStateMethod = validateStateOfPlayer;
            }

            // otherplayer = GameObject.FindGameObjectWithTag("OtherPlayer");

            wait();
            Debug.Log("Ok Wait 2 seconds!");


            RPS_Position posScript = (RPS_Position)otherplayer.GetComponent <RPS_Position>() as RPS_Position;
            Debug.Log("RPS Adder2");

            //Add the other Players to the List for Knockout
            test = GameObject.FindGameObjectWithTag("OtherPlayer").GetComponent <PlayerTicket>();
            knockManagerList.players.Add(test);
            //  knockManagerList.AddPlayerCount();
            //  Debug.Log("AddPlayerCount +1");

            /*   wait();
             * for (int i = 0; i < knockManagerList.players.Count; i++)
             * {
             *     if (knockManagerList.players[i] != null)
             *         knockManagerList.playerCount += 1;
             * }
             */
            //remove duplicates
            // knockManagerList.players = knockManagerList.players.Distinct().ToList();
            Debug.Log("testOtherPlayerForKnockOutMode");

            //  knockOutManager.GetComponent<KnockoutModeManager>().AddOthers();
            //  Debug.Log("AddOtherNetWorkScript");

            // add the position to the storageScript
            if (!storageScript.positionScript.Contains(posScript))
            {
                storageScript.positionScript.Add(posScript);
            }
        }
    }
        public override void OnInspectorGUI()
        {
            SmoothSyncPUN2 myTarget = (SmoothSyncPUN2)target;

            GUIContent contentWhenToUpdateTransform = new GUIContent("When to Update Transform", "Update will have smoother results but FixedUpdate may be better for physics.");

            EditorGUILayout.PropertyField(serializedObject.FindProperty("whenToUpdateTransform"), contentWhenToUpdateTransform);
            GUIContent contentInterpolationBackTime = new GUIContent("Interpolation Back Time", "How much time in the past non-owned objects should be. This is so if you hit a latency spike, you still have a buffer of the interpolationBackTime of known States before you start extrapolating into the unknown. Increasing will make interpolation more likely to be used, decreasing will make extrapolation more likely to be used. Keep above 1/SendRate to attempt to always interpolate. In seconds.");

            EditorGUILayout.PropertyField(serializedObject.FindProperty("interpolationBackTime"), contentInterpolationBackTime);

            GUIContent contentTimeCorrectionSpeed = new GUIContent("Time Correction Speed", "The estimated owner time will shift by at most this amount per second. Lower values will be smoother but may take time to adjust to larger jumps in latency. Keep this lower than ~.5 unless you are having serious latency issues.");

            EditorGUILayout.PropertyField(serializedObject.FindProperty("timeCorrectionSpeed"), contentTimeCorrectionSpeed);
            GUIContent contentPositionLerpSpeed = new GUIContent("Position Easing Speed", "How fast to ease to the new position on non-owned objects. 0 is never, 1 is instant.");

            EditorGUILayout.PropertyField(serializedObject.FindProperty("positionLerpSpeed"), contentPositionLerpSpeed);
            GUIContent contentRotationLerpSpeed = new GUIContent("Rotation Easing Speed", "How fast to ease to the new rotation on non-owned objects. 0 is never, 1 is instant.");

            EditorGUILayout.PropertyField(serializedObject.FindProperty("rotationLerpSpeed"), contentRotationLerpSpeed);
            GUIContent contentScaleLerpSpeed = new GUIContent("Scale Easing Speed", "How fast to ease to the new scale on non-owned objects. 0 is never, 1 is instant.");

            EditorGUILayout.PropertyField(serializedObject.FindProperty("scaleLerpSpeed"), contentScaleLerpSpeed);

            GUIContent contentVariablesToSync = new GUIContent("Variables to Sync", "Fine tune what variables to sync.");

            showWhatToSync = EditorGUILayout.Foldout(showWhatToSync, contentVariablesToSync);
            if (showWhatToSync)
            {
                EditorGUI.indentLevel++;
                GUIContent contentSyncPosition = new GUIContent("Sync Position", "Fine tune what variables to sync.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("syncPosition"), contentSyncPosition);
                GUIContent contentSyncRotation = new GUIContent("Sync Rotation", "Fine tune what variables to sync");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("syncRotation"), contentSyncRotation);
                GUIContent contentSyncScale = new GUIContent("Sync Scale", "Fine tune what variables to sync");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("syncScale"), contentSyncScale);
                GUIContent contentSyncVelocity = new GUIContent("Sync Velocity", "Fine tune what variables to sync");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("syncVelocity"), contentSyncVelocity);
                GUIContent contentSyncAngularVelocity = new GUIContent("Sync Angular Velocity", "Fine tune what variables to sync");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("syncAngularVelocity"), contentSyncAngularVelocity);
                EditorGUI.indentLevel--;
            }

            GUIContent contentExtrapolation = new GUIContent("Extrapolation", "Extrapolation is going into the unknown based on information we had in the past. Generally, you'll want extrapolation to help fill in missing information during lag spikes.");

            showExtrapolation = EditorGUILayout.Foldout(showExtrapolation, contentExtrapolation);
            if (showExtrapolation)
            {
                EditorGUI.indentLevel++;
                GUIContent contentExtrapolationMode = new GUIContent("Extrapolation Mode", "None: No extrapolation. Limited: Some extrapolation. Unlimited: Unlimited extrapolation.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("extrapolationMode"), contentExtrapolationMode);
                if (myTarget.extrapolationMode == SmoothSyncPUN2.ExtrapolationMode.Limited)
                {
                    GUIContent contentUseExtrapolationTimeLimit     = new GUIContent("Use Extrapolation Time Limit", "Whether or not you want to use extrapolationTimeLimit. You can use only the extrapolationTimeLimit and save a distance check every extrapolation frame.");
                    GUIContent contentUseExtrapolationDistanceLimit = new GUIContent("Use Extrapolation Distance Limit", "Whether or not you want to use extrapolationDistanceLimit. You can use only the extrapolationTimeLimit and save a distance check every extrapolation frame.");
                    GUIContent contentExtrapolationDistanceLimit    = new GUIContent("Extrapolation Distance Limit", "How much distance into the future a non-owned object is allowed to extrapolate. In distance units.");
                    GUIContent contentExtrapolationTimeLimit        = new GUIContent("Extrapolation Time Limit", "How much time into the future a non-owned object is allowed to extrapolate. In seconds.");
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("useExtrapolationTimeLimit"), contentUseExtrapolationTimeLimit);
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("extrapolationTimeLimit"), contentExtrapolationTimeLimit);
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("useExtrapolationDistanceLimit"), contentUseExtrapolationDistanceLimit);
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("extrapolationDistanceLimit"), contentExtrapolationDistanceLimit);
                }
                EditorGUI.indentLevel--;
            }

            GUIContent contentThresholds = new GUIContent("Thresholds", "Use thresholds to control when to send and set the transform.");

            showThresholds = EditorGUILayout.Foldout(showThresholds, contentThresholds);
            if (showThresholds)
            {
                EditorGUI.indentLevel++;
                GUIContent contentSnapTimeThreshold = new GUIContent("Snap Time Threshold", "The estimated owner time will change instantly if the difference is larger than this amount (in seconds) when receiving an update. Generally keep at default unless you have a very low send rate and expect large variance in your latencies.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("snapTimeThreshold"), contentSnapTimeThreshold);
                GUIContent contentSnapPositionThreshold = new GUIContent("Snap Position Threshold", "If the position is more than snapThreshold units from the target position, it will jump to the target position immediately instead of easing. Set to 0 to not use at all. In distance units.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("snapPositionThreshold"), contentSnapPositionThreshold);
                GUIContent contentSnapRotationThreshold = new GUIContent("Snap Rotation Threshold", "If the rotation is more than snapThreshold units from the target rotation, it will jump to the target rotation immediately instead of easing. Set to 0 to not use at all. In degrees.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("snapRotationThreshold"), contentSnapRotationThreshold);
                GUIContent contentSnapScaleThreshold = new GUIContent("Snap Scale Threshold", "If the scale is more than snapThreshold units from the target scale, it will jump to the target scale immediately instead of easing. Set to 0 to not use at all. In degrees.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("snapScaleThreshold"), contentSnapScaleThreshold);

                GUIContent contentSendPositionThreshold = new GUIContent("Send Position Threshold", "A synced object's position is only sent if it is off from the last sent position by more than the threshold. In distance units.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("sendPositionThreshold"), contentSendPositionThreshold);
                GUIContent contentSendRotationThreshold = new GUIContent("Send Rotation Threshold", "A synced object's rotation is only sent if it is off from the last sent rotation by more than the threshold. In degrees.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("sendRotationThreshold"), contentSendRotationThreshold);
                GUIContent contentSendScaleThreshold = new GUIContent("Send Scale Threshold", "A synced object's scale is only sent if it is off from the last sent scale by more than the threshold. In distance units.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("sendScaleThreshold"), contentSendScaleThreshold);
                GUIContent contentSendVelocityThreshold = new GUIContent("Send Velocity Threshold", "A synced object's velocity is only sent if it is off from the last sent velocity by more than the threshold. In distance per second.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("sendVelocityThreshold"), contentSendVelocityThreshold);
                GUIContent contentSendAngularVelocityThreshold = new GUIContent("Send Angular Velocity Threshold", "A synced object's angular velocity is only sent if it is off from the last sent angular velocity by more than the threshold. In degrees per second.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("sendAngularVelocityThreshold"), contentSendAngularVelocityThreshold);

                GUIContent contentReceivedPositionThreshold = new GUIContent("Received Position Threshold", "A synced object's position is only updated if it is off from the target position by more than the threshold. Set to 0 to always update. Usually keep at 0 unless you notice problems with backtracking on stops. In distance units.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("receivedPositionThreshold"), contentReceivedPositionThreshold);
                GUIContent contentReceivedRotationThreshold = new GUIContent("Received Rotation Threshold", "A synced object's rotation is only updated if it is off from the target rotation by more than the threshold. Set to 0 to always update. Usually keep at 0 unless you notice problems with backtracking on stops. In degrees.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("receivedRotationThreshold"), contentReceivedRotationThreshold);
                EditorGUI.indentLevel--;
            }

            GUIContent contentCompression = new GUIContent("Compression", "Convert floats sent over the network to Halfs, which use half as much bandwidth but are also half as precise. It'll start becoming noticeably inaccurate over ~500.");

            showCompressions = EditorGUILayout.Foldout(showCompressions, contentCompression);
            if (showCompressions)
            {
                EditorGUI.indentLevel++;
                GUIContent contentCompressPosition = new GUIContent("Compress Position", "Compress floats to save bandwidth.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("isPositionCompressed"), contentCompressPosition);
                GUIContent contentCompressRotation = new GUIContent("Compress Rotation", "Compress floats to save bandwidth.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("isRotationCompressed"), contentCompressRotation);
                GUIContent contentCompressScale = new GUIContent("Compress Scale", "Compress floats to save bandwidth.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("isScaleCompressed"), contentCompressScale);
                GUIContent contentCompressVelocity = new GUIContent("Compress Velocity", "Compress floats to save bandwidth.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("isVelocityCompressed"), contentCompressVelocity);
                GUIContent contentCompressAngularVelocity = new GUIContent("Compress Angular Velocity", "Compress floats to save bandwidth.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("isAngularVelocityCompressed"), contentCompressAngularVelocity);
                EditorGUI.indentLevel--;
            }

            GUIContent contentMiscellaneous = new GUIContent("Miscellaneous", "Miscellaneous");

            showMiscellaneous = EditorGUILayout.Foldout(showMiscellaneous, contentMiscellaneous);
            if (showMiscellaneous)
            {
                EditorGUI.indentLevel++;
                GUIContent contentUseVelocityForSyncing = new GUIContent("Use Velocity Driven Syncing", "Set velocity instead of position on non-owned objects. Can be smoother but will be less accurate. Is meant to be used for racing or flying player objects but may have other uses.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("setVelocityInsteadOfPositionOnNonOwners"), contentUseVelocityForSyncing);
                if (myTarget.setVelocityInsteadOfPositionOnNonOwners == true)
                {
                    GUIContent contentMaxPositionDifference = new GUIContent("Max Position Difference", "If the difference between where it is and where it should be hits this, then it will go to location next frame. Is on an exponential scale otherwise. Only used for Velocity Driven Syncing.");
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("maxPositionDifferenceForVelocitySyncing"), contentMaxPositionDifference);
                }
                GUIContent contentUseLocalTransformOnly = new GUIContent("Use Local Transform Only", "Useful for VR applications that always have objects in local space.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("useLocalTransformOnly"), contentUseLocalTransformOnly);
                GUIContent contentAutomaticallyResetTime = new GUIContent("Automatically Reset Time", "Enable automatic local time reset to avoid float precision issues in long running games.\n\nWhen enabled localTime will be reset approximately every hour to prevent it from growing too large and introducing float precision issues that can cause jittering and other syncing issues in long running games. This costs an extra byte per network update, so don't enable this if you don't need it. When enabled localTime is also reset on each Scene load.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("automaticallyResetTime"), contentAutomaticallyResetTime);
            }

            serializedObject.ApplyModifiedProperties();
            //EditorUtility.SetDirty(myTarget);
        }
示例#5
0
        /// <summary>
        /// Deserialize a message from the network.
        /// </summary>
        /// <remarks>
        /// Only receives what it needs and decompresses floats if you chose to.
        /// </remarks>
        /// <param name="writer">The Networkreader to read from.</param>
        public void Deserialize(BinaryReader reader, SmoothSyncPUN2 smoothSync)
        {
            // The first received byte tells us what we need to be syncing.
            byte syncInfoByte        = reader.ReadByte();
            bool syncPosition        = shouldSyncPosition(syncInfoByte);
            bool syncRotation        = shouldSyncRotation(syncInfoByte);
            bool syncScale           = shouldSyncScale(syncInfoByte);
            bool syncVelocity        = shouldSyncVelocity(syncInfoByte);
            bool syncAngularVelocity = shouldSyncAngularVelocity(syncInfoByte);

            state.atPositionalRest = shouldBeAtPositionalRest(syncInfoByte);
            state.atRotationalRest = shouldBeAtRotationalRest(syncInfoByte);

            int syncIndex = (int)reader.ReadUInt32();

            state.ownerTimestamp = reader.ReadSingle();

            if (!smoothSync)
            {
                Debug.LogWarning("Could not find target for network state message.");
                return;
            }

            // If we want the server to relay non-owned object information out to other clients, set these variables so we know what we need to send.
            if (PhotonNetwork.IsMasterClient && !smoothSync.photonView.IsMine)
            {
                state.serverShouldRelayPosition        = syncPosition;
                state.serverShouldRelayRotation        = syncRotation;
                state.serverShouldRelayScale           = syncScale;
                state.serverShouldRelayVelocity        = syncVelocity;
                state.serverShouldRelayAngularVelocity = syncAngularVelocity;
            }

            // Find the correct object to sync according to the syncIndex.
            for (int i = 0; i < smoothSync.childObjectSmoothSyncs.Length; i++)
            {
                if (smoothSync.childObjectSmoothSyncs[i].syncIndex == syncIndex)
                {
                    smoothSync = smoothSync.childObjectSmoothSyncs[i];
                }
            }

            state.receivedTimestamp = smoothSync.localTime;

            if (smoothSync.receivedStatesCounter < PhotonNetwork.SerializationRate)
            {
                smoothSync.receivedStatesCounter++;
            }

            // Read position.
            if (syncPosition)
            {
                if (smoothSync.isPositionCompressed)
                {
                    if (smoothSync.isSyncingXPosition)
                    {
                        state.position.x = HalfHelper.Decompress(reader.ReadUInt16());
                    }
                    if (smoothSync.isSyncingYPosition)
                    {
                        state.position.y = HalfHelper.Decompress(reader.ReadUInt16());
                    }
                    if (smoothSync.isSyncingZPosition)
                    {
                        state.position.z = HalfHelper.Decompress(reader.ReadUInt16());
                    }
                }
                else
                {
                    if (smoothSync.isSyncingXPosition)
                    {
                        state.position.x = reader.ReadSingle();
                    }
                    if (smoothSync.isSyncingYPosition)
                    {
                        state.position.y = reader.ReadSingle();
                    }
                    if (smoothSync.isSyncingZPosition)
                    {
                        state.position.z = reader.ReadSingle();
                    }
                }
            }
            else
            {
                if (smoothSync.stateCount > 0)
                {
                    state.position = smoothSync.stateBuffer[0].position;
                }
                else
                {
                    state.position = smoothSync.getPosition();
                }
            }

            // Read rotation.
            if (syncRotation)
            {
                state.reusableRotationVector = Vector3.zero;
                if (smoothSync.isRotationCompressed)
                {
                    if (smoothSync.isSyncingXRotation)
                    {
                        state.reusableRotationVector.x  = HalfHelper.Decompress(reader.ReadUInt16());
                        state.reusableRotationVector.x *= Mathf.Rad2Deg;
                    }
                    if (smoothSync.isSyncingYRotation)
                    {
                        state.reusableRotationVector.y  = HalfHelper.Decompress(reader.ReadUInt16());
                        state.reusableRotationVector.y *= Mathf.Rad2Deg;
                    }
                    if (smoothSync.isSyncingZRotation)
                    {
                        state.reusableRotationVector.z  = HalfHelper.Decompress(reader.ReadUInt16());
                        state.reusableRotationVector.z *= Mathf.Rad2Deg;
                    }
                    state.rotation = Quaternion.Euler(state.reusableRotationVector);
                }
                else
                {
                    if (smoothSync.isSyncingXRotation)
                    {
                        state.reusableRotationVector.x = reader.ReadSingle();
                    }
                    if (smoothSync.isSyncingYRotation)
                    {
                        state.reusableRotationVector.y = reader.ReadSingle();
                    }
                    if (smoothSync.isSyncingZRotation)
                    {
                        state.reusableRotationVector.z = reader.ReadSingle();
                    }
                    state.rotation = Quaternion.Euler(state.reusableRotationVector);
                }
            }
            else
            {
                if (smoothSync.stateCount > 0)
                {
                    state.rotation = smoothSync.stateBuffer[0].rotation;
                }
                else
                {
                    state.rotation = smoothSync.getRotation();
                }
            }
            // Read scale.
            if (syncScale)
            {
                if (smoothSync.isScaleCompressed)
                {
                    if (smoothSync.isSyncingXScale)
                    {
                        state.scale.x = HalfHelper.Decompress(reader.ReadUInt16());
                    }
                    if (smoothSync.isSyncingYScale)
                    {
                        state.scale.y = HalfHelper.Decompress(reader.ReadUInt16());
                    }
                    if (smoothSync.isSyncingZScale)
                    {
                        state.scale.z = HalfHelper.Decompress(reader.ReadUInt16());
                    }
                }
                else
                {
                    if (smoothSync.isSyncingXScale)
                    {
                        state.scale.x = reader.ReadSingle();
                    }
                    if (smoothSync.isSyncingYScale)
                    {
                        state.scale.y = reader.ReadSingle();
                    }
                    if (smoothSync.isSyncingZScale)
                    {
                        state.scale.z = reader.ReadSingle();
                    }
                }
            }
            else
            {
                if (smoothSync.stateCount > 0)
                {
                    state.scale = smoothSync.stateBuffer[0].scale;
                }
                else
                {
                    state.scale = smoothSync.getScale();
                }
            }
            // Read velocity.
            if (syncVelocity)
            {
                if (smoothSync.isVelocityCompressed)
                {
                    if (smoothSync.isSyncingXVelocity)
                    {
                        state.velocity.x = HalfHelper.Decompress(reader.ReadUInt16());
                    }
                    if (smoothSync.isSyncingYVelocity)
                    {
                        state.velocity.y = HalfHelper.Decompress(reader.ReadUInt16());
                    }
                    if (smoothSync.isSyncingZVelocity)
                    {
                        state.velocity.z = HalfHelper.Decompress(reader.ReadUInt16());
                    }
                }
                else
                {
                    if (smoothSync.isSyncingXVelocity)
                    {
                        state.velocity.x = reader.ReadSingle();
                    }
                    if (smoothSync.isSyncingYVelocity)
                    {
                        state.velocity.y = reader.ReadSingle();
                    }
                    if (smoothSync.isSyncingZVelocity)
                    {
                        state.velocity.z = reader.ReadSingle();
                    }
                }
                smoothSync.latestReceivedVelocity = state.velocity;
            }
            else
            {
                // If we didn't receive an updated velocity, use the latest received velocity.
                state.velocity = smoothSync.latestReceivedVelocity;
            }
            // Read anguluar velocity.
            if (syncAngularVelocity)
            {
                if (smoothSync.isAngularVelocityCompressed)
                {
                    state.reusableRotationVector = Vector3.zero;
                    if (smoothSync.isSyncingXAngularVelocity)
                    {
                        state.reusableRotationVector.x  = HalfHelper.Decompress(reader.ReadUInt16());
                        state.reusableRotationVector.x *= Mathf.Rad2Deg;
                    }
                    if (smoothSync.isSyncingYAngularVelocity)
                    {
                        state.reusableRotationVector.y  = HalfHelper.Decompress(reader.ReadUInt16());
                        state.reusableRotationVector.y *= Mathf.Rad2Deg;
                    }
                    if (smoothSync.isSyncingZAngularVelocity)
                    {
                        state.reusableRotationVector.z  = HalfHelper.Decompress(reader.ReadUInt16());
                        state.reusableRotationVector.z *= Mathf.Rad2Deg;
                    }
                    state.angularVelocity = state.reusableRotationVector;
                }
                else
                {
                    if (smoothSync.isSyncingXAngularVelocity)
                    {
                        state.angularVelocity.x = reader.ReadSingle();
                    }
                    if (smoothSync.isSyncingYAngularVelocity)
                    {
                        state.angularVelocity.y = reader.ReadSingle();
                    }
                    if (smoothSync.isSyncingZAngularVelocity)
                    {
                        state.angularVelocity.z = reader.ReadSingle();
                    }
                }
                smoothSync.latestReceivedAngularVelocity = state.angularVelocity;
            }
            else
            {
                // If we didn't receive an updated angular velocity, use the latest received angular velocity.
                state.angularVelocity = smoothSync.latestReceivedAngularVelocity;
            }

            //// Update new owner information sent from the Server.
            //if (smoothSync.isSmoothingAuthorityChanges && !NetworkServer.active)
            //{
            //    smoothSync.ownerChangeIndicator = (int)reader.ReadByte();
            //}

            if (smoothSync.automaticallyResetTime)
            {
                state.localTimeResetIndicator = (int)reader.ReadByte();
            }
        }
示例#6
0
 /// <summary>
 /// Copy the SmoothSync object to a NetworkState.
 /// </summary>
 /// <param name="smoothSyncScript">The SmoothSync object</param>
 public void copyFromSmoothSync(SmoothSyncPUN2 smoothSyncScript)
 {
     this.smoothSync = smoothSyncScript;
     state.copyFromSmoothSync(smoothSyncScript);
 }
示例#7
0
 public NetworkStatePUN2(SmoothSyncPUN2 smoothSyncScript)
 {
     this.smoothSync = smoothSyncScript;
     state.copyFromSmoothSync(smoothSyncScript);
 }
示例#8
0
 public PhotonCarInstantiator([Inject(Id = "Car")] PhotonView photonView, SmoothSyncPUN2 smoothSync)
 {
     _photonView = photonView;
     _smoothSync = smoothSync;
 }