本文整理汇总了C#中UnityEngine.BitStream类的典型用法代码示例。如果您正苦于以下问题:C# BitStream类的具体用法?C# BitStream怎么用?C# BitStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitStream类属于UnityEngine命名空间,在下文中一共展示了BitStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeSerialize
// assumes a reading stream
public void DeSerialize( BitStream stream )
{
int x = 0;
int y = 0;
stream.Serialize( ref x );
stream.Serialize( ref y );
this.x = x;
this.y = y;
}
示例2: Serialize
public static bool Serialize (BitStream stream, bool boolean)
// Serialize a bool to a BitStream
{
int integer = boolean ? 1 : 0;
stream.Serialize (ref integer);
return integer == 1;
}
示例3: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
float ping = 1.0F;
if (stream.isWriting) {
stream.Serialize(ref ping);
} else {
transitTime = (Network.time - info.timestamp)*1000;
stream.Serialize(ref ping);
}
}
示例4: OnSerializeNetworkView
public void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if(stream.isReading)
{
mRefreshRecSum++;
}
else
{
mRefreshSentSum++;
}
parent.SingleEndpoint_OnSerialize(stream, ConnectedUser);
}
示例5: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
int count = packets.Count;
if (stream.isWriting)
{
stream.Serialize(ref count);
while (packets.Count > 0)
{
VoiceChatPacket packet = packets.Dequeue();
stream.WritePacket(packet);
// If this packet is the same size as the sample size, we can return it
if (packet.Data.Length == VoiceChatSettings.Instance.SampleSize)
{
VoiceChatBytePool.Instance.Return(packet.Data);
}
}
}
else
{
if (Network.isServer)
{
stream.Serialize(ref count);
for (int i = 0; i < count; ++i)
{
packets.Enqueue(stream.ReadPacket());
if (Network.connections.Length < 2)
{
packets.Dequeue();
}
}
}
else
{
stream.Serialize(ref count);
for (int i = 0; i < count; ++i)
{
var packet = stream.ReadPacket();
if (player != null)
{
player.OnNewSample(packet);
}
}
}
}
}
示例6: OnSerializeNetworkView
protected void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo msg)
{
var time = 0;
//mID = (int) ID;
if (stream.isWriting)
{
stream.Serialize(ref DoubleMissileTime);
//stream.Serialize(ref mID);
}
else
{
stream.Serialize(ref time);
DoubleMissileTime = time;
//stream.Serialize(ref mID);
//ID = (PlayerIndex) mID;
}
}
示例7: OnSerializeNetworkView
private void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) {
// Serialize the position and color
if (stream.isWriting) {
Color color = _renderer.material.color;
stream.Serialize(ref color.r);
stream.Serialize(ref color.g);
stream.Serialize(ref color.b);
stream.Serialize(ref color.a);
} else {
Color color = Color.white;
stream.Serialize(ref color.r);
stream.Serialize(ref color.g);
stream.Serialize(ref color.b);
stream.Serialize(ref color.a);
_renderer.material.color = color;
}
_transformInterpolation.OnSerializeNetworkView(stream, info, _transform.position, _transform.rotation);
}
示例8: OnSerializeNetworkView
public void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info, Vector3 position, Quaternion rotation) {
// Always send transform (depending on reliability of the network view)
if (stream.isWriting) {
// When receiving, buffer the information
stream.Serialize(ref position);
stream.Serialize(ref rotation);
} else {
// Receive latest state information
position = Vector3.zero;
rotation = Quaternion.identity;
stream.Serialize(ref position);
stream.Serialize(ref rotation);
// Shift buffer contents, oldest data erased, 18 becomes 19, ... , 0 becomes 1
for (int i = _bufferedStates.Length - 1; i >= 1; i--) {
_bufferedStates[i] = _bufferedStates[i - 1];
}
// Save currect received state as 0 in the buffer, safe to overwrite after shifting
State state;
state.Timestamp = info.timestamp;
state.Position = position;
state.Rotation = rotation;
_bufferedStates[0] = state;
// Increment state count but never exceed buffer size
_timestampCount = Mathf.Min(_timestampCount + 1, _bufferedStates.Length);
// Check integrity, lowest numbered state in the buffer is newest and so on
for (int i = 0; i < _timestampCount - 1; i++) {
if (_bufferedStates[i].Timestamp < _bufferedStates[i + 1].Timestamp)
Debug.Log("State inconsistent");
}
_isReceivedFirstInfo = true;
// Debug.Log("stamp: " + info.Timestamp + "my time: " + Network.time + "delta: " + (Network.time - info.Timestamp));
}
}
示例9: INTERNAL_CALL_Serializen
private static extern void INTERNAL_CALL_Serializen(BitStream self, ref NetworkViewID viewID);
示例10: Serialize
// assumes a writing stream
public void Serialize( BitStream stream )
{
location.Serialize( stream );
offset.Serialize( stream );
}
示例11: Serialize
// assumes a writing stream
public void Serialize( BitStream stream )
{
int x = this.x;
int y = this.y;
stream.Serialize( ref x );
stream.Serialize( ref y );
}
示例12: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
LogTime("OnSerializeNetworkView");
CallScriptMethod("OnSerializeNetworkView");
}
示例13: OnSerializeNetworkView
/// <summary>Used to customize synchronization of variables in a script watched by a network view.</summary>
public virtual void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) { }
示例14: OnSerializeNetworkView
public void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
var vessel = GetComponent<Vessel>();
if (stream.isWriting)
{
var eccentricity = (float)vessel.orbit.eccentricity;
var semiMajorAxis = (float)vessel.orbit.semiMajorAxis;
var inclination = (float)vessel.orbit.inclination;
var lan = (float)vessel.orbit.LAN;
var argumentOfPeriapsis = (float)vessel.orbit.argumentOfPeriapsis;
var meanAnomalyAtEpoch = (float)vessel.orbit.meanAnomalyAtEpoch;
var epoch = (float)vessel.orbit.epoch;
var bodyId = FlightGlobals.Bodies.IndexOf(vessel.orbit.referenceBody);
stream.Serialize(ref eccentricity, float.Epsilon);
stream.Serialize(ref semiMajorAxis, float.Epsilon);
stream.Serialize(ref inclination, float.Epsilon);
stream.Serialize(ref lan, float.Epsilon);
stream.Serialize(ref argumentOfPeriapsis, float.Epsilon);
stream.Serialize(ref meanAnomalyAtEpoch, float.Epsilon);
stream.Serialize(ref epoch, float.Epsilon);
stream.Serialize(ref bodyId);
}
else
{
float eccentricity = 0f, semiMajorAxis = 0f, inclination = 0f, lan = 0f, argumentOfPeriapsis = 0f;
var meanAnomalyAtEpoch = 0f;
var epoch = 0f;
var bodyId = 0;
stream.Serialize(ref eccentricity, float.Epsilon);
stream.Serialize(ref semiMajorAxis, float.Epsilon);
stream.Serialize(ref inclination, float.Epsilon);
stream.Serialize(ref lan, float.Epsilon);
stream.Serialize(ref argumentOfPeriapsis, float.Epsilon);
stream.Serialize(ref meanAnomalyAtEpoch, float.Epsilon);
stream.Serialize(ref epoch, float.Epsilon);
stream.Serialize(ref bodyId);
var newOrbit = new Orbit(inclination, eccentricity, semiMajorAxis, lan, argumentOfPeriapsis, meanAnomalyAtEpoch, epoch, FlightGlobals.Bodies[bodyId]);
newOrbit.UpdateFromUT(Planetarium.GetUniversalTime());
if (vessel.packed)
{
if (vessel.Landed)
vessel.Landed = false;
if (vessel.Splashed)
vessel.Splashed = false;
vessel.orbit.UpdateFromOrbitAtUT(newOrbit, Planetarium.GetUniversalTime(), newOrbit.referenceBody);
}
else
{
vessel.SetPosition(newOrbit.pos);
vessel.SetWorldVelocity(newOrbit.vel);
}
}
}
示例15: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
InvokeInManagers ("OnSerializeNetworkView", stream, info);
}