當前位置: 首頁>>代碼示例>>C#>>正文


C# UnityEngine.NetworkMessageInfo類代碼示例

本文整理匯總了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;
     }
 }
開發者ID:silantzis,項目名稱:blockotron,代碼行數:7,代碼來源:NetworkInterpolatedTransform.cs

示例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;
    }
開發者ID:silantzis,項目名稱:blockotron,代碼行數:29,代碼來源:NetworkExplosive.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: 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);
            }
        }*/
    }
開發者ID:GJL91,項目名稱:Epidemic,代碼行數:34,代碼來源:moveHealer.cs

示例5: OnSerializeNetworkView

    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        if (!stream.isWriting)
        {

        }
    }
開發者ID:keaton-freude,項目名稱:UnityTowerDefense,代碼行數:7,代碼來源:WaypointMover.cs

示例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);
 }
開發者ID:rkdrnf,項目名稱:fortresswar,代碼行數:7,代碼來源:TileNetwork.cs

示例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);
    }
開發者ID:Ronnrein,項目名稱:bad-golf-community-edition,代碼行數:60,代碼來源:networkManagerServer.cs

示例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);
        }
    }
開發者ID:chrisscherer,項目名稱:ISGame,代碼行數:25,代碼來源:Predictor.cs

示例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;
        }
    }
開發者ID:Game-Group,項目名稱:dog-fighter,代碼行數:26,代碼來源:NetworkSync.cs

示例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;
     }
 }
開發者ID:coolyangzc,項目名稱:IndirectGestureKeyboard,代碼行數:29,代碼來源:Server.cs

示例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;
            }

        }
    }
開發者ID:rehabgame,項目名稱:fighton,代碼行數:33,代碼來源:Ball.cs

示例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;
        }
    }
開發者ID:Midipil,項目名稱:SansDessusDessous,代碼行數:27,代碼來源:NetworkEnemyController.cs

示例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
			
		}
	}
開發者ID:mlakhal,項目名稱:CollaborativeAugmentedRealityEnvironment,代碼行數:31,代碼來源:ColorPicker1_scripts.cs

示例14: OnNetworkInstantiate

 void OnNetworkInstantiate(NetworkMessageInfo info)
 {
     if(networkView.isMine)
     {
         StartCoroutine(DestroyAfter(duration));
     }
 }
開發者ID:Zatchmeister,項目名稱:Dias,代碼行數:7,代碼來源:BoxScript.cs

示例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;
        }
    }
開發者ID:Dankerprouduct,項目名稱:Derp-Bots,代碼行數:31,代碼來源:DevPerks.cs


注:本文中的UnityEngine.NetworkMessageInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。