本文整理汇总了C#中UnityEngine.NetworkMessageInfo类的典型用法代码示例。如果您正苦于以下问题:C# NetworkMessageInfo类的具体用法?C# NetworkMessageInfo怎么用?C# NetworkMessageInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetworkMessageInfo类属于UnityEngine命名空间,在下文中一共展示了NetworkMessageInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnNetworkInstantiate
void OnNetworkInstantiate(NetworkMessageInfo msg)
{
if (networkView.isMine)
{
this.enabled = false;
}
}
示例2: OnNetworkInstantiate
void OnNetworkInstantiate(NetworkMessageInfo info)
{
if (networkView.isMine)
{
// Disable interpolated transform, we control the movement on this client
GetComponent<NetworkInterpolatedTransform>().enabled = false;
}
else
{
name += "Remote";
if (_owner == Network.player)
{
// note; we should enable some prediction components here
GetComponent<NetworkInterpolatedTransform>().enabled = true;
rigidbody.useGravity = false;
collider.enabled = false;
}
else
{
GetComponent<NetworkInterpolatedTransform>().enabled = true;
rigidbody.useGravity = false;
collider.enabled = false;
}
}
// we will decide when the object is destroyed
autoDestroy = false;
}
示例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: OnNetworkInstantiate
void OnNetworkInstantiate(NetworkMessageInfo info)
{
Debug.Log("New object instantiated by " + info.sender);
string sender = info.sender.ToString();
if (!Network.isServer) {
if (!sender.Equals ("-1")) {
Debug.Log("healer instant cams = " + Camera.allCameras.Length);
for (int i = 0; i < Camera.allCameras.Length; i++) {
Debug.Log ("Camera[" + i + "] = " + Camera.allCameras[i]);
}
//Camera.allCameras[Camera.allCameras.Length - 1].enabled = false;
Camera.allCameras[1].enabled = false;
GameObject[] launchers = GameObject.FindGameObjectsWithTag("Launcher");
Debug.Log ("Number of launchers = " + launchers.Length);
launchers[launchers.Length - 1].SetActive(false);
} else {
Camera.allCameras[1].enabled = false;
}
}
/*Debug.Log("cams = " + Camera.allCameras.Length);
string sender = info.sender.ToString();
GameObject[] launchers = GameObject.FindGameObjectsWithTag("Launcher");
Debug.Log ("Number of launchers = " + launchers.Length);
if (!Network.isServer) {
if (sender.Equals ("-1")) {
Camera.allCameras[1].enabled = false;
Camera.allCameras[0].enabled = true;
} else {
Camera.allCameras[Camera.allCameras.Length-1].enabled = false;
launchers[launchers.Length - 1].SetActive(false);
}
}*/
}
示例5: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if (!stream.isWriting)
{
}
}
示例6: RecvHealth
public void RecvHealth(byte[] pckData, NetworkMessageInfo info)
{
//ServerCheck
S2C.SetStructureHealth pck = new S2C.SetStructureHealth();
pck.DeserializeFromBytes(pckData);
TileManager.Inst.Get(pck.m_ID).RecvHealth(pck);
}
示例7: GiveMeACart
void GiveMeACart(string cartModel, string ballModel, string characterModel, NetworkMessageInfo info)
{
// create new buggy for the new guy - his must be done on the server otherwise collisions wont work!
Vector3 spawnLocation = new Vector3(0,5,0);
Vector3 velocity = new Vector3(0,0,0);
// instantiate the prefabs
GameObject cartContainerObject = (Instantiate(Resources.Load(cartModel), spawnLocation, Quaternion.identity) as GameObject);
GameObject ballGameObject = Instantiate(Resources.Load(ballModel), spawnLocation + new Vector3(3,0,0), Quaternion.identity) as GameObject;
GameObject characterGameObject = Instantiate(Resources.Load(characterModel), spawnLocation + new Vector3(0,-1,0), Quaternion.identity) as GameObject;
GameObject cartGameObject = cartContainerObject.transform.FindChild ("buggy").gameObject;
// set buggy as characters parent
characterGameObject.transform.parent = cartGameObject.transform;
// create and set viewIDs
NetworkViewID cartViewIDTransform = Network.AllocateViewID();
NetworkView cgt = cartContainerObject.AddComponent("NetworkView") as NetworkView;
cgt.observed = cartContainerObject.transform;
cgt.viewID = cartViewIDTransform;
cgt.stateSynchronization = NetworkStateSynchronization.Unreliable;
NetworkViewID cartViewIDRigidbody = Network.AllocateViewID();
NetworkView cgr = cartGameObject.AddComponent("NetworkView") as NetworkView;
cgr.observed = cartGameObject.rigidbody;
cgr.viewID = cartViewIDRigidbody;
cgr.stateSynchronization = NetworkStateSynchronization.Unreliable;
NetworkViewID ballViewID = Network.AllocateViewID();
ballGameObject.networkView.viewID = ballViewID;
NetworkViewID characterViewID = Network.AllocateViewID();
characterGameObject.networkView.viewID = characterViewID;
// tell everyone else about it
networkView.RPC("SpawnPrefab", RPCMode.Others, cartViewIDTransform, spawnLocation, velocity, cartModel);
networkView.RPC("SpawnPrefab", RPCMode.Others, ballViewID, spawnLocation, velocity, ballModel);
networkView.RPC("SpawnPrefab", RPCMode.Others, characterViewID, spawnLocation, velocity, characterModel);
// tell all players this is a player and not some random objects
networkView.RPC("SpawnPlayer", RPCMode.Others, cartViewIDTransform, cartViewIDRigidbody, ballViewID, characterViewID, 0, info.sender);
// tell the player it's theirs
networkView.RPC("ThisOnesYours", info.sender, cartViewIDTransform, ballViewID, characterViewID);
// create a PlayerInfo for it
PlayerInfo newGuy = new PlayerInfo();
newGuy.cartModel = cartModel;
newGuy.cartContainerObject = cartContainerObject;
newGuy.cartGameObject = cartGameObject;
newGuy.cartViewIDTransform = cartViewIDTransform;
newGuy.cartViewIDRigidbody = cartViewIDRigidbody;
newGuy.ballModel = ballModel;
newGuy.ballGameObject = ballGameObject;
newGuy.ballViewID = ballViewID;
newGuy.characterModel = characterModel;
newGuy.characterGameObject = characterGameObject;
newGuy.characterViewID = characterViewID;
newGuy.currentMode = 0; // set them in buggy
newGuy.player = info.sender;
// add it to the lists
nvs.players.Add(newGuy);
}
示例8: 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);
}
}
示例9: 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;
}
}
示例10: ReceiveMessage
void ReceiveMessage(string message, NetworkMessageInfo netInfo)
{
//Debug.Log(message);
string tag = message.Split(':')[0];
string msg = message.Split(':')[1];
switch (tag)
{
case "Began":
gesture.Begin(float.Parse(msg.Split(',')[0]), float.Parse(msg.Split(',')[1]));
break;
case "Moved":
gesture.Move(float.Parse(msg.Split(',')[0]), float.Parse(msg.Split(',')[1]));
break;
case "Ended":
gesture.End(float.Parse(msg.Split(',')[0]), float.Parse(msg.Split(',')[1]));
break;
case "Choose Candidate":
lexicon.Accept(int.Parse(msg));
break;
case "Keyboard Size Msg":
lexicon.UpdateSizeMsg(msg);
break;
case "Delete":
//lexicon.Delete();
break;
default:
break;
}
}
示例11: 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;
}
}
}
示例12: 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;
}
}
示例13: 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
}
}
示例14: OnNetworkInstantiate
void OnNetworkInstantiate(NetworkMessageInfo info)
{
if(networkView.isMine)
{
StartCoroutine(DestroyAfter(duration));
}
}
示例15: OnSerializeNetworkView
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Vector3 syncPosition = Vector3.zero;
Quaternion rot = Quaternion.identity;
if (stream.isWriting)
{
syncPosition = transform.position;
rot = transform.rotation;
stream.Serialize(ref syncPosition);
stream.Serialize(ref rot);
}
else
{
stream.Serialize(ref syncPosition);
stream.Serialize(ref rot);
syncTime = 0f;
syncDelay = Time.time - lastSynchronizationTime;
lastSynchronizationTime = Time.time;
syncStartPosition = transform.position;
syncEndPosition = syncPosition;
qSrot = transform.rotation;
qErot = rot;
}
}