Ejemplo n.º 1
0
        public void OnPlayerLeft(NetworkRunner runner, PlayerRef player)
        {
            Util.Log($"{player.PlayerId} disconnected");

            StartCoroutine(PlayerModel.Get(player).Co_RemovePlayer());
            SetConnectionStatus(ConnectionStatus);
        }
Ejemplo n.º 2
0
        public void OnPlayerLeft(NetworkRunner runner, PlayerRef player)
        {
            Debug.Log("Player Left");
            _despawnPlayerCallback(runner, player);

            SetConnectionStatus(_status, "Player Left");
        }
Ejemplo n.º 3
0
        // Objects are despawned when a runner is shutdown <<-- 왜 안되지
        public void OnShutdown(NetworkRunner runner, ShutdownReason shutdownReason)
        {
            Util.Log($"OnShutDown {shutdownReason}");
            SetConnectionStatus(Enum.ConnectionStatus.Disconnected);

            (string status, string msg) = ShutdownReasonToHuman(shutdownReason);
            //TODO : UI에 뿌려줄거라면! status와 msg 이용하면 됨.

            for (int i = RoomPlayer.Players.Count - 1; i >= 0; i--)
            {
                RoomPlayer player = RoomPlayer.Players[i];
                StartCoroutine(player.Co_RemovePlayer());
            }
            for (int i = PlayerModel.Players.Count - 1; i >= 0; i--)
            {
                PlayerModel player = PlayerModel.Players[i];
                if (!player || !player.Object || player.Object.InputAuthority)
                {
                    continue;
                }
                StartCoroutine(player.Co_RemovePlayer());
            }

            if (_runner)
            {
                Destroy(_runner.gameObject);
            }

            _pool.ClearPools();

            _runner = null;
        }
Ejemplo n.º 4
0
 public void OnConnectFailed(NetworkRunner runner, NetAddress remoteAddress, NetConnectFailedReason reason)
 {
     Util.Log($"Connect Failed {reason}");
     LeaveSession();
     SetConnectionStatus(Enum.ConnectionStatus.Failed);
     (string status, string msg) = ConnectFailedReasonToHuman(reason);
     //TODO : UI에 뿌려주자 status msg
 }
Ejemplo n.º 5
0
        public void OnPlayerJoined(NetworkRunner runner, PlayerRef player)
        {
            if (runner.IsServer)
            {
                Debug.Log("Hosted Mode - Spawning Player");
                InstantiatePlayer(runner, player);
            }
//			SetConnectionStatus(ConnectionStatus.Connected, "");
        }
Ejemplo n.º 6
0
 public void OnConnectedToServer(NetworkRunner runner)
 {
     Debug.Log("Connected to server");
     if (runner.GameMode == GameMode.Shared)
     {
         Debug.Log("Shared Mode - Spawning Player");
         InstantiatePlayer(runner, runner.LocalPlayer);
     }
     SetConnectionStatus(ConnectionStatus.Connected, "");
 }
Ejemplo n.º 7
0
 public void OnConnectedToServer(NetworkRunner runner)
 {
     if (_gameMode == GameMode.Shared)
     {
         var roomPlayer = runner.Spawn(NetworkManager.In.roomPlayerPrefab, Vector3.zero, Quaternion.identity, _runner.LocalPlayer);
         roomPlayer.GameState = RoomPlayer.EGameState.Lobby;
     }
     Util.Log("Connected to server", Enum.LogLevel.Network);
     SetConnectionStatus(Enum.ConnectionStatus.Connected);
 }
Ejemplo n.º 8
0
        private void InstantiatePlayer(NetworkRunner runner, PlayerRef playerref)
        {
            if (_spawnWorldCallback != null && (runner.IsServer || runner.IsSharedModeMasterClient))
            {
                _spawnWorldCallback(runner);
                _spawnWorldCallback = null;
            }

            _spawnPlayerCallback(runner, playerref);
        }
Ejemplo n.º 9
0
 public void OnConnectRequest(NetworkRunner runner, NetworkRunnerCallbackArgs.ConnectRequest request, byte[] token)
 {
     if (runner.CurrentScene > 0)
     {
         Util.Log($"Refused connection requested by {request.RemoteAddress}");
         request.Refuse();
     }
     else
     {
         request.Accept();
     }
 }
Ejemplo n.º 10
0
        public void OnShutdown(NetworkRunner runner, ShutdownReason shutdownReason)
        {
            Debug.Log("OnShutdown");
            string message = "";

            // switch (shutdownReason)
            // {
            //  case GameManager.ShutdownReason_GameAlreadyRunning:
            //      message = "Game in this room already started!";
            //      break;
            //  case ShutdownReason.IncompatibleConfiguration:
            //      message = "This room already exist in a different game mode!";
            //      break;
            //  case ShutdownReason.Ok:
            //      message = "User terminated network session!";
            //      break;
            //  case ShutdownReason.Error:
            //      message = "Unknown network error!";
            //      break;
            //  case ShutdownReason.ServerInRoom:
            //      message = "There is already a server/host in this room";
            //      break;
            //  case ShutdownReason.DisconnectedByPluginLogic:
            //      message = "The Photon server plugin terminated the network session!";
            //      break;
            //  default:
            //      message = shutdownReason.ToString();
            //      break;
            // }
            SetConnectionStatus(ConnectionStatus.Disconnected, message);

            // TODO: This cleanup should be handled by the ClearPools call below, but currently Fusion is not returning pooled objects on shutdown, so...
            // Destroy all NOs
            NetworkObject[] nos = FindObjectsOfType <NetworkObject>();
            for (int i = 0; i < nos.Length; i++)
            {
                Destroy(nos[i].gameObject);
            }

            // Clear all the player registries
            // TODO: This does not belong in here
            //PlayerManager.ResetPlayerManager();

            // Reset the object pools
            _pool.ClearPools();

            if (_runner != null && _runner.gameObject)
            {
                Destroy(_runner.gameObject);
            }
        }
 public void ReleaseInstance(NetworkRunner runner, NetworkObject no, bool isSceneObject)
 {
     Debug.Log($"Releasing {no} instance, isSceneObject={isSceneObject}");
     if (no != null)
     {
         FusionObjectPool pool;
         if (_poolsByInstance.TryGetValue(no, out pool))
         {
             pool.ReturnToPool(no);
             no.gameObject.SetActive(false);                     // Should always disable before re-parenting, or we will dirty it twice
             no.transform.SetParent(transform, false);
         }
         else
         {
             no.gameObject.SetActive(false);                     // Should always disable before re-parenting, or we will dirty it twice
             no.transform.SetParent(null, false);
             Destroy(no.gameObject);
         }
     }
 }
        public NetworkObject AcquireInstance(NetworkRunner runner, NetworkPrefabInfo info)
        {
            NetworkObject prefab;

            if (NetworkProjectConfig.Global.PrefabTable.TryGetPrefab(info.Prefab, out prefab))
            {
                FusionObjectPool pool = GetPool(prefab);
                NetworkObject    newt = pool.GetFromPool(Vector3.zero, Quaternion.identity);

                if (newt == null)
                {
                    newt = Instantiate(prefab, Vector3.zero, Quaternion.identity);
                    _poolsByInstance[newt] = pool;
                }

                newt.gameObject.SetActive(true);
                return(newt);
            }

            Debug.LogError("No prefab for " + info.Prefab);
            return(null);
        }
Ejemplo n.º 13
0
        public async void JoinOrCreateLobby()
        {
            SetConnectionStatus(Enum.ConnectionStatus.Connecting);

            if (_runner != null)
            {
                LeaveSession();
            }

            if (_runner == null)
            {
                Util.Log("runner 생성");
                GameObject session = new GameObject("Session");
                Util.Log($"{session.name}");
                _runner = session.AddComponent <NetworkRunner>();
            }

            _runner.ProvideInput = true;
            _runner.AddCallbacks(this);

            if (_pool == null)
            {
                _pool = gameObject.AddComponent <FusionObjectPoolRoot>();
            }

            RoomPlayer.Players.Clear();
            PlayerModel.Players.Clear();

            await _runner.StartGame(new StartGameArgs
            {
                GameMode            = _gameMode,
                SessionName         = NetworkManager.In.RoomName,
                ObjectPool          = _pool,
                PlayerCount         = Constants.MaxPlayer,
                SceneObjectProvider = this.GetOrAddComponent <NetworkSceneManagerDefault>() // 없어도 될 듯 싶으나 경고 디버그가 출력되어 추가해둠
            });
        }
Ejemplo n.º 14
0
        public async void Launch(GameMode mode, string room,
                                 INetworkSceneObjectProvider sceneLoader,
                                 Action <NetworkRunner, ConnectionStatus, string> onConnect,
                                 Action <NetworkRunner> onSpawnWorld,
                                 Action <NetworkRunner, PlayerRef> onSpawnPlayer,
                                 Action <NetworkRunner, PlayerRef> onDespawnPlayer)
        {
            _connectionCallback    = onConnect;
            _spawnWorldCallback    = onSpawnWorld;
            _spawnPlayerCallback   = onSpawnPlayer;
            _despawnPlayerCallback = onDespawnPlayer;

            SetConnectionStatus(ConnectionStatus.Connecting, "");

            DontDestroyOnLoad(gameObject);

            if (_runner == null)
            {
                _runner = gameObject.AddComponent <NetworkRunner>();
            }
            _runner.name         = name;
            _runner.ProvideInput = mode != GameMode.Server;

            if (_pool == null)
            {
                _pool = gameObject.AddComponent <FusionObjectPoolRoot>();
            }

            await _runner.StartGame(new StartGameArgs()
            {
                GameMode            = mode,
                SessionName         = room,
                ObjectPool          = _pool,
                SceneObjectProvider = sceneLoader
            });
        }
Ejemplo n.º 15
0
 public void OnSceneLoadDone(NetworkRunner runner)
 {
 }
Ejemplo n.º 16
0
 public void OnReliableDataReceived(NetworkRunner runner, PlayerRef player, ArraySegment <byte> data)
 {
 }
Ejemplo n.º 17
0
 public void OnHostMigration(NetworkRunner runner, HostMigrationToken hostMigrationToken)
 {
 }
Ejemplo n.º 18
0
 public void OnCustomAuthenticationResponse(NetworkRunner runner, Dictionary <string, object> data)
 {
 }
Ejemplo n.º 19
0
 public void OnSessionListUpdated(NetworkRunner runner, List <SessionInfo> sessionList)
 {
 }
Ejemplo n.º 20
0
 public void OnUserSimulationMessage(NetworkRunner runner, SimulationMessagePtr message)
 {
 }
Ejemplo n.º 21
0
 public void OnDisconnectedFromServer(NetworkRunner runner)
 {
     Debug.Log("Disconnected from server");
     SetConnectionStatus(ConnectionStatus.Disconnected, "");
 }
Ejemplo n.º 22
0
 public void OnInput(NetworkRunner runner, NetworkInput input)
 {
     //if (SceneManager.GetActiveScene().buildIndex < 1) return;
     //if (!PlayerManager.In.LocalPlayer) return;
 }
Ejemplo n.º 23
0
 public void OnConnectRequest(NetworkRunner runner, NetworkRunnerCallbackArgs.ConnectRequest request, byte[] token)
 {
     request.Accept();
 }
Ejemplo n.º 24
0
 public void OnConnectFailed(NetworkRunner runner, NetAddress remoteAddress, NetConnectFailedReason reason)
 {
     Debug.Log($"Connect failed {reason}");
     SetConnectionStatus(ConnectionStatus.Failed, reason.ToString());
 }
Ejemplo n.º 25
0
 public void OnDisconnectedFromServer(NetworkRunner runner)
 {
 }
Ejemplo n.º 26
0
 public void OnInput(NetworkRunner runner, NetworkInput input)
 {
 }
Ejemplo n.º 27
0
 public void OnSceneLoadStart(NetworkRunner runner)
 {
 }
Ejemplo n.º 28
0
 public void OnInputMissing(NetworkRunner runner, PlayerRef player, NetworkInput input)
 {
 }
Ejemplo n.º 29
0
        //InetworkRunner Interface 구현부
        #region INetworkRunnerCallbacks Method

        public void OnPlayerJoined(NetworkRunner runner, PlayerRef player)
        {
            Util.Log("OnPlayerJoined");
            Util.Log(player.PlayerId.ToString(), Enum.LogLevel.Network);
        }