本文整理汇总了C#中BitStream类的典型用法代码示例。如果您正苦于以下问题:C# BitStream类的具体用法?C# BitStream怎么用?C# BitStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BitStream类属于命名空间,在下文中一共展示了BitStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例2: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if(stream.isWriting) {
//Position Synchronization
Vector3 position = transform.position; stream.Serialize(ref position);
//Rotation Synchronization
Quaternion rotation = transform.rotation; stream.Serialize(ref rotation);
//Current Movement
Vector3 directionVector = motor.inputMoveDirection;
stream.Serialize(ref directionVector);
}
else {
//Position Synchronization
Vector3 position = Vector3.zero; stream.Serialize(ref position);
transform.position = position;
//Rotation synchronization
Quaternion rotation = Quaternion.identity; stream.Serialize(ref rotation);
transform.rotation = rotation;
//Current Movement
Vector3 directionVector = Vector3.zero;
stream.Serialize(ref directionVector);
motor.inputMoveDirection = directionVector;
}
}
示例3: OnSerializeNetworkView2D
public void OnSerializeNetworkView2D(BitStream stream, NetworkMessageInfo info,
UnitActionCommand pUnitActionCommand, bool pIsAlive)
{
Transform lTransform = characterController.transform;
Vector3 lData = Vector3.zero;
//---------------------------------------------------
if (stream.isWriting)
{
lData = lTransform.position;
lData.z = yVelocity;
}
//---------------------------------------------------
stream.Serialize(ref lData);
//---------------------------------------------------
if (stream.isReading)
{
yVelocity = lData.z;
lData.z = 0f;
lTransform.position = lData;
var lDeltaTime = (float)(Network.time - info.timestamp);
if (lDeltaTime > 0.02f)
update2D(pUnitActionCommand, UnitFace.getValue(pUnitActionCommand.face),
pIsAlive, lDeltaTime * Time.timeScale);
lastUpdateTime = Time.time;
}
}
示例4: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Vector3 syncDest = Vector3.zero;
Vector3 syncPos = Vector3.zero;
if (stream.isWriting && Network.isServer)
{
syncDest = destination;
syncPos = this.gameObject.transform.position;
stream.Serialize(ref syncDest);
stream.Serialize(ref syncPos);
}
else if (stream.isReading)
{
stream.Serialize(ref syncDest);
stream.Serialize(ref syncPos);
destination = syncDest;
if (agent != null)
agent.SetDestination (destination);
/*
Vector3 diffPos = this.gameObject.transform.position - syncPos;
if (diffPos.sqrMagnitude >= 1){
this.gameObject.transform.position = syncPos;
}
*/
}
}
示例5: OnSerializeNetworkView
void OnSerializeNetworkView( BitStream stream, NetworkMessageInfo info )
{
Vector3 syncPosition = Vector3.zero; // для синхронизации позиции
Vector3 syncVelocity = Vector3.zero; // для синхронизации действующей силы
Quaternion syncRotation = Quaternion.identity; // для синхронизации поворота
if ( stream.isWriting ) { // если отправляем в сеть то считываем данные обьекта и отправляем
syncPosition = rigidbody.position;
stream.Serialize( ref syncPosition );
syncPosition = rigidbody.velocity;
stream.Serialize( ref syncVelocity );
syncRotation = rigidbody.rotation;
stream.Serialize( ref syncRotation );
} else { // иначе считываем из сети
stream.Serialize( ref syncPosition );
stream.Serialize( ref syncVelocity );
stream.Serialize( ref syncRotation );
syncTime = 0f; // сбрасываем время синхронизации
syncDelay = Time.time - lastSynchronizationTime; // получаем дельту придыдущей синхронизации
lastSynchronizationTime = Time.time; // записываем новое время последней синхронизации
syncEndPosition = syncPosition + syncVelocity * syncDelay; // конечная точка в которую двигаеться обьект
syncStartPosition = rigidbody.position; // начальная точка равна текущей позиции
syncEndRotation = syncRotation; // конечный поворот
syncStartRotation = rigidbody.rotation; // начальный поворот
}
}
示例6: OnSerializeNetworkView
protected virtual void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if (selected == _PlayerOwn || stream.isReading)
{
if (stream.isWriting)
{
syncPos = pos;
syncRot = rot;
//syncVel = controller.velocity;
}
stream.Serialize(ref syncPos);
stream.Serialize(ref syncRot);
//stream.Serialize(ref syncVel);
if (stream.isReading)
{
if (syncPos == Vector3.zero)
{ }
else
{
pos = syncPos;
rot = syncRot;
}
//vel = syncVel;
}
}
}
示例7: OnSerializeNetworkView
// Update is called once per frame
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
{
Vector3 position = rigidbody.position;
Vector3 forward = transform.forward;
Vector3 velocity = rigidbody.velocity;
Vector3 angularVelocity = rigidbody.angularVelocity;
if(stream.isWriting)
{
stream.Serialize(ref position);
stream.Serialize(ref forward);
stream.Serialize(ref velocity);
stream.Serialize(ref angularVelocity);
}
else
{
stream.Serialize(ref position);
targetPosition = position;
stream.Serialize(ref forward);
targetForward = forward;
stream.Serialize(ref velocity);
speed = velocity;
stream.Serialize(ref angularVelocity);
angularSpeed = angularVelocity;
}
}
}
示例8: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Quaternion _syncDirection = Quaternion.identity;
Vector3 _syncPosition = Vector3.zero;
Vector3 _syncVelocity = Vector3.zero;
if (stream.isWriting)
{
_syncDirection = this.transform.rotation;
_syncPosition = this.transform.position;
_syncVelocity = this.rigidbody.velocity;
stream.Serialize(ref _syncDirection);
stream.Serialize(ref _syncPosition);
stream.Serialize(ref _syncVelocity);
}
else
{
stream.Serialize(ref _syncDirection);
stream.Serialize(ref _syncPosition);
stream.Serialize(ref _syncVelocity);
if(Quaternion.Angle(this.transform.rotation,_syncDirection) > 10 ){
this.gameObject.transform.rotation = Quaternion.Lerp(this.transform.rotation, _syncDirection,5 );
}
if( Vector3.Distance(this.transform.position,_syncPosition) > 10 ){
this.gameObject.transform.position = Vector3.Lerp(this.transform.position, _syncPosition,5);
}
if(Vector3.Distance(this.rigidbody.velocity,_syncVelocity)> 10){
this.rigidbody.velocity = Vector3.Lerp(this.rigidbody.velocity, _syncVelocity , 5);
}
}
}
示例9: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
var sync_pos = new Vector3();
var sync_rot = new Quaternion();
var sync_hp = 0.0f;
if (stream.isReading)
{
stream.Serialize(ref sync_pos);
stream.Serialize(ref sync_rot);
stream.Serialize(ref sync_hp);
transform.position = sync_pos;
transform.rotation = sync_rot;
m_CurrentHP = sync_hp;
}
else
{
sync_pos = transform.position;
sync_rot = transform.rotation;
sync_hp = m_CurrentHP;
stream.Serialize(ref sync_pos);
stream.Serialize(ref sync_rot);
stream.Serialize(ref sync_hp);
}
}
示例10: OnSerialNetworkView
public void OnSerialNetworkView(BitStream stream, NetworkMessageInfo info)
{
float punch = punchSpeed;
float direction = directionMultiplyerX;
float health = HP;
if (stream.isWriting)
{
punch = punchSpeed;
stream.Serialize(ref punch);
direction = directionMultiplyerX;
stream.Serialize(ref direction);
health = HP;
stream.Serialize(ref health);
}
else
{
stream.Serialize(ref punch);
punchSpeed = punch;
stream.Serialize(ref direction);
directionMultiplyerX = direction;
stream.Serialize(ref health);
HP = health;
}
}
示例11: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
float net_currentAmmo = 0;
float net_maxAmmo = 0;
float net_ammoRegenRate = 0;
if (stream.isWriting)
{
net_currentAmmo = currentAmmo;
net_maxAmmo = maxAmmo;
net_ammoRegenRate = ammoRegenRate;
stream.Serialize(ref net_currentAmmo);
stream.Serialize(ref net_maxAmmo);
stream.Serialize(ref net_ammoRegenRate);
}
else if (stream.isReading)
{
stream.Serialize(ref net_currentAmmo);
stream.Serialize(ref net_maxAmmo);
stream.Serialize(ref net_ammoRegenRate);
currentAmmo = net_currentAmmo;
maxAmmo = net_maxAmmo;
ammoRegenRate = net_ammoRegenRate;
}
}
示例12: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Vector3 pos = observedRigidbody.position;
Quaternion rot = observedRigidbody.rotation;
float vel = observedRigidbody.velocity.magnitude;
if(stream.isWriting)
{
stream.Serialize(ref pos);
stream.Serialize(ref rot);
stream.Serialize(ref vel);
}
else
{
stream.Serialize(ref pos);
stream.Serialize(ref rot);
stream.Serialize(ref vel);
receiver.serverPosition = pos;
receiver.serverRotation = rot;
receiver.serverVelocity = vel;
receiver.lerpToTarget();
for(int i = serverStateBuffer.Length - 1; i >= 1; i--)
{
serverStateBuffer[i] = serverStateBuffer[i-1];
}
serverStateBuffer[0] = new NetState(info.timestamp, pos, rot);
}
}
示例13: OnSerializeNetworkView
private void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Vector3 syncPosition = Vector3.zero;
Vector3 syncVelocity = Vector3.zero;
if (stream.isWriting)
{
syncPosition = transform.position;
stream.Serialize(ref syncPosition);
syncVelocity = _controller.velocity;
stream.Serialize(ref syncVelocity);
}
else
{
stream.Serialize(ref syncPosition);
stream.Serialize(ref syncVelocity);
_syncTime = 0f;
_syncDelay = Time.time - _lastSynchroTime;
_lastSynchroTime = Time.time;
_syncEndPosition = syncPosition + syncVelocity * _syncDelay;
_syncStartPosition = transform.position;
}
}
示例14: 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;
}
}
示例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);
}
}