Пример #1
0
    private GameObject RemoteCreatePlayer(int playerIndex, NetworkViewID playerViewID, NetworkViewID pointerViewID)
    {
        // set the position based on the player index
        Vector3    initialLocation = m_playerSpawnTransforms[playerIndex].position;
        Quaternion initialRotation = m_playerSpawnTransforms[playerIndex].rotation;

        // create the player object
        GameObject player = Resources.Load("Player") as GameObject;

        player = Instantiate(player, initialLocation, initialRotation) as GameObject;

        // get the network view id from the player
        NetworkView playerNetworkView = player.GetComponent <NetworkView>();

        playerNetworkView.viewID = playerViewID;

        Wand playerWand = player.GetComponent <Wand>();
        PointerController pointerController  = playerWand.m_pointerController;
        NetworkView       pointerNetworkView = pointerController.gameObject.GetComponent <NetworkView>();

        pointerNetworkView.viewID = pointerViewID;

        // if the player is mine, connect it to the leap controller
        if (playerViewID.isMine)
        {
            m_leapManager.ConnectPlayer(player);
            m_camera.transform.position = m_cameraSpawnTransforms[playerIndex].position;
            m_camera.transform.rotation = m_cameraSpawnTransforms[playerIndex].rotation;
        }

        // save a local reference to the player
        m_players[playerIndex] = player;

        // set the color and the name
        VisualizationController visualizationController = player.GetComponent <VisualizationController>();

        visualizationController.InitializeColors(m_playerColors[playerIndex]);
        player.name = playerIndex == 0 ? "HostPlayer" : "ClientPlayer";


        // if the player is the second player, reverse the controlls (the camera is from the other direction)
        if (playerIndex == 1)
        {
            player.GetComponentInChildren <PointerController>().m_cameraFlipped = true;
        }

        return(player);
    }