本文整理汇总了C#中PhotonMessageInfo类的典型用法代码示例。如果您正苦于以下问题:C# PhotonMessageInfo类的具体用法?C# PhotonMessageInfo怎么用?C# PhotonMessageInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PhotonMessageInfo类属于命名空间,在下文中一共展示了PhotonMessageInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnPhotonSerializeView
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if(stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
if(anim.IsPlaying("Run"))
{
stream.SendNext(useThisMove = 1);
}
if(anim.IsPlaying ("Idle"))
{
stream.SendNext (useThisMove = -1);
}
if(anim.IsPlaying ("AutoAttack"))
{
stream.SendNext(useThisMove = -2);
}
}
else
{
realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();
useThisMove = (int)stream.ReceiveNext();
}
}
示例2: OnPhotonSerializeView
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if(stream.isWriting) {
// This is our player. We need to send our actual position to the network.
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext(anim.GetFloat("Speed"));
stream.SendNext(anim.GetBool("Jumping"));
}
else {
// This is someone else's player. We need to reciece their position.
// Right now, "realPosition" holds the other person's position at the LAST frame.
// Instead of simply updating "realPosition" and continuing to lerp,
//we MAY want to set our transform.position to immediately to this old "realPosition"
//and then update realPosition
realPosition = (Vector3)stream.ReceiveNext ();
realRotation = (Quaternion)stream.ReceiveNext ();
anim.SetFloat ("Speed", (float)stream.ReceiveNext() );
anim.SetBool ("Jumping", (bool)stream.ReceiveNext() );
if(gotFirstUpdate == false) {
transform.position = realPosition;
transform.rotation = realRotation;
gotFirstUpdate = true;
}
}
}
示例3: OnPhotonSerializeView
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting == true)
{
if (this.m_SynchronizeVelocity == true)
{
stream.SendNext(this.m_Body.velocity);
}
if (this.m_SynchronizeAngularVelocity == true)
{
stream.SendNext(this.m_Body.angularVelocity);
}
}
else
{
if (this.m_SynchronizeVelocity == true)
{
this.m_Body.velocity = (Vector3)stream.ReceiveNext();
}
if (this.m_SynchronizeAngularVelocity == true)
{
this.m_Body.angularVelocity = (Vector3)stream.ReceiveNext();
}
}
}
示例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
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
//We own this player: send the others our data
// stream.SendNext((int)controllerScript._characterState);
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
//stream.SendNext(GetComponent<Rigidbody>().velocity);
}
else
{
//Network player, receive data
//controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
correctPlayerPos = (Vector3)stream.ReceiveNext();
correctPlayerRot = (Quaternion)stream.ReceiveNext();
//GetComponent<Rigidbody>().velocity = (Vector3)stream.ReceiveNext();
if (!appliedInitialUpdate)
{
appliedInitialUpdate = true;
transform.position = correctPlayerPos;
transform.rotation = correctPlayerRot;
//GetComponent<Rigidbody>().velocity = Vector3.zero;
}
}
}
示例6: 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
}
}
示例7: OnPhotonSerializeView
/// <summary>
/// Serializing the photon views
/// </summary>
/// <param name="stream"> the stream of information </param>
/// <param name="info"> information about the messages </param>
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
// if it's us tell them where we are, else it's everyone else telling use where they are
if (stream.isWriting)
{
// send pos stuff
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
// send animation stuff
stream.SendNext(Mathf.Abs(motor.movement.velocity.x));
stream.SendNext(motor.grounded);
// Input info
stream.SendNext(Input.GetButton("Jump"));
stream.SendNext(Input.GetButtonUp("Fire1"));
}
else
{
// recieve pos
realPos = (Vector3)stream.ReceiveNext();
realRot = (Quaternion)stream.ReceiveNext();
// receive anim info
velocity = (float)stream.ReceiveNext();
onGround = (bool)stream.ReceiveNext();
// Input info
jumping = (bool)stream.ReceiveNext();
shoot = (bool)stream.ReceiveNext();
}
}
示例8: OnPhotonSerializeView
//Serilize Data Across the network, we want everyone to know where they are
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
//Send to everyone else a local players variables to be synced and recieved by all other players on network
if (stream.isWriting)
{
//send to clients where we are
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext(health);
//Sync Animation States
}
else
{
//Get from clients where they are
//Write in the same order we read, if not writing we are reading.
realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();
health = (float)stream.ReceiveNext();
//Sync Animation States
}
}
示例9: OnPhotonSerializeView
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
// write time & position to stream
stream.SendNext(PhotonNetwork.time);
// send orientation
stream.SendNext((double)transform.rotation.eulerAngles.y); // get Y-rotation
}
else
{
// receive keyframe
double time = (double)stream.ReceiveNext();
double orientation = (double)stream.ReceiveNext();
if (m_OrientationKeyframesList == null) m_OrientationKeyframesList = new KeyframeList<double>();
m_OrientationKeyframesList.Add(time, orientation);
if (m_OrientationKeyframesList.Count > 2)
{
//Debug.Log("removing old keyframes");
// remove old keyframes ( let's say 5 seconds old? )
m_OrientationKeyframesList.RemoveAllBefore(time - 5);
}
}
}
示例10: OnPhotonSerializeView
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if(stream.isWriting) {
stream.SendNext(transform.position);
} else {
position = (Vector3)stream.ReceiveNext();
}
}
示例11: OnPhotonInstantiate
void OnPhotonInstantiate(PhotonMessageInfo msg)
{
// This is our own player
if (photonView.isMine)
{
//camera.main.enabled=false;
localPlayer = true;
Destroy(GameObject.Find("LevelCamera"));
Machinegun gun = transform.GetComponentInChildren < Machinegun>();
gun.localPlayer = true;
}
// This is just some remote controlled player, don't execute direct
// user input on this. DO enable multiplayer controll
else
{
name += msg.sender.name;
transform.Find("CrateCamera").gameObject.active = false;
FPSWalker4 tmp2 = GetComponent<FPSWalker4>() as FPSWalker4;
tmp2.enabled = false;
MouseLook tmp5 = GetComponent<MouseLook>() as MouseLook;
tmp5.enabled = false;
}
}
示例12: 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;
}
}
示例13: 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;
}
}
示例14: OnPhotonSerializeView
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if(stream.isWriting)
{
// this is my player. need to send my actual position to the network
stream.SendNext(transform.position);
stream.SendNext(_charController.velocity);
stream.SendNext(transform.rotation);
}
else
{
//this is another player. need to get his position data. then update my version of this player
Vector3 syncPosition = (Vector3)stream.ReceiveNext();
Vector3 syncVelocity = (Vector3)stream.ReceiveNext();
syncEndRotation = (Quaternion)stream.ReceiveNext();
syncStartRotation = transform.rotation;
syncTime = 0f;
syncDelay = Time.time - lastSynchronizationTime;
lastSynchronizationTime = Time.time;
syncEndPosition = syncPosition + syncVelocity * syncDelay;
syncStartPosition = transform.position;
}
}
示例15: OnPhotonSerializeView
public void OnPhotonSerializeView(PhotonStream aStream, PhotonMessageInfo aInfo)
{
if (aStream.isWriting)
{
aStream.SendNext(transform.position);
aStream.SendNext(transform.rotation.eulerAngles.z);
aStream.SendNext(m_health);
}
else
{
m_photonPosition = (Vector3)aStream.ReceiveNext();
m_photonRotation = (float)aStream.ReceiveNext();
m_health = (int)aStream.ReceiveNext();
stopWatch.Stop();
if (stopWatch.ElapsedMilliseconds > (1000 / PhotonNetwork.sendRate))
{
m_photonReleasedPositions.Add(new TimePosition(m_photonPosition, (float)stopWatch.ElapsedMilliseconds, m_photonRotation));
if (m_once && m_photonReleasedPositions.Count >= 4)
{
m_once = false;
StartCoroutine("ReleasePositions");
}
stopWatch.Reset();
}
stopWatch.Start();
}
}