本文整理汇总了C#中UnityEngine.BitStream.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# BitStream.Serialize方法的具体用法?C# BitStream.Serialize怎么用?C# BitStream.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.BitStream
的用法示例。
在下文中一共展示了BitStream.Serialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnSerializeNetworkView
public int playerIndex = 0; // Player index of driver who spawned fake item box
#endregion Fields
#region Methods
// Send data over network
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Vector3 position = Vector3.zero;
Vector3 forwardVector = Vector3.zero;
Vector3 upVector = Vector3.zero;
if (stream.isWriting)
{
// Sending data...
position = this.transform.position;
forwardVector = this.transform.forward;
upVector = this.transform.up;
stream.Serialize(ref position);
stream.Serialize(ref forwardVector);
stream.Serialize(ref upVector);
stream.Serialize(ref moveDirection);
stream.Serialize(ref this.playerIndex);
}
else
{
// Receiving data...
stream.Serialize(ref position);
stream.Serialize(ref forwardVector);
stream.Serialize(ref upVector);
this.transform.position = position;
this.transform.rotation = Quaternion.LookRotation(forwardVector, upVector);
stream.Serialize(ref moveDirection);
stream.Serialize(ref this.playerIndex);
}
}
示例2: OnSerializeNetworkView
//Rigidbody
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
var lIsKinematic = true;
var lPosition = Vector3.zero;
var lRot = Quaternion.identity;
if (stream.isWriting)
{
lPosition = transform.position;
lRot = transform.rotation;
lIsKinematic = rigidbody.isKinematic;
//lBoxPos = _supplyBox.transform.position;
}
stream.Serialize(ref lIsKinematic);
stream.Serialize(ref lPosition);
stream.Serialize(ref lRot);
//stream.Serialize(ref lBoxPos);
if (stream.isReading)
{
transform.position = lPosition;
transform.rotation = lRot;
rigidbody.isKinematic = lIsKinematic;
}
if(!lIsKinematic)
{
networkView.observed = rigidbody;
Destroy(this);
}
}
示例3: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
float net_currentHealth = 0;
float net_maxHealth = 0;
bool net_isTargeted = false;
if (stream.isWriting)
{
net_currentHealth = currentHealth;
net_maxHealth = maxHealth;
net_isTargeted = isTargeted;
stream.Serialize(ref net_currentHealth);
stream.Serialize(ref net_maxHealth);
stream.Serialize(ref net_isTargeted);
}
else if (stream.isReading)
{
stream.Serialize(ref net_currentHealth);
stream.Serialize(ref net_maxHealth);
stream.Serialize(ref net_isTargeted);
currentHealth = net_currentHealth;
maxHealth = net_maxHealth;
isTargeted = net_isTargeted;
}
}
示例4: OnSerializeNetworkView
private void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if (stream.isWriting)
{
Debug.Log("Writing.");
Vector3 pos = this.transform.position;
Vector3 orientation = this.transform.eulerAngles;
stream.Serialize(ref pos);
stream.Serialize(ref orientation);
}
else
{
Debug.Log("Receiving.");
Vector3 pos = Vector3.zero;
Vector3 orientation = Vector3.zero;
stream.Serialize(ref pos);
stream.Serialize(ref orientation);
this.transform.position = pos;
this.transform.eulerAngles = orientation;
}
}
示例5: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Vector3 syncPosition = Vector3.zero;
Vector3 syncVelocity = Vector3.zero;
if (stream.isWriting)
{
syncPosition = GetComponent<Rigidbody>().position;
stream.Serialize(ref syncPosition);
syncPosition = GetComponent<Rigidbody>().velocity;
stream.Serialize(ref syncVelocity);
//finPos = GetComponent<Rigidbody>().transform;
//Debug.Log("FinPos: " + finPos);
}
else
{
stream.Serialize(ref syncPosition);
stream.Serialize(ref syncVelocity);
syncTime = 0f;
syncDelay = Time.time - lastSynchronizationTime;
lastSynchronizationTime = Time.time;
syncEndPosition = syncPosition + syncVelocity * syncDelay;
syncStartPosition = GetComponent<Rigidbody>().position;
}
}
示例6: OnSerializeNetworkView
public void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Vector3 pos = observedTransform.position;
Quaternion rot = observedTransform.rotation;
if(stream.isWriting) {
stream.Serialize(ref pos);
stream.Serialize(ref rot);
}
else{
stream.Serialize(ref pos);
stream.Serialize(ref rot);
reciever.serverPos = pos;
reciever.serverRot = rot;
reciever.lerpToTarget();
for( int i = serverStateBuffer.Length - 1; i >= 1;i--){
serverStateBuffer[i] = serverStateBuffer[i-1];
}
serverStateBuffer[0] = new NetState();
serverStateBuffer[0].setState((float)info.timestamp, pos, rot);
}
}
示例7: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if (stream.isWriting)
{
// Vector3 pos = transform.position;
Quaternion rot = transform.rotation;
// int _animState = (int)animState;
// stream.Serialize(ref pos);
stream.Serialize(ref rot);
// stream.Serialize(ref _animState);
}
else
{
// Vector3 revPos = Vector3.zero;
Quaternion revRot = Quaternion.identity;
// int _animState = 0;
// stream.Serialize(ref revPos);
stream.Serialize(ref revRot);
// stream.Serialize(ref _animState);
// currPos = revPos;
currRot = revRot;
// animState = (AnimState)_animState;
}
}
示例8: OnSerializeNetworkView
/* This function is automatically called every time it sends or receives datas.
(To use for data that constantly changed) */
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Quaternion syncRotation = Quaternion.identity;
// The player is writing to the stream (= he moves its own Character...)
if (stream.isWriting)
{
syncRotation = transform.localRotation;
stream.Serialize(ref syncRotation);
}
// The ClientInstance of the player's opponent need to be moved
else
{
stream.Serialize(ref syncRotation);
// Interpolation : smoothing the transition from the old to the new data values
syncTime = 0f;
syncDelay = Time.time - lastSynchronizationTime;
lastSynchronizationTime = Time.time;
// Prediction : the rotation is "updated" before the new data is received
syncStartRotation = transform.localRotation;
syncEndRotation = syncRotation;
}
}
示例9: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
//locateMarkersAndLimbs();
Vector3 tempPos = Vector3.zero;
Quaternion tempRot = Quaternion.identity;
//ADD THE parentP2 changes here as well! To stop jitter!!
if((Network.isServer)&&(stream.isWriting))
{
if(!parentP1)
{
tempPos = transform.position;
tempRot = transform.rotation;
stream.Serialize(ref tempPos);
stream.Serialize(ref tempRot);
}
}
if(Network.isClient)
{
if(!parentP1)
{
stream.Serialize(ref tempPos);
stream.Serialize(ref tempRot);
transform.position = tempPos;
transform.rotation = tempRot;
}
}
}
示例10: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Vector3 syncPosition = Vector3.zero;
Quaternion syncRotation = Quaternion.identity;
Vector3 syncVelocity = Vector3.zero;
if (stream.isWriting)
{
syncPosition = transform.position;
stream.Serialize(ref syncPosition);
syncRotation = transform.rotation;
stream.Serialize(ref syncRotation);
syncVelocity = controller.velocity;
stream.Serialize(ref syncVelocity);
}
else
{
stream.Serialize(ref syncPosition);
stream.Serialize(ref syncRotation);
stream.Serialize(ref syncVelocity);
syncTime = 0f;
syncDelay = Time.time - lastSynchronizationTime;
lastSynchronizationTime = Time.time;
syncEndPosition = syncPosition + syncVelocity * syncDelay;
syncStartPosition = transform.position;
syncEndRotation = syncRotation;
syncStartRotation = transform.rotation;
}
}
示例11: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo 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);
for (int i = m_BufferedState.Length - 1; i >= 1; i--)
{
m_BufferedState[i] = m_BufferedState[i - 1];
}
State state;
state.timestamp = info.timestamp;
state.pos = pos;
state.rot = rot;
m_BufferedState[0] = state;
m_TimestampCount = Mathf.Min(m_TimestampCount + 1, m_BufferedState.Length);
for (int i = 0; i < m_TimestampCount - 1; i++)
{
if (m_BufferedState[i].timestamp < m_BufferedState[i + 1].timestamp)
Debug.Log("State inconsistent");
}
}
}
示例12: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
BoardLocation newLocation= new BoardLocation(new IntVector2(0,0), new IntVector2(0,0));
int maxSpeed = 0;
IntVector2 direction = new IntVector2(0,0);
BoardLocation lastBoardLocation = new BoardLocation(new IntVector2( 0, 0), new IntVector2(0,0));
if (stream.isWriting)
{
newLocation = this.boardLocation;
maxSpeed = this.maxSpeed;
direction = this.direction;
lastBoardLocation = this.lastBoardLocation;
newLocation.Serialize( stream );
stream.Serialize( ref maxSpeed );
direction.Serialize( stream );
lastBoardLocation.Serialize( stream );
}
else
{
newLocation.DeSerialize( stream );
stream.Serialize( ref maxSpeed );
direction.DeSerialize( stream );
lastBoardLocation.DeSerialize( stream );
this.boardLocation = newLocation;
this.maxSpeed = maxSpeed;
this.direction = direction;
this.lastBoardLocation = lastBoardLocation;
}
}
示例13: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if (initialized) {
Vector3 syncPosition = Vector3.zero;
Quaternion syncRotation = Quaternion.identity;
Vector3 syncVelocity = Vector3.zero;
float syncHealth = 0f;
if (stream.isWriting) {
syncPosition = transform.position;
syncRotation = transform.rotation;
syncVelocity = rigidbody.velocity;
syncHealth = playerDefense.health;
}
stream.Serialize(ref syncPosition);
stream.Serialize(ref syncRotation);
stream.Serialize(ref syncVelocity);
stream.Serialize(ref syncHealth);
if (stream.isReading) {
syncTime = 0f;
float currentTime = Time.time;
syncDelay = currentTime - lastSynchronizationTime;
lastSynchronizationTime = currentTime;
startSyncPosition = transform.position;
startSyncRotation = transform.rotation;
endSyncPosition = syncPosition + syncVelocity * syncDelay;
endSyncRotation = syncRotation;
this.syncHealth = syncHealth;
}
}
}
示例14: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Vector3 tempPos = Vector3.zero;
Quaternion tempRot = Quaternion.identity;
if((Network.isServer)&&(stream.isWriting))
{
//Debug.Log("Hellow");
tempPos = transform.position;
tempRot = transform.rotation;
stream.Serialize(ref tempPos);
stream.Serialize(ref tempRot);
}
else if(Network.isClient)
{
stream.Serialize(ref tempPos);
stream.Serialize(ref tempRot);
transform.position = tempPos;
transform.rotation = tempRot;
}
}
示例15: OnSerializeNetworkView
public void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Vector3 pos = observedTransform.position;
Quaternion rot = observedTransform.rotation;
if (stream.isWriting) {
//Debug.Log("Server is writing");
stream.Serialize(ref pos);
stream.Serialize(ref rot);
}
else {
//This code takes care of the local client!
stream.Serialize(ref pos);
stream.Serialize(ref rot);
receiver.serverPosition = pos;
receiver.serverRotation = rot;
//Smoothly correct clients position
//receiver.lerpToTarget();
//Take care of data for interpolating remote objects movements
// Shift up the buffer
for ( int i = serverStateBuffer.Length - 1; i >= 1; i-- ) {
serverStateBuffer[i] = serverStateBuffer[i-1];
}
//Override the first element with the latest server info
serverStateBuffer[0] = new NetworkState((float)info.timestamp, pos, rot);
}
}