本文整理汇总了C#中PhotonStream.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# PhotonStream.Serialize方法的具体用法?C# PhotonStream.Serialize怎么用?C# PhotonStream.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhotonStream
的用法示例。
在下文中一共展示了PhotonStream.Serialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnPhotonSerializeView
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
Vector3 pos = transform.localPosition;
Quaternion rot = transform.localRotation;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
}
else
{
Vector3 pos = Vector3.zero;
Quaternion rot = Quaternion.identity;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
latestCorrectPos = pos;
onUpdatePos = transform.localPosition;
fraction = 0;
transform.localRotation = rot;
}
}
示例2: OnPhotonSerializeView
/// <summary>
/// While script is observed (in a PhotonView), this is called by PUN with a stream to write or read.
/// </summary>
/// <remarks>
/// The property stream.isWriting is true for the owner of a PhotonView. This is the only client that
/// should write into the stream. Others will receive the content written by the owner and can read it.
///
/// Note: Send only what you actually want to consume/use, too!
/// Note: If the owner doesn't write something into the stream, PUN won't send anything.
/// </remarks>
/// <param name="stream">Read or write stream to pass state of this GameObject (or whatever else).</param>
/// <param name="info">Some info about the sender of this stream, who is the owner of this PhotonView (and GameObject).</param>
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
Debug.Log ("OnPhotonSerializeView");
if (stream.isWriting)
{
Vector3 pos = transform.localPosition;
Quaternion rot = transform.localRotation;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
stream.Serialize(ref playerId);
int _st = (int)stoneType;
stream.Serialize(ref _st);
}
else
{
// Receive latest state information
Vector3 pos = Vector3.zero;
Quaternion rot = Quaternion.identity;
int _st = (int)stoneType;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
stream.Serialize(ref playerId);
stream.Serialize(ref _st);
latestCorrectPos = pos; // save this to move towards it in FixedUpdate()
onUpdatePos = transform.localPosition; // we interpolate from here to latestCorrectPos
fraction = 0; // reset the fraction we alreay moved. see Update()
transform.localRotation = rot; // this sample doesn't smooth rotation
stoneType = (StoneType)_st;
}
}
示例3: OnPhotonSerializeView
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
Vector3 pos = transform.localPosition;
Quaternion rot = transform.localRotation;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
}
else
{
// Receive latest state information
Vector3 pos = Vector3.zero;
Quaternion rot = Quaternion.identity;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
this.latestCorrectPos = pos; // save this to move towards it in FixedUpdate()
this.onUpdatePos = transform.localPosition; // we interpolate from here to latestCorrectPos
this.fraction = 0; // reset the fraction we alreay moved. see Update()
transform.localRotation = rot; // this sample doesn't smooth rotation
}
}
示例4: OnPhotonSerializeView
// this method is called by PUN when this script is being "observed" by a PhotonView (setup in inspector)
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
// Always send transform (depending on reliability of the network view)
if (stream.isWriting)
{
Vector3 pos = transform.localPosition;
Quaternion rot = transform.localRotation;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
}
// When receiving, buffer the information
else
{
// Receive latest state information
Vector3 pos = Vector3.zero;
Quaternion rot = Quaternion.identity;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
lastMovement = (pos - latestCorrectPos) / (Time.time - lastTime);
lastTime = Time.time;
latestCorrectPos = pos;
transform.position = latestCorrectPos;
}
}
示例5: OnPhotonSerializeView
// this method is called by PUN when this script is being "observed" by a PhotonView (setup in inspector)
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
// the controlling player of a cube sends only the position
Vector3 pos = transform.localPosition;
stream.Serialize(ref pos);
}
else
{
// other players (not controlling this cube) will read the position and timing and calculate everything else based on this
Vector3 updatedLocalPos = Vector3.zero;
stream.Serialize(ref updatedLocalPos);
double timeDiffOfUpdates = info.timestamp - this.lastTime; // the time that passed after the sender sent it's previous update
this.lastTime = info.timestamp;
// the movementVector calculates how far the "original" cube moved since it sent the last update.
// we calculate this based on the sender's timing, so we exclude network lag. that makes our movement smoother.
this.movementVector = (updatedLocalPos - this.latestCorrectPos) / (float)timeDiffOfUpdates;
// the errorVector is how far our cube is away from the incoming position update. using this corrects errors somewhat, until the next update arrives.
// with this, we don't have to correct our cube's position with a new update (which introduces visible, hard stuttering).
this.errorVector = (updatedLocalPos - transform.localPosition) / (float)timeDiffOfUpdates;
// next time we get an update, we need this update's position:
this.latestCorrectPos = updatedLocalPos;
}
}
示例6: OnPhotonSerializeView
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
// Send data to server
if (stream.isWriting)
{
Vector3 pos = transform.position;
Quaternion rot = transform.rotation;
//Vector3 velocity = Vector3.zero; //rigidbody.velocity;
//Vector3 angularVelocity = Vector3.zero; // rigidbody.angularVelocity;
stream.Serialize(ref pos);
//stream.Serialize(ref velocity);
stream.Serialize(ref rot);
//stream.Serialize(ref angularVelocity);
}
// Read data from remote client
else
{
Vector3 pos = Vector3.zero;
Vector3 velocity = Vector3.zero;
Quaternion rot = Quaternion.identity;
Vector3 angularVelocity = Vector3.zero;
stream.Serialize(ref pos);
//stream.Serialize(ref velocity);
stream.Serialize(ref rot);
//stream.Serialize(ref angularVelocity);
// Shift the buffer sideways, deleting state 20
for (int i=m_BufferedState.Length-1;i>=1;i--)
{
m_BufferedState[i] = m_BufferedState[i-1];
}
// Record current state in slot 0
State state;
state.timestamp = info.timestamp;
state.pos = pos;
state.velocity = velocity;
state.rot = rot;
state.angularVelocity = angularVelocity;
m_BufferedState[0] = state;
// Update used slot count, however never exceed the buffer size
// Slots aren't actually freed so this just makes sure the buffer is
// filled up and that uninitalized slots aren't used.
m_TimestampCount = Mathf.Min(m_TimestampCount + 1, m_BufferedState.Length);
// Check if states are in order, if it is inconsistent you could reshuffel or
// drop the out-of-order state. Nothing is done here
for (int i=0;i<m_TimestampCount-1;i++)
{
if (m_BufferedState[i].timestamp < m_BufferedState[i+1].timestamp)
Debug.Log("State inconsistent");
}
}
}
示例7: OnPhotonSerializeView
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
Vector3 pos = transform.localPosition;
Quaternion rot = transform.localRotation;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
if(anim != null)
{
float zVel = anim.GetFloat("Z_Vel");
float xVel = anim.GetFloat("X_Vel");
bool jumping = anim.GetBool("Jumping");
stream.Serialize(ref zVel);
stream.Serialize(ref xVel);
stream.Serialize(ref jumping);
}
}
else
{
// Receive latest state information
Vector3 pos = Vector3.zero;
Quaternion rot = Quaternion.identity;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
if(anim != null)
{
float zVel = 0;
float xVel = 0;
bool jumping = false;
stream.Serialize(ref zVel);
stream.Serialize(ref xVel);
stream.Serialize(ref jumping);
anim.SetFloat("Z_Vel",zVel);
anim.SetFloat("X_Vel",xVel);
anim.SetBool("Jumping",jumping);
}
latestCorrectPos = pos; // save this to move towards it in Update()
onUpdatePos = transform.localPosition; // we interpolate from here to latestCorrectPos
latestCorrectRot = rot; // same with rotation
onUpdateRot = transform.localRotation;
fraction = 0; // reset the fraction we alreay moved. see Update()
if(firstUpdate)
{
transform.localPosition = pos;
transform.localRotation = rot;
firstUpdate = false;
}
}
}
示例8: OnPhotonSerializeView
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.Serialize(ref Kappa);
}
else
{
stream.Serialize(ref Kappa);
}
}
示例9: OnPhotonSerializeView
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
Vector3 pos = transform.position;
Quaternion rot = transform.rotation;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
if (stream.isReading)
{
transform.position = pos;
transform.rotation = rot;
}
}
示例10: OnPhotonSerializeView
private void OnPhotonSerializeView(PhotonStream Stream, PhotonMessageInfo Info)
{
// Send data to server
if (Stream.isWriting)
{
// Not sending data when in slow-motion or fast-motion.
if (Time.timeScale != NormalTimeScale)
return;
var Position = rigidbody.position;
var Rotation = rigidbody.rotation;
var Velocity = rigidbody.velocity;
var AngularVelocity = rigidbody.angularVelocity;
Stream.Serialize(ref Position);
Stream.Serialize(ref Velocity);
Stream.Serialize(ref Rotation);
Stream.Serialize(ref AngularVelocity);
}
// Read data from remote client
else
{
var Position = Vector3.zero;
var Velocity = Vector3.zero;
var Rotation = Quaternion.identity;
var AngularVelocity = Vector3.zero;
Stream.Serialize(ref Position);
Stream.Serialize(ref Velocity);
Stream.Serialize(ref Rotation);
Stream.Serialize(ref AngularVelocity);
// Shift the buffer sideways, deleting the last state.
for (var i = BufferedStates.Length - 1; i >= 1; i--)
BufferedStates[i] = BufferedStates[i - 1];
// Record current state in slot 0
BufferedStates[0] = new RigidBodyState(Info.timestamp, Position, Velocity, Rotation, AngularVelocity);
// Update used slot count, however never exceed the buffer size
// Slots aren't actually freed so this just makes sure the buffer is
// filled up and that uninitalized slots aren't used.
UsedBufferedStatesCount = Mathf.Min(UsedBufferedStatesCount + 1, BufferedStates.Length);
// Check if states are in order, if it is inconsistent you could reshuffel or
// drop the out-of-order state. Nothing is done here
for (var i = 0; i < UsedBufferedStatesCount - 1; i++)
{
if (BufferedStates[i].Timestamp < BufferedStates[i + 1].Timestamp)
Debug.Log("State inconsistent");
}
}
}
示例11: OnPhotonSerializeView
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
Vector3 pos = transform.localPosition;
stream.Serialize(ref pos);
}
else
{
Vector3 pos = Vector3.zero;
stream.Serialize(ref pos);
}
}
示例12: OnPhotonSerializeView
// in an "observed" script:
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
Vector3 pos = this.transform.localPosition;
stream.Serialize(ref pos);
}
else
{
Vector3 pos = Vector3.zero;
stream.Serialize(ref pos); // pos gets filled-in. must be used somewhere
}
}
示例13: OnPhotonSerializeView
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
// Always send transform (depending on reliability of the network view)
if (stream.isWriting)
{
Vector3 pos = transform.localPosition;
Quaternion rot = transform.localRotation;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
stream.SendNext(Environment.TickCount);
}
// When receiving, buffer the information
else
{
// Receive latest state information
Vector3 pos = Vector3.zero;
Quaternion rot = Quaternion.identity;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
int localTimeOfSend = (int)stream.ReceiveNext();
//Debug.Log("timeDiff" + (Environment.TickCount - localTimeOfSend) + " update age: " + (PhotonNetwork.time - info.timestamp));
// Shift buffer contents, oldest data erased, 18 becomes 19, ... , 0 becomes 1
for (int i = this.m_BufferedState.Length - 1; i >= 1; i--)
{
this.m_BufferedState[i] = this.m_BufferedState[i - 1];
}
// Save currect received state as 0 in the buffer, safe to overwrite after shifting
State state;
state.timestamp = info.timestamp;
state.pos = pos;
state.rot = rot;
this.m_BufferedState[0] = state;
// Increment state count but never exceed buffer size
this.m_TimestampCount = Mathf.Min(this.m_TimestampCount + 1, this.m_BufferedState.Length);
// Check integrity, lowest numbered state in the buffer is newest and so on
for (int i = 0; i < this.m_TimestampCount - 1; i++)
{
if (this.m_BufferedState[i].timestamp < this.m_BufferedState[i + 1].timestamp)
{
Debug.Log("State inconsistent");
}
}
}
}
示例14: OnPhotonSerializeView
/// <summary>
/// While script is observed (in a PhotonView), this is called by PUN with a stream to write or read.
/// </summary>
/// <remarks>
/// The property stream.isWriting is true for the owner of a PhotonView. This is the only client that
/// should write into the stream. Others will receive the content written by the owner and can read it.
///
/// Note: Send only what you actually want to consume/use, too!
/// Note: If the owner doesn't write something into the stream, PUN won't send anything.
/// </remarks>
/// <param name="stream">Read or write stream to pass state of this GameObject (or whatever else).</param>
/// <param name="info">Some info about the sender of this stream, who is the owner of this PhotonView (and GameObject).</param>
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
Vector3 pos = transform.localPosition;
Quaternion rot = transform.rotation;
int hlth = health;
//ItemType itmType = itemType;
float rspwnTime = respawnTime;
float rspwnStrt = respawnStart;
int st = (int)state;
float dsbleTime = disableTime;
int tm = (int)team;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
stream.Serialize(ref hlth);
stream.Serialize(ref rspwnTime);
stream.Serialize(ref rspwnStrt);
stream.Serialize(ref st);
stream.Serialize(ref dsbleTime);
stream.Serialize(ref tm);
}
else
{
// Receive latest state information
Vector3 pos = Vector3.zero;
Quaternion rot = Quaternion.identity;
int hlth = 0;
float rspwnTime = 0;
float rspwnStrt = 0;
int st = 0;
float dsbleTime = 0;
int tm = 0;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
stream.Serialize(ref hlth);
stream.Serialize(ref rspwnTime);
stream.Serialize(ref rspwnStrt);
stream.Serialize(ref st);
stream.Serialize(ref dsbleTime);
stream.Serialize(ref tm);
transform.position = pos;
transform.rotation = rot; // this sample doesn't smooth rotation
health = hlth;
respawnTime = rspwnTime;
respawnStart = rspwnStrt;
state = (ItemState)st;
disableTime = dsbleTime;
team = (Team)tm;
}
}
示例15: OnPhotonSerializeView
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
networkCulling.SetGroup(photonView);
Vector3 pos = transform.position;
Quaternion rot = transform.rotation;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
}
else
{
Vector3 pos = transform.position;
Quaternion rot = transform.rotation;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
SetPositionRotation(pos,rot); //Your own synchronization code (or just directly set the position/rotation for now)
}
}