protected override void Awake()
    {
        base.Awake();

        pun = PUNManager.Instance;

        if (pun == null)
        {
            Debug.LogError($"{typeof(PUNMenuController)} could not find an instance of {typeof(PUNManager)}", this);
            return;
        }

        menu = InitialiseNewElement("Multi Player");
        VisualElement optionRoot = menu.Q(OPTION_ROOT);

        { //Join Room
            RoomField newRoomElement = new RoomField("New Room", "Room Name", "Create");
            newRoomElement.OnSubmit += () => CreateRoom(newRoomElement);
            optionRoot.Add(newRoomElement);
        }

        { //Join Room
            RoomField joinRoomElement = new RoomField("Join Room", "Room Name", "Connect");
            joinRoomElement.OnSubmit += () => JoinRoom(joinRoomElement);
            optionRoot.Add(joinRoomElement);
        }
        optionRoot.Add(InitialiseOption("Back to Main Menu", () =>
        {
            StartAnimation(AnimState.Out, OnComplete: () =>
            {
                Destroy(PUNManager.Instance);
                SceneManager.LoadScene(0);
            });
        }));
    }
Example #2
0
    void Awake()
    {
        //Singleton initialisation
        if (Instance != null)
        {
            Destroy(this);
            return;
        }

        Instance = this;


        PhotonNetwork.AutomaticallySyncScene = true;
        DontDestroyOnLoad(this.gameObject);

        if (!ConnectToServer())
        {
            Debug.LogWarning("Failed to connect to photon server");
        }
    }