Exemple #1
0
    private void Awake()
    {
        transitioner = GetComponent <Transitioner>();
        mainTrans    = mainCanvas.GetComponent <Transitionable>();
        connectTrans = connectCanvas.GetComponent <Transitionable>();

        onLobbyErrorListener = new Action <IEventParam>(
            (e) =>
        {
            connectText.text = "Error: " + ((StringParam)e).val;
            errorConfirmButton.gameObject.SetActive(true);
        });

        onTryConnectListener = new Action <IEventParam>(
            (e) =>
        {
            IpParam p        = (IpParam)e;
            connectText.text = (p.host) ? "Hosting match" : "Connecting to " + p.ip;
        });

        onTryConnectTimeoutListener = new Action <IEventParam>(
            (e) =>
        {
            BoolParam p      = (BoolParam)e;
            connectText.text = "Failed to Connect";
            errorConfirmButton.gameObject.SetActive(true);
        });

        connectListener = new Action <IEventParam>(
            (e) =>
        {
            connectText.text = "Starting match...";
            EventManager.Instance.Raise("request-scene", new IntParam(2));
        });
    }
Exemple #2
0
    protected override void Awake()
    {
        base.Awake();

        // Initialize members
        MessageQueue = new Queue <Message>();
        Net          = gameObject.AddComponent <NetSocketManager>();
        Net.Init(new MessageSerializer(this));

        // Initialize listeners
        tryConnectListener = new Action <IEventParam>(
            (e) =>
        {
            IpParam p = (IpParam)e;

            Net.Hosting    = p.host;
            Net.remoteIp   = p.ip;
            Net.remotePort = p.port;
            Net.Listen();

            //Debug.Log("Try connect as " + (p.host ? "host" : "client"));
        });

        tryConnectTimeoutListener = new Action <IEventParam>(
            (e) =>
        {
            Net.OnDisconnect();
            Net.StopListening();
        });
    }