コード例 #1
0
        CreateNew
            (NetworkedPlayerController controller)
        {
            MyContract.RequireArgumentNotNull(
                controller,
                "NetworkedPlayerController"
                );

            PlayerIdentifier ExtantId
                = controller
                  .gameObject
                  .GetComponent <PlayerIdentifier>();
            PlayerIdentifier NewId = ExtantId;

            if (ExtantId == null)
            {
                NewId = controller
                        .gameObject
                        .AddComponent <PlayerIdentifier>();
                NewId.SetBackingController(controller);
                Debug.Log(
                    "No existing PlayerIdentifier for "
                    + NewId.ToString()
                    + "\nCreating new PlayerIdentifier with net id "
                    + NewId.netId
                    );
            }
            return(NewId);
        }
コード例 #2
0
        CreateNew
            (NetworkInstanceId controllerNetworkId)
        {
            MyContract.RequireArgumentNotNull(
                controllerNetworkId,
                "controllerNetworkId"
                );

            GameObject PlayerControllerHost
                = NetworkServer.FindLocalObject(controllerNetworkId);

            MyContract.RequireArgumentNotNull(
                PlayerControllerHost,
                GameObjectNotPresentMessage
                );

            NetworkedPlayerController PlayerController
                = PlayerControllerHost
                  .GetComponent <NetworkedPlayerController>();

            MyContract.RequireArgumentNotNull(
                PlayerController,
                NPCNotPresentMessage
                );

            return(CreateNew(PlayerController));
        }
コード例 #3
0
 /// <summary>
 /// When the incorporeal player controller is created by the server
 /// (the main controller for networked interaction)
 ///
 /// N.B. Slightly hacky edge-case - I'm leaving deletion of these objects to the scene change
 /// (from online to offline scene)
 /// </summary>
 public void LocalPlayerControllerCreatedHandler(NetworkedPlayerController IPC)
 {
     Debug.Log("Local player object created");
     GenerateLocalScene(); // N.B. there are dependencies from here
     InitialisePlayerController(IPC);
     SetupGameCameras(PlayerController.transform);
     SetupInGameUI(IPC);
     PlayerController.CmdSpawnStartingSpaceShip(PlayerShipClassChoice);
 }
コード例 #4
0
        private void passthroughLocalPlayerStarted(NetworkedPlayerController IPC)
        {
            LocalPlayerStartHandler handler = LocalPlayerStarted;

            if (oem.shouldTriggerEvent(handler))
            {
                handler(IPC);
            }
        }
コード例 #5
0
        public string ToString()
        {
            if (PlayerID != null)
            {
                if (BackingController != null)
                {
                    return(StandardIdentifier());
                }
                else // can't use netid yet
                {
                    // try to recover
                    GameObject NPCHost;

                    // The following section is disgusting,
                    // but I can't tell why this is happening.
                    // I only pull the value after
                    // the local player controller is spawned
                    // (in NetworkedPlayerController.OnStartServer)
                    // so there's no reason why the gameobject
                    // should be null/unready.
                    //
                    // It looks (to me) like Unity's networking tries to
                    // instantiate this object with new rather than
                    // with AddComponent, so it becomes "headless".
                    // This is all undocumented behaviour,
                    // so I'm just going to try and avoid dealing with it.
                    try
                    {
                        NPCHost = gameObject;
                    }
                    catch (NullReferenceException nre)
                    {
                        Debug.LogWarning(NoGameObjectWarning);
                        NPCHost = NetworkServer.FindLocalObject(PlayerID);
                        if (NPCHost == null)
                        {
                            return(BackupIndentifier());
                        }
                    }
                    NetworkedPlayerController NPC
                        = NPCHost
                          .GetComponent <NetworkedPlayerController>();
                    MyContract.RequireFieldNotNull(
                        NPC,
                        "NetworkedPlayerController attached to the "
                        + "local object corresponding to NetworkInstanceId "
                        + PlayerID.ToString()
                        );
                    BackingController = NPC;
                    return(StandardIdentifier());
                }
            }
            else
            {
                return("Null" + PrintInitStatus());
            }
        }
コード例 #6
0
 SetBackingController
     (NetworkedPlayerController controller)
 {
     MyContract.RequireArgumentNotNull(
         controller,
         "Networked Player Controller"
         );
     BackingController = controller;
     PlayerID          = controller.netId;
 }
コード例 #7
0
        EnterOnlineSceneConnectionComplete
            (NetworkedPlayerController playerController)
        {
            ServerConnectionComplete           = true;
            NetworkManager.LocalPlayerStarted -= EnterOnlineSceneConnectionComplete;
            Debug.Log("PIM: Online connection complete");
            GameStateManager GSM = GameStateManager.FindCurrentGameManager();

            MyContract.RequireFieldNotNull(GSM, "Game State Manager");
            NetworkManager.PlayerDisconnected += GSM.OnPlayerDisconnect;
            FinishEnterOnlineSceneIfReady();
        }
コード例 #8
0
 private void SetupInGameUI(NetworkedPlayerController NPC)
 {
     UIManager.SetPlayerController(PlayerController);
     UIManager.EnteringMultiplayerGame(NetworkManager.networkAddress);
     NPC.EventScoreUpdated += UIManager.OnScoreUpdate;
     NPC.EventPlayerRemovedFromScoreboard
         += UIManager.OnPlayerRemovedFromScoreboard;
     NPC.LocalPlayerShipDestroyed += delegate(PlayerIdentifier killer)
     {
         UIManager.OnLocalPlayerShipDestroyed(killer, NPC.RespawnDelay);
     };
     NPC.CmdSendScoreboardStateToUI();
 }
コード例 #9
0
        private void InitialisePlayerController(NetworkedPlayerController IPC)
        {
            this.PlayerController = IPC;

            PlayerController.setCurrentShipChoice(PlayerShipClassChoice);
            PlayerController.initialiseShipClassManager(SpaceshipClassManager);

            // Hook up spaceship spawn event
            PlayerController.LocalPlayerShipSpawned += localPlayerShipCreatedHandler;
            PlayerController.LocalPlayerShipSpawned += UIManager.OnLocalPlayerShipSpawned;
            // as this is the local player,
            // there is no need to check for existing ship spawns
            // (they would have been observed directly through the RPC in the IPC)
            PlayerController.LocalPlayerShipHealthChanged += UIManager.SetCurrentPlayerHealth;
        }
コード例 #10
0
        public GameObject playerControllerSpawnHandler(Vector3 position, NetworkHash128 assetId)
        {
            Debug.Log("player controller spawn handler called");
            GameObject player_obj
                = (GameObject)Instantiate(player_prefab,
                                          position,
                                          Quaternion.identity);
            NetworkedPlayerController spawned_player_controller
                = player_obj.GetComponent <NetworkedPlayerController>();

            spawned_player_controller.LocalPlayerStarted += passthroughLocalPlayerStarted;
            spawned_player_controller.SetupComplete();

            return(player_obj);
        }
コード例 #11
0
        CreateNew
            (NetworkConnection conn)
        {
            MyContract.RequireArgument(
                conn.playerControllers.Count == 1,
                "the input connection has only one "
                + "player controller associated with it",
                "conn"
                );
            PlayerController          PC         = conn.playerControllers[0];
            GameObject                RootObject = PC.gameObject;
            NetworkedPlayerController NPC
                = RootObject.GetComponent <NetworkedPlayerController>();

            MyContract.RequireArgumentNotNull(NPC, NpcIdentifyingText);

            return(CreateNew(NPC));
        }
コード例 #12
0
        public void OnPlayerJoin(NetworkedPlayerController playerController)
        {
            MyContract.RequireArgumentNotNull(playerController, "playerController");
            PlayerIdentifier NewPlayerId = PlayerIdentifier.CreateNew(playerController);

            playerController.ShipDestroyed
                += delegate(PlayerIdentifier hunter)
                {
                Scoreboard.OnKillEvent(hunter, NewPlayerId);
                };
            Scoreboard.ScoreUpdate += playerController.OnScoreUpdate;
            Scoreboard.PlayerRemoved
                += playerController.OnPlayerRemovedFromScoreboardPassthrough;
            Scoreboard.RegisterNewPlayer(NewPlayerId);
            //Debug.Log("Game State Manager: Checking if we have a spaceship class manager");
            MyContract.RequireFieldNotNull(SSClassManager, "Spaceship Class Manager");
            //Debug.Log("Game State Manager: Initialising given NPC with our SSCManager");
            playerController.initialiseShipClassManager(SSClassManager);
        }
コード例 #13
0
        public void SetPlayerController(NetworkedPlayerController playerController)
        {
            if (!CameraRegistry.Contains((int)CameraRoles.FixedUi))
            {
                throw new InvalidOperationException(CAMERA_NOT_SET_EXCEPTION_MESSAGE);
            }

            ScoreboardUiManager ScoreUIManager
                = ComponentRegistry
                  .RetrieveManager
                  <ScoreboardUiManager>
                      (UIElements.Scoreboard);

            if (ScoreUIManager != null)
            {
                ScoreUIManager.LocalPlayerId = playerController.netId;
            }

            this.PlayerController = playerController;
            //player_centred_canvas.worldCamera = player_UI_camera;
            //player_centred_canvas_object.transform.SetParent(player_object.transform);
            //player_centred_canvas_object.transform.localPosition = player_centred_UI_offset;
        }
コード例 #14
0
 /// <summary>
 /// Called when this client disconnects from the server
 /// </summary>
 public void OnClientDisconnect()
 {
     PlayerController = null;
     ExitNetworkGame(false);
 }