本文整理汇总了C#中BitStream类的典型用法代码示例。如果您正苦于以下问题:C# BitStream类的具体用法?C# BitStream怎么用?C# BitStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitStream类属于命名空间,在下文中一共展示了BitStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
}
开发者ID:pmlamotte,项目名称:2Pac,代码行数:32,代码来源:BoardObject.cs
示例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;
}
}
开发者ID:rameshvarun,项目名称:FTMoba,代码行数:28,代码来源:CreepScript.cs
示例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;
}
}
开发者ID:Seraphli,项目名称:TheInsectersWar,代码行数:28,代码来源:Character2D.cs
示例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;
}
*/
}
}
开发者ID:vmohan7,项目名称:Assassins,代码行数:28,代码来源:AIPath.cs
示例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; // начальный поворот
}
}
开发者ID:NextGenIntelligence,项目名称:HabrahabrUnityMultiplayer,代码行数:31,代码来源:PlayerControls.cs
示例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;
}
}
}
开发者ID:ConnectDeveloper01,项目名称:dorumon,代码行数:26,代码来源:Zombie.cs
示例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;
}
}
}
开发者ID:etiens,项目名称:VikingQuest,代码行数:32,代码来源:ResyncPosition.cs
示例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);
}
}
}
开发者ID:hellsmith,项目名称:AnUn,代码行数:34,代码来源:PositionSyncScript.cs
示例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);
}
}
开发者ID:EternalWind,项目名称:Fighters,代码行数:27,代码来源:PlayerController.cs
示例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;
}
}
开发者ID:kyle1235,项目名称:Project_Flat,代码行数:30,代码来源:PlayerCombat.cs
示例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;
}
}
开发者ID:datnewb,项目名称:Kartus,代码行数:27,代码来源:CharacterAmmo.cs
示例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);
}
}
开发者ID:rdemaeye,项目名称:mergePractice,代码行数:31,代码来源:Predictor.cs
示例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;
}
}
开发者ID:BluBambu,项目名称:SkyArena,代码行数:25,代码来源:PlayerMovement.cs
示例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;
}
}
开发者ID:ZachHoefler,项目名称:pokeMMOn,代码行数:33,代码来源:Player.cs
示例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);
}
}
开发者ID:Final-Parsec,项目名称:TheVenomEvent,代码行数:28,代码来源:Predictor.cs
示例16: 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");
}
}
}
开发者ID:ConnectDeveloper01,项目名称:dorumon,代码行数:32,代码来源:NetworkInterpolatedTransform.cs
示例17: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Vector3 syncPosition = Vector3.zero;
if ((networkView.isMine) && stream.isWriting)
{
//Write data to stream
syncPosition = transform.position;
stream.Serialize(ref syncPosition);
print (gameObject.name);
}
else
{
//Get data from stream
stream.Serialize(ref syncPosition);
//Calculate sync delay (ping, kind of)
syncDelay = Time.time - lastSynchronizationTime;
lastSynchronizationTime = Time.time;
NetworkManager.changeMenuDebugStatus("syncDelay: "+syncDelay);
//Set new start and end position for movement interpolation
syncStartPosition = syncEndPosition;
syncEndPosition = syncPosition;
print (syncStartPosition);
print ("end: "+syncEndPosition);
}
}
开发者ID:Lowell92,项目名称:Yer_A_Wizard_Oculus,代码行数:27,代码来源:SyncPlayerB.cs
示例18: OnSerializeNetworkView
void OnSerializeNetworkView (BitStream stream, NetworkMessageInfo info)
{
if (stream.isWriting) {
//This is executed on the owner of the networkview
//The owner sends it's color over the network
//send color
Vector3 tempcolor = new Vector3(gameObject.GetComponent<Renderer>().material.color.r,gameObject.GetComponent<Renderer>().material.color.g,gameObject.GetComponent<Renderer>().material.color.b);
stream.Serialize (ref tempcolor);//"Encode" it, and send it
} else {
//Executed on all non-owners
//receive a color and set the object to it
//get color
Vector3 tempcolor = Vector3.zero;
Color colorReceive = Color.black;
stream.Serialize (ref tempcolor);
colorReceive = new Color(tempcolor.x, tempcolor.y, tempcolor.z, 1.0f);
//We've just recieved the current servers position of this object in 'posReceive'.
renderer.material.color = colorReceive;
//To reduce laggy movement a bit you could comment the line above and use position lerping below instead:
//transform.position = Vector3.Lerp(transform.position, posReceive, 0.9f); //"lerp" to the posReceive by 90%
//It would be even better to save the last received server position and lerp to it in Update because it is executed more often than OnSerializeNetworkView
}
}
开发者ID:mlakhal,项目名称:CollaborativeAugmentedRealityEnvironment,代码行数:31,代码来源:ColorPicker1_scripts.cs
示例19: OnSerializeNetworkView
//Sends or Recieves Serialized variables over the network.
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
//Variable to be used over the network.
Vector3 syncPosition = Vector3.zero;
//If you're the owner of the object you are sending the objects position over the network.
if(stream.isWriting)
{
//Set syncPosition to this objects current position.
syncPosition = transform.position;
//Send the position over the network.
stream.Serialize(ref syncPosition);
}
//You're recieving the position from the Owner.
else
{
//Serialize the new incoming position.
stream.Serialize(ref syncPosition);
syncTime = 0.0f;
syncDelay = Time.time - lastSyncTime;
lastSyncTime = Time.time;
syncStartPosition = transform.position;
syncEndPosition = syncPosition;
}
}
开发者ID:ToaLetan,项目名称:UnityNetTest,代码行数:28,代码来源:SyncPositionOverNetwork.cs
示例20: 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;
}
}
开发者ID:Midipil,项目名称:SansDessusDessous,代码行数:27,代码来源:NetworkEnemyController.cs
注:本文中的BitStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论