Exemplo n.º 1
0
    public UserData InitLocalUser(int ID, string name, string address, int localPort, bool isMe, UserRole userRole)
    {
        if (userRole == UserRole.Player)
        {
            _userGameObject = Instantiate(playerPrefab);
        }
        else if (userRole == UserRole.Tracker)
        {
            _userGameObject = Instantiate(trackerPrefab);
        }
        else if (userRole == UserRole.Viewer || userRole == UserRole.Server ||
                 (userRole == UserRole.Playback && gameEngine.playbackManager.mode == PlaybackMode.Offline)) // offline playback is considered as a normal viewer
        {
            _userGameObject = Instantiate(viewerPrefab);
        }
        else if (userRole == UserRole.Playback && gameEngine.playbackManager.mode == PlaybackMode.Online)
        {
            _userGameObject = Instantiate(playerPrefab);
            _userGameObject.AddComponent <ViewerController>();
        }

        if (userRole == UserRole.Viewer || userRole == UserRole.Tracker || userRole == UserRole.Server || userRole == UserRole.Playback)
        {
            viewerController = _userGameObject.GetComponent <ViewerController>();
            viewerController.InitViewerController(isMe);
        }

        UserData user = _userGameObject.GetComponent <UserData>();

        //int rank;

        //if(userRole == UserRole.Playback && gameEngine.playbackManager.mode == PlaybackMode.Offline) rank = -1;
        //else rank = CountPlayers();

        user.InitUserData(ID, name, address, localPort, _userGameObject, isMe, playerNameVisible, userRole, gameEngine.vrRigPrefab, gameEngine.useVRHeadset);

        if (userRole != UserRole.Server)
        {
            usersPlaying.Add(user);
            if (userRole == UserRole.Player)
            {
                StoreUserParts(user);
            }
            foreach (GameObject model in GameObject.FindGameObjectsWithTag("SteamModel"))
            {
                model.SetActive(false);
            }
        }

        // print names above head
        if (gameEngine._userRole == UserRole.Player || gameEngine.gameData.showNamesAboveHead == 0) // mask UI for players when not wanted
        {
            gameEngine.userManager.playerNameVisible = false;
        }
        else
        {
            gameEngine.userManager.playerNameVisible = true;
        }

        me = user;

        return(user);
    }