当前位置: 首页>>代码示例>>C#>>正文


C# NetworkViewID.ToString方法代码示例

本文整理汇总了C#中UnityEngine.NetworkViewID.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkViewID.ToString方法的具体用法?C# NetworkViewID.ToString怎么用?C# NetworkViewID.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.NetworkViewID的用法示例。


在下文中一共展示了NetworkViewID.ToString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: JoinPlayer

    public void JoinPlayer(NetworkViewID newPlayerView, Vector3 pos, NetworkPlayer netPlayer)
    {
        if(netPlayer.ipAddress==LocalAddress)
        {
            Debug.Log("Server responded to my connection request, instantiating player " + newPlayerView.ToString());

            GameObject newPlayer = Instantiate(LocalPlayerPrefab, pos, Quaternion.identity) as GameObject;
            newPlayer.GetComponent<NetworkView>().viewID = newPlayerView;
            newPlayer.tag = "Player";
            newPlayer.name = "Player " + newPlayerView.ToString();

            newPlayer.GetComponent<playerController>().isLocalPlayer = true;
            newPlayer.GetComponent<playerController>().target = pos;
            newPlayer.GetComponent<playerController>().netPlayer = netPlayer;

            // populate a data structure with player information

            players.Add(new Player(netPlayer, newPlayer, newPlayerView));

            // set the global PlayerObject as a convenience variable
            // to easily find the local player GameObject to send position updates

            PlayerObject = newPlayer;

            // attach the main camera

            Camera.main.transform.position = PlayerObject.transform.position + new Vector3(0,1F,0);
            Camera.main.transform.parent = PlayerObject.transform;

            // provide the playerObject to all scripts on the world object

            gameObject.BroadcastMessage("SetLocalPlayerObject",PlayerObject,SendMessageOptions.DontRequireReceiver);

        } else {

            Debug.Log("Another player connected: " + newPlayerView.ToString());

            GameObject newPlayer = Instantiate(RemotePlayerPrefab, pos, Quaternion.identity) as GameObject;
            newPlayer.GetComponent<NetworkView>().viewID = newPlayerView;
            newPlayer.tag = "Player";
            newPlayer.name = "Player " + newPlayerView.ToString();

            // because this in not the local player, deactivate the character controller

            newPlayer.GetComponent<CharacterController>().enabled = false;
            newPlayer.GetComponent<playerController>().isLocalPlayer = false;
            newPlayer.GetComponent<playerController>().target = pos;
            newPlayer.GetComponent<playerController>().netPlayer = netPlayer;

            // populate a data structure with player information

            players.Add(new Player(netPlayer, newPlayer, newPlayerView));

        }
    }
开发者ID:bernarde-bgi,项目名称:bgirpsg,代码行数:55,代码来源:networkController.cs

示例2: JoinPlayer

    void JoinPlayer(NetworkViewID newPlayerView, Vector3 pos, NetworkPlayer p)
    {
        // instantiate the prefab
        // and set some of its properties

        GameObject newPlayer = Instantiate(playerPrefab, pos, Quaternion.identity) as GameObject;
        newPlayer.GetComponent<NetworkView>().viewID = newPlayerView;
        newPlayer.tag = "Player";

        // set the remote player's target to its current location
        // so that non-moving remote player don't move to the origin
        newPlayer.GetComponent<playerController>().target = pos;

        // most importantly, populate the NetworkPlayer
        // structure with the data received from the player
        // this will allow us to ignore updates from ourself

        newPlayer.GetComponent<playerController>().netPlayer = p;

        // the local GameObject for any player is unknown to
        // the server, so it can only send updates for NetworkPlayer
        // IDs - which we need to translate to a player's local
        // GameObject representation

        // to do this, we will add the player to the "players" Hashtable
        // for fast reverse-lookups for player updates
        // Hashtable structure is NetworkPlayer --> GameObject

        players.Add(p,newPlayer);

        if(Network.isClient)
        {
            if(p.ipAddress==LocalAddress)
            {
                Debug.Log("Server accepted my connection request, I am real player now: " + newPlayerView.ToString());

                // because this is the local player, activate the character controller

                newPlayer.GetComponent<CharacterController>().enabled = true;
                newPlayer.GetComponent<playerController>().isLocalPlayer = true;

                // also, set the global localPlayerObject as a convenience variable
                // to easily find the local player GameObject to send position updates

                localPlayerObject = newPlayer;

                // also, now put us into the "playing" GameState

                GameState = (int)state.playing;

                // and finally, attach the main camera to me

                Camera.main.transform.parent = newPlayer.transform;
                Camera.main.transform.localPosition = new Vector3(0,1,0);

            } else {

                Debug.Log("Another player connected: " + newPlayerView.ToString());

                // because this in not the local player, deactivate the character controller

                newPlayer.GetComponent<CharacterController>().enabled = false;
                newPlayer.GetComponent<playerController>().isLocalPlayer = false;
            }
        }
    }
开发者ID:Game-Group,项目名称:dog-fighter,代码行数:66,代码来源:networkController.cs

示例3: OnNetworkInstantiate

    // Use this for initialization
    void OnNetworkInstantiate(NetworkMessageInfo info)
    {
        thisPlayerColor = Color.black;
        ownedPrisms = new List<ManipulatableScript>();
        lookAT = new Vector3(0.0f, 0.0f, 1.0f);
        playerTransform = cameraTransform = this.transform;

        //deal with this when adding multiple player support
        //thisView = this.gameObject.GetComponent(typeof(NetworkView)) as NetworkView;
        netid = thisView.viewID;
        theID = netid.ToString();
        char[] space = {' '};
        int tempIndex = theID.IndexOfAny(space);
        theID = theID.Substring(tempIndex + 1);
        int tempID = int.Parse(theID);
        setID(tempID);
        //GameObject secondary = GameObject.FindGameObjectWithTag("Secondary");
        //secondaryTemplate = secondary.GetComponent(typeof(SecondaryProjectileScript)) as SecondaryProjectileScript;
        GameObject camera = GameObject.FindGameObjectWithTag("MainCamera");
        camera_script = camera.GetComponent(typeof(FPSKinectCameraScript)) as FPSKinectCameraScript;
    }
开发者ID:nickreynolds,项目名称:Senior-Project,代码行数:22,代码来源:PlayerScript.cs

示例4: LoginToServer

	void LoginToServer(string user, string pass, NetworkPlayer player, NetworkViewID id)
	{
		if(Network.isServer)
		{
			GameManager.NetMessage(user + " joined the game");
			//Logger.Write("Player " + player.ToString() + " : " + user + " - " +player.ipAddress + " trying to log in");
			
			//Loop through all connected players and send details.
			networkView.RPC("RandomMessage", player, "Sending players through");
			foreach(KeyValuePair<NetworkPlayer, GameObject> pair in Players)
			{
				if(pair.Key != player)
				{
					Debug.Log("Sending player data : " + pair.Value.ToString() + " to " + player.ToString() + " : " + id.ToString());
					networkView.RPC("SpawnPlayer", player, pair.Value.networkView.viewID, pair.Value.transform.position, PlayerNames[pair.Key]);
					//networkView.RPC("RandomMessage", player, pair.Value.networkView.viewID.ToString() + "being sent through");
					pair.Value.networkView.SetScope(player, true);
					pair.Value.networkView.RPC("ResetNetworkView", pair.Key);
				}
			}

			//Test for player
			//if(false)
			//	return;

			Players[player] = null;
			PlayerNames[player] = user;


			if(!LoadPlayerState(id,player))
			{
				SpawnPlayer(id, GetSpawnLocation(), user);
			}

			GameObject itemGO = ItemManager.CraftItem("WoodStick", player);
			Players[player].networkView.RPC("ItemAttach", player, itemGO.networkView.viewID);

			//Loop through all items
			int itemCount = 0;
			foreach(GameObject go in GameObject.FindGameObjectsWithTag("Item"))
			{
				Item item = (Item)go.GetComponent(typeof(Item));

				if(!item.IsOwned)
				{
					ItemManager.Instance.networkView.RPC("SpawnItemRPC", player, item.name, go.transform.position, go.networkView.viewID);
					item.VerifyItemWithServer(player);
					itemCount++;
				}
			}
			//GameManager.SendMessage("Sent " + itemCount + " itemSpawns to " + PlayerNames[player], true);

			//Loop through all AI
			networkView.RPC("RandomMessage", player, "Sending AI through");
			foreach(GameObject go in GameObject.FindGameObjectsWithTag("AI"))
			{
				go.networkView.SetScope(player, true);
				AIManager.Instance.SpawnEnemy(go, player);
			}
		}
	}
开发者ID:Blurift,项目名称:Instincts,代码行数:61,代码来源:NetworkManager.cs

示例5: RemotePlayerJoin

    private void RemotePlayerJoin(NetworkPlayer _NetClient, NetworkViewID _NetViewID)
    {
        Player joiningPlayer = new Player(_NetClient, _NetViewID, PlayerInputDevice.E_PlayerInputInvalid);
        m_Players.Add(joiningPlayer);

        Debug.Log("Remote player joined");
        Debug.Log("IP: "+ _NetClient.ipAddress + ", port:" + _NetClient.port + ", NetViewID: " + _NetViewID.ToString());
    }
开发者ID:mhoulier,项目名称:unity3d_template,代码行数:8,代码来源:PlayerManager.cs

示例6: LocalPlayerJoin

    private void LocalPlayerJoin(NetworkPlayer _NetClient, NetworkViewID _NetViewID)
    {
        Player joiningPlayer = null;
        foreach(Player pendingPlayer in m_PendingLocalPlayers)
        {
            if (pendingPlayer.m_NetViewID == _NetViewID)
            {
                System.Diagnostics.Debug.Assert(joiningPlayer.m_NetClient == _NetClient);

                joiningPlayer = pendingPlayer;
                break;
            }
        }
        System.Diagnostics.Debug.Assert(joiningPlayer != null);

        if (joiningPlayer != null)
        {
            m_Players.Add(joiningPlayer);
            m_PendingLocalPlayers.Remove(joiningPlayer);

            Debug.Log("Local player joined (input: " + joiningPlayer.m_LocalPlayerInput.ToString() + ")");
            Debug.Log("IP: "+ _NetClient.ipAddress + ", port:" + _NetClient.port + ", NetViewID: " + _NetViewID.ToString());
        }
        else
        {
            Debug.Log("Local player couldn't join: missing from the local players pending list!");
            Debug.Log("IP: "+ _NetClient.ipAddress + ", port:" + _NetClient.port + ", NetViewID: " + _NetViewID.ToString());
        }
    }
开发者ID:mhoulier,项目名称:unity3d_template,代码行数:29,代码来源:PlayerManager.cs

示例7: PlayerJoinAuthority

    public void PlayerJoinAuthority(NetworkPlayer _NetClient, NetworkViewID _NetViewID)
    {
        Debug.Log("Player join on Authority");
        Debug.Log("IP: "+ _NetClient.ipAddress + ", port:" + _NetClient.port + ", NetViewID: " + _NetViewID.ToString());

        //@TODO: any team balancing or sthg to do here?
        //Remove NPC AIs if needed?

        //@FIXME: handle case where server is full?

        //player join on server
        PlayerJoin(_NetClient, _NetViewID);

        //player join on clients
        networkView.RPC("PlayerJoin", RPCMode.Others, _NetClient, _NetViewID);
    }
开发者ID:mhoulier,项目名称:unity3d_template,代码行数:16,代码来源:PlayerManager.cs


注:本文中的UnityEngine.NetworkViewID.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。