IsWriting
How do I use Is Writing
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
288 | if (stream.isWriting) | 1 |
25 | if (stream.isWriting) | 2 |
37 | if (stream.isWriting) | 3 |
37 | if (stream.isWriting) | 4 |
33 | if (stream.isWriting) | 5 |
19 | if (stream.isWriting) | 6 |
439 | if( stream.isWriting == true ) | 7 |
34 | if( stream.isWriting == true ) | 8 |
34 | if( stream.isWriting == true ) | 9 |
170 | if( stream.isWriting == true ) | 10 |
File name: PickupController.cs
Copy
286 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
287 {
288 if (stream.isWriting)
289 {
290 stream.SendNext(this.transform.position);
291 stream.SendNext((byte)this._characterState);
292 }
293 else
294 {
295 bool initialRemotePosition = (remotePosition == Vector3.zero);
296
297 remotePosition = (Vector3)stream.ReceiveNext();
298 this._characterState = (PickupCharacterState)((byte)stream.ReceiveNext());
299
300 if (initialRemotePosition)
301 {
302 // avoids lerping the character from "center" to the "current" position when this client joins
303 this.transform.position = remotePosition;
304 }
305 }
306 }
File name: CubeExtra.cs
Copy
21 // this method is called by PUN when this script is being "observed" by a PhotonView (setup in inspector)
22 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
23 {
24 // Always send transform (depending on reliability of the network view)
25 if (stream.isWriting)
26 {
27 Vector3 pos = transform.localPosition;
28 Quaternion rot = transform.localRotation;
29 stream.Serialize(ref pos);
30 stream.Serialize(ref rot);
31 }
32 // When receiving, buffer the information
33 else
34 {
35 // Receive latest state information
36 Vector3 pos = Vector3.zero;
37 Quaternion rot = Quaternion.identity;
38 stream.Serialize(ref pos);
39 stream.Serialize(ref rot);
40
41 lastMovement = (pos - latestCorrectPos) / (Time.time - lastTime);
42
43 lastTime = Time.time;
44 latestCorrectPos = pos;
45
46 transform.position = latestCorrectPos;
47 }
48 }
File name: CubeInter.cs
Copy
34 void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
35 {
36 // Always send transform (depending on reliability of the network view)
37 if (stream.isWriting)
38 {
39 Vector3 pos = transform.localPosition;
40 Quaternion rot = transform.localRotation;
41 stream.Serialize(ref pos);
42 stream.Serialize(ref rot);
43 }
44 // When receiving, buffer the information
45 else
46 {
47 // Receive latest state information
48 Vector3 pos = Vector3.zero;
49 Quaternion rot = Quaternion.identity;
50 stream.Serialize(ref pos);
51 stream.Serialize(ref rot);
52
53 // Shift buffer contents, oldest data erased, 18 becomes 19, ... , 0 becomes 1
54 for (int i = m_BufferedState.Length - 1; i >= 1; i--)
55 {
56 m_BufferedState[i] = m_BufferedState[i - 1];
57 }
58
59
60 // Save currect received state as 0 in the buffer, safe to overwrite after shifting
61 State state;
62 state.timestamp = info.timestamp;
63 state.pos = pos;
64 state.rot = rot;
65 m_BufferedState[0] = state;
66
67 // Increment state count but never exceed buffer size
68 m_TimestampCount = Mathf.Min(m_TimestampCount + 1, m_BufferedState.Length);
69
70 // Check integrity, lowest numbered state in the buffer is newest and so on
71 for (int i = 0; i < m_TimestampCount - 1; i++)
72 {
73 if (m_BufferedState[i].timestamp < m_BufferedState[i + 1].timestamp)
74 Debug.Log("State inconsistent");
75 }
76 }
77 }
File name: CubeLerp.cs
Copy
35 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
36 {
37 if (stream.isWriting)
38 {
39 Vector3 pos = transform.localPosition;
40 Quaternion rot = transform.localRotation;
41 stream.Serialize(ref pos);
42 stream.Serialize(ref rot);
43 }
44 else
45 {
46 // Receive latest state information
47 Vector3 pos = Vector3.zero;
48 Quaternion rot = Quaternion.identity;
49
50 stream.Serialize(ref pos);
51 stream.Serialize(ref rot);
52
53 latestCorrectPos = pos; // save this to move towards it in FixedUpdate()
54 onUpdatePos = transform.localPosition; // we interpolate from here to latestCorrectPos
55 fraction = 0; // reset the fraction we alreay moved. see Update()
56
57 transform.localRotation = rot; // this sample doesn't smooth rotation
58 }
59 }
File name: ThirdPersonNetwork.cs
Copy
31 void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
32 {
33 if (stream.isWriting)
34 {
35 //We own this player: send the others our data
36 stream.SendNext((int)controllerScript._characterState);
37 stream.SendNext(transform.position);
38 stream.SendNext(transform.rotation);
39 }
40 else
41 {
42 //Network player, receive data
43 controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
44 correctPlayerPos = (Vector3)stream.ReceiveNext();
45 correctPlayerRot = (Quaternion)stream.ReceiveNext();
46 }
47 }
File name: NetworkCharacter.cs
Copy
17 void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
18 {
19 if (stream.isWriting)
20 {
21 // We own this player: send the others our data
22 stream.SendNext(transform.position);
23 stream.SendNext(transform.rotation);
24
25 myThirdPersonController myC = GetComponent
26 stream.SendNext((int)myC._characterState);
27 }
28 else
29 {
30 // Network player, receive data
31 this.correctPlayerPos = (Vector3)stream.ReceiveNext();
32 this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
33
34 myThirdPersonController myC = GetComponent
35 myC._characterState = (CharacterState)stream.ReceiveNext();
36 }
37 }
File name: PhotonAnimatorView.cs
Copy
432 void OnPhotonSerializeView( PhotonStream stream, PhotonMessageInfo info )
433 {
434 if( m_Animator == null )
435 {
436 return;
437 }
438
439 if( stream.isWriting == true )
440 {
441 if( m_WasSynchronizeTypeChanged == true )
442 {
443 m_StreamQueue.Reset();
444 SerializeSynchronizationTypeState( stream );
445
446 m_WasSynchronizeTypeChanged = false;
447 }
448
449 m_StreamQueue.Serialize( stream );
450 SerializeDataDiscretly( stream );
451 }
452 else
453 {
454#if PHOTON_DEVELOP
455 if( ReceivingSender != null )
456 {
457 ReceivingSender.OnPhotonSerializeView( stream, info );
458 }
459 else
460#endif
461 {
462 if( stream.PeekNext() is byte[] )
463 {
464 DeserializeSynchronizationTypeState( stream );
465 }
466
467 m_StreamQueue.Deserialize( stream );
468 DeserializeDataDiscretly( stream );
469 }
470 }
471 }
File name: PhotonRigidbody2DView.cs
Copy
32 void OnPhotonSerializeView( PhotonStream stream, PhotonMessageInfo info )
33 {
34 if( stream.isWriting == true )
35 {
36 if( m_SynchronizeVelocity == true )
37 {
38 stream.SendNext( m_Body.velocity );
39 }
40
41 if( m_SynchronizeAngularVelocity == true )
42 {
43 stream.SendNext( m_Body.angularVelocity );
44 }
45 }
46 else
47 {
48 if( m_SynchronizeVelocity == true )
49 {
50 m_Body.velocity = (Vector2)stream.ReceiveNext();
51 }
52
53 if( m_SynchronizeAngularVelocity == true )
54 {
55 m_Body.angularVelocity = (float)stream.ReceiveNext();
56 }
57 }
58 }
File name: PhotonRigidbodyView.cs
Copy
32 void OnPhotonSerializeView( PhotonStream stream, PhotonMessageInfo info )
33 {
34 if( stream.isWriting == true )
35 {
36 if( m_SynchronizeVelocity == true )
37 {
38 stream.SendNext( m_Body.velocity );
39 }
40
41 if( m_SynchronizeAngularVelocity == true )
42 {
43 stream.SendNext( m_Body.angularVelocity );
44 }
45 }
46 else
47 {
48 if( m_SynchronizeVelocity == true )
49 {
50 m_Body.velocity = (Vector3)stream.ReceiveNext();
51 }
52
53 if( m_SynchronizeAngularVelocity == true )
54 {
55 m_Body.angularVelocity = (Vector3)stream.ReceiveNext();
56 }
57 }
58 }
File name: PhotonTransformViewPositionControl.cs
Copy
163 public void OnPhotonSerializeView( Vector3 currentPosition, PhotonStream stream, PhotonMessageInfo info )
164 {
165 if( m_Model.SynchronizeEnabled == false )
166 {
167 return;
168 }
169
170 if( stream.isWriting == true )
171 {
172 SerializeData( currentPosition, stream, info );
173 }
174 else
175 {
176 DeserializeData( stream, info );
177 }
178
179 m_LastSerializeTime = PhotonNetwork.time;
180 m_UpdatedPositionAfterOnSerialize = false;
181 }
IsWriting 173 lượt xem
Gõ tìm kiếm nhanh...