Beispiel #1
0
    // Start is called before the first frame update
    void Start()
    {
        Application.targetFrameRate = 60;
        btnConnect   = this.transform.Find("BtnConnect").GetComponent <Button>();
        btnClose     = this.transform.Find("BtnClose").GetComponent <Button>();
        btnLogin     = this.transform.Find("BtnLogin").GetComponent <Button>();
        btnStart     = this.transform.Find("BtnStart").GetComponent <Button>();
        btnShoot     = this.transform.Find("BtnShoot").GetComponent <Button>();
        btnRight     = this.transform.Find("BtnRight").GetComponent <DoubleClickButton>();
        btnDown      = this.transform.Find("BtnDown").GetComponent <DoubleClickButton>();
        btnLeft      = this.transform.Find("BtnLeft").GetComponent <DoubleClickButton>();
        btnUp        = this.transform.Find("BtnUp").GetComponent <DoubleClickButton>();
        txtLog       = this.transform.Find("TxtLog").GetComponent <Text>();
        ballPrefab   = this.transform.Find("Ball");
        bulletPrefab = this.transform.Find("Bullet");
        NetMgr.GetInstance().client = new SocketClient();
        btnConnect.onClick.AddListener(delegate()
        {
            Connect();
        });
        btnClose.onClick.AddListener(delegate()
        {
            NetScene.getInstance().StopGame();
            stopGame();
        });
        btnLogin.onClick.AddListener(delegate()
        {
            Debug.Log("click login");
            //client.ClientWrite(Protocol.Move, "client send" + client.getLocalPort());
            NetMgr.GetInstance().client.ClientWrite(Protocol.Login, "login");;
        });
        btnStart.onClick.AddListener(delegate()
        {
            //client.ClientWrite(Protocol.Move, "client send" + client.getLocalPort());
            Debug.Log("click start");
            ModelFactory.getStance().startSpawn = true;
            NetMgr.GetInstance().client.ClientWrite(Protocol.StartGame, "start game");;
        });
        btnShoot.onClick.AddListener(delegate()
        {
            //AlgorithmsUtil.test();
            //client.ClientWrite(Protocol.Move, "client send" + client.getLocalPort());
            Debug.Log("click shoot");
            NetMgr.GetInstance().Send(Protocol.Update, ByteUtil.IntToBytes2(ActionType.shoot));

            //byte[] action = ByteUtil.intToBytes2(ActionType.keyboardMove);
            //byte[] content = ByteUtil.intToBytes2(3);
            //byte[] send = ByteUtil.bytesCombine(action, content);
            //NetMgr.getInstance().send(Protocol.Update, send);
        });

        btnRight.addPointerUp(delegate(object sender, EventArgs e)
        {
            onPointerUp(1);
        });
        btnRight.addPointerDown(delegate(object sender, EventArgs e)
        {
            onPointerDown(1);
        });

        btnDown.addPointerUp(delegate(object sender, EventArgs e)
        {
            onPointerUp(2);
        });
        btnDown.addPointerDown(delegate(object sender, EventArgs e)
        {
            onPointerDown(2);
        });

        btnLeft.addPointerUp(delegate(object sender, EventArgs e)
        {
            onPointerUp(3);
        });
        btnLeft.addPointerDown(delegate(object sender, EventArgs e)
        {
            onPointerDown(3);
        });

        btnUp.addPointerUp(delegate(object sender, EventArgs e)
        {
            onPointerUp(4);
        });
        btnUp.addPointerDown(delegate(object sender, EventArgs e)
        {
            onPointerDown(4);
        });
        Screen.fullScreenMode = FullScreenMode.Windowed;


        ModelFactory.getStance().init();
        UnityEngine.Random.InitState(1);
    }
Beispiel #2
0
    // Start is called before the first frame update
    void Start()
    {
        DoubleClickButton button = gameObject.GetComponent <DoubleClickButton>();

        button.OnSingleClick += DismissBio;
    }