コード例 #1
0
        public override void OnServerRemovePlayer(NetworkConnection conn, PlayerController player)
        {
            var playerControllerId = player.playerControllerId;

            NetworkLobbyPlayer oldLobbyPlayer = GetLobbyPlayer(conn);


            byte slot = oldLobbyPlayer.slot;

            _colourPool.releaseColour(oldLobbyPlayer.colour);
            Destroy(oldLobbyPlayer.gameObject);
            lobbySlots[slot] = null;
            base.OnServerRemovePlayer(conn, player);

            for (int i = 0; i < lobbySlots.Length; i++)
            {
                var lobbyPlayer = lobbySlots[i];
                if (lobbyPlayer != null)
                {
                    lobbyPlayer.GetComponent <NetworkLobbyPlayer>().readyToBegin = false;

                    s_LobbyReadyToBeginMessage.slotId     = lobbyPlayer.slot;
                    s_LobbyReadyToBeginMessage.readyState = false;
                    NetworkServer.SendToReady(null, MsgType.LobbyReadyToBegin, s_LobbyReadyToBeginMessage);
                }
            }

            OnLobbyServerPlayerRemoved(conn, playerControllerId);
        }
コード例 #2
0
    void Start()
    {
//		if (ClientSceneManager.Instance == null || ClientSceneManager.Instance.GetThisPlayerData () == null) {
//			Debug.LogWarning ("making up our own player data because this client's player data is null");
//			DisplayFinishPosition(new System.Random().Next(10));
//		} else {
//		DisplayFinishPosition (ClientSceneManager.Instance.GetThisPlayerData ().FinishPosition);
//		}

        NetworkCompat.NetworkLobbyPlayer thisLobbyPlayer = null;
        foreach (var lobbyPlayer in GameObject.FindObjectsOfType <NetworkCompat.NetworkLobbyPlayer> ())
        {
            if (lobbyPlayer.isLocalPlayer)
            {
                thisLobbyPlayer = lobbyPlayer;
                break;
            }
        }

        if (thisLobbyPlayer == null)
        {
            return;
        }

        DisplayFinishPosition(thisLobbyPlayer.lastGameResult.FinishPosition);
    }
コード例 #3
0
    private void GenerateImage()
    {
        GameObject prefab;

        NetworkCompat.NetworkLobbyPlayer thisLobbyPlayer = null;
        foreach (var lobbyPlayer in GameObject.FindObjectsOfType <NetworkCompat.NetworkLobbyPlayer> ())
        {
            if (lobbyPlayer.isLocalPlayer)
            {
                thisLobbyPlayer = lobbyPlayer;
                break;
            }
        }

        if (thisLobbyPlayer == null)
        {
            return;
        }

        int place = thisLobbyPlayer.lastGameResult.FinishPosition;

        switch (place)
        {
        case 0:
            prefab = FirstPlacePrefab;
            break;

        case 1:
            prefab = SecondPlacePrefab;
            break;

        case 2:
            prefab = ThirdPlacePrefab;
            break;

        default:
            prefab = RunnerUpPrefab;
            break;
        }
        foreach (Transform child in transform)
        {
            GameObject.Destroy(child.gameObject);
        }

        GameObject instantiatedObj = GameObject.Instantiate(prefab);
        Transform  name            = instantiatedObj.transform.Find("name");

        if (name != null)
        {
            Text textRenderer = name.gameObject.GetComponent <Text> ();
            textRenderer.text = thisLobbyPlayer.nickname;
        }

        instantiatedObj.transform.parent     = transform;
        instantiatedObj.transform.localScale = Vector3.one;
        instantiatedObj.GetComponent <RectTransform> ().localPosition = Vector3.zero;
    }
コード例 #4
0
        void OnValidate()
        {
            if (m_MaxPlayers <= 0)
            {
                m_MaxPlayers = 1;
            }

            if (m_MaxPlayersPerConnection <= 0)
            {
                m_MaxPlayersPerConnection = 1;
            }

            if (m_MaxPlayersPerConnection > maxPlayers)
            {
                m_MaxPlayersPerConnection = maxPlayers;
            }

            if (m_MinPlayers < 0)
            {
                m_MinPlayers = 0;
            }

            if (m_MinPlayers > m_MaxPlayers)
            {
                m_MinPlayers = m_MaxPlayers;
            }

            if (m_LobbyPlayerPrefab != null)
            {
                var uv = m_LobbyPlayerPrefab.GetComponent <NetworkIdentity>();
                if (uv == null)
                {
                    m_LobbyPlayerPrefab = null;
                    Debug.LogWarning("LobbyPlayer prefab must have a NetworkIdentity component.");
                }
            }

            if (m_GamePlayerPrefab != null)
            {
                var uv = m_GamePlayerPrefab.GetComponent <NetworkIdentity>();
                if (uv == null)
                {
                    m_GamePlayerPrefab = null;
                    Debug.LogWarning("GamePlayer prefab must have a NetworkIdentity component.");
                }
            }
        }
コード例 #5
0
    private void AddPlayerForPosition(NetworkCompat.NetworkLobbyPlayer player, int pos)
    {
        GameObject spawnPosition;
        RuntimeAnimatorController celebrationAnimation;

        switch (pos)
        {
        case 0:
            spawnPosition        = FirstPlaceSpawn;
            celebrationAnimation = AnimationController1stPlace;
            break;

        case 1:
            spawnPosition        = SecondPlaceSpawn;
            celebrationAnimation = AnimationController2ndPlace;
            break;

        case 2:
            spawnPosition        = ThirdPlaceSpawn;
            celebrationAnimation = AnimationController3rdPlace;
            break;

        default:
            return;
        }



        GameObject obj;

        if (player != null)
        {
            obj = Garage.InstantiateVehicle(Garage.CarType.MODEL, player.vehicleId, player.colour);
        }
        else
        {
            obj = Garage.InstantiateVehicle(Garage.CarType.MODEL, Garage.AvailableVehicles[0].Id, 320);
        }

        var animator = obj.transform.FindChild("Car_Model").gameObject.GetComponent <Animator> ();

        animator.runtimeAnimatorController = celebrationAnimation;

        obj.transform.localRotation *= Quaternion.AngleAxis(90, Vector3.up);
        obj.transform.SetParent(spawnPosition.transform, false);
    }
コード例 #6
0
        NetworkLobbyPlayer GetLobbyPlayer(NetworkConnection conn)
        {
            NetworkLobbyPlayer oldLobbyPlayer = null;

            foreach (var lobbyPlayer in lobbySlots)
            {
                if (lobbyPlayer == null)
                {
                    continue;
                }

                if (lobbyPlayer.serverId == conn.connectionId)
                {
                    oldLobbyPlayer = lobbyPlayer;
                }
            }
            return(oldLobbyPlayer);
        }
コード例 #7
0
    // I can't think of a better way of piping the evtn through right now...
    IEnumerator ApplyLobbyPlayerCarProperties()
    {
        NetworkCompat.NetworkLobbyPlayer player = ClientSceneManager.Instance.GetOwnLobbyPlayer();
        while (player == null)
        {
            player = ClientSceneManager.Instance.GetOwnLobbyPlayer();
            yield return(new WaitForSeconds(0.5f));
        }
        player.OnCarDetailsUpdateEvent += () => {
            NetworkCompat.NetworkLobbyPlayer newPlayer = ClientSceneManager.Instance.GetOwnLobbyPlayer();
            Debug.Log(string.Format("adding car shell for vehicle id: {0}", newPlayer.vehicleId));
            Garage.ApplyVehicleToShell(newPlayer.vehicleId, CarObject, newPlayer.colour);
        };

        Debug.Log(string.Format("adding initial car shell for vehicle id: {0}", player.vehicleId));
        Garage.ApplyVehicleToShell(player.vehicleId, CarObject, player.colour);

        while (true)
        {
            Debug.Log(string.Format("checking name: {0} vehicle id: {1}", ClientSceneManager.Instance.GetOwnLobbyPlayer().nickname, ClientSceneManager.Instance.GetOwnLobbyPlayer().vehicleId));
            yield return(new WaitForSeconds(5));
        }
    }
コード例 #8
0
    public override GameObject OnLobbyServerCreateGamePlayer(NetworkConnection conn, short playerControllerId)
    {
        NetworkCompat.NetworkLobbyPlayer thisLobbyPlayer = null;
        foreach (var lobbyPlayer in GameObject.FindObjectsOfType <NetworkCompat.NetworkLobbyPlayer>())
        {
            if (lobbyPlayer.connectionToClient.connectionId.Equals(conn.connectionId))
            {
                thisLobbyPlayer = lobbyPlayer;
                break;
            }
        }
        if (thisLobbyPlayer == null)
        {
            return(null);
        }



        var obj = (GameObject)Instantiate(gamePlayerPrefab, Vector3.zero, Quaternion.identity);



        var carController = obj.GetComponent <CarController> ();

        carController.ServerId = conn.connectionId;
        carController.Lifetime = carController.MaxLifetime = CalculatePlayerGameDuration();
        var carProperties = obj.GetComponent <CarProperties> ();

        carProperties.OriginalHue = thisLobbyPlayer.colour;

        if (OnLobbyClientGameLoadedEvent != null)
        {
            OnLobbyClientGameLoadedEvent(conn);
        }
        return(obj);
    }