예제 #1
0
 /// <summary>
 /// 发送数据
 /// </summary>
 private void SendData(byte[] data)
 {
     try {
         Debug.Log("total length:" + data.Length);
         string str = "";
         for (int i = 0; i < data.Length; i++)
         {
             str += data[i] + " ";
         }
         Debug.Log(str);
         if (stream != null)
         {
             stream.Write(data, 0, data.Length);
         }
         else
         {
             showMessageTip("服务器断开连接,请重新运行程序或稍后再试");
             isConnected = false;
             SocketEventHandle.getInstance().noticeDisConect();
             //ReConnectScript.getInstance().ReConnectToServer();
             //Connect();
         }
         Debug.Log("send over");
     } catch (Exception ex) {
         Debug.Log(ex.ToString());
         //	showMessageTip("服务器断开连接,请重新运行程序或稍后再试");
         isConnected = false;
         SocketEventHandle.getInstance().noticeDisConect();
         //ReConnectScript.getInstance().ReConnectToServer();
         //Connect();
     }
 }
예제 #2
0
 public void closeDialog()
 {
     MyDebug.Log("closeDialog");
     SocketEventHandle.getInstance().CreateRoomCallBack -= onCreateRoomCallback;
     Destroy(this);
     Destroy(gameObject);
 }
예제 #3
0
 public void removeListener()
 {
     SocketEventHandle.getInstance().cardChangeNotice    -= cardChangeNotice;
     CommonEvent.getInstance().DisplayBroadcast          -= gameBroadcastNotice;
     SocketEventHandle.getInstance().contactInfoResponse -= contactInfoResponse;
     //	SocketEventHandle.getInstance ().gameBroadcastNotice -= gameBroadcastNotice;
 }
예제 #4
0
    void Awake()
    {
        SocketEventHandle.getInstance().disConnetNotice        += disConnetNotice;
        SocketEventHandle.getInstance().hostUpdateDrawResponse += hostUpdateDrawResponse;
        SocketEventHandle.getInstance().otherTeleLogin         += otherTeleLogin;
        SocketEventHandle.getInstance().cardChangeNotice       += cardChangeNotice;

        if (PlayerPrefs.HasKey("yinyueVolume"))
        {
            GlobalDataScript.yinyueVolume  = PlayerPrefs.GetFloat("yinyueVolume");
            GlobalDataScript.yinxiaoVolume = PlayerPrefs.GetFloat("yinxiaoVolume");
        }

        if (PlayerPrefs.HasKey("isYueYu"))
        {
            int yueyu = PlayerPrefs.GetInt("isYueYu");
            if (yueyu > 0)
            {
                GlobalDataScript.isYueYu = true;
            }
            else
            {
                GlobalDataScript.isYueYu = false;
            }
        }
    }
예제 #5
0
 public void CloseDialog()
 {
     SocketEventHandle.getInstance().inviteGetRewardResponse -= InviteGetRewardCallBack;
     SocketEventHandle.getInstance().inviteHistoryResponse   -= ShowHistory;
     Destroy(this);
     Destroy(gameObject);
 }
예제 #6
0
 void Start()
 {
     SocketEventHandle.getInstance().giftResponse += giftResponse;
     CommonEvent.getInstance().prizeCountChange   += prizeCountChange;
     CustomSocket.getInstance().sendMsg(new GetGiftRequest("0"));
     choujiangNum.text = GlobalDataScript.loginResponseData.account.prizecount + "";
 }
예제 #7
0
    public IEnumerator PlayClipData(Int16[] intArr, int sendUUid)
    {
        if (intArr.Length == 0)
        {
            Debug.Log("get intarr clipdata is null");
            yield return(0);
        }
        MyDebug.Log("PlayClipData");

        //排麦序,当有人在语音时,等待。
        while (playAudio.isPlaying)
        {
            yield return(new WaitForSeconds(0.2f));
        }

        //从Int16[]到float[]
        float[] samples       = new float[intArr.Length];
        int     rescaleFactor = 32767;

        for (int i = 0; i < intArr.Length; i++)
        {
            samples[i] = (float)intArr[i] / rescaleFactor;
        }

        playAudio.clip = AudioClip.Create("playRecordClip", intArr.Length, 1, 8000, false, false);
        playAudio.clip.SetData(samples, 0);
        playAudio.mute = false;
        //playAudio.Play();
        //AudioCallBack callbackTest;
        PlayClipDataBy();//callbackTest

        SocketEventHandle.getInstance().micInputNoticeOther(sendUUid);
    }
예제 #8
0
 void OnDestroy()
 {
     if (SocketEventHandle.checkInstance())
     {
         SocketEventHandle.getInstance().micInputNotice -= micInputNotice;
     }
 }
예제 #9
0
    void Start()
    {
        GlobalDataScript.playCountForGoldType = 0;
        if (GlobalDataScript.configTemp.pay == 0)
        {
            foreach (GameObject go in fangka)
            {
                go.SetActive(true);
            }
        }
        else
        {
            foreach (GameObject go in fangka)
            {
                go.SetActive(false);
            }
        }
        openDefaultSetingPanel();         //打开默认房间设置
        SocketEventHandle.getInstance().CreateRoomCallBack += onCreateRoomCallback;
        SocketEventHandle.getInstance().JoinRoomCallBack   += onJoinRoomCallBack;

        if (SocketEventHandle.getInstance().serviceErrorNotice != null)
        {
            SocketEventHandle.getInstance().serviceErrorNotice = null;
        }
        SocketEventHandle.getInstance().serviceErrorNotice += serviceResponse;
    }
예제 #10
0
    public bool sendHeadData2()
    {
        MyDebug.Log("send head data");
        try
        {
            if (stream != null && tcpclient.Connected)
            {
                //stream.Write(headBytes, 0, headBytes.Length);

                return(true);
            }
            else
            {
                isConnected = false;
                if (!GlobalDataScript.isonLoginPage)
                {
                    PrefabManage.loadPerfab("Prefab/Panel_Start");
                }
                SocketEventHandle.getInstance().noticeDisConect();
                return(false);
            }
        }
        catch (Exception ex)
        {
            MyDebug.Log(ex.ToString());
            isConnected = false;
            //showMessageTip ("服务器已断开连接,请重新登录");
            isConnected = false;
            SocketEventHandle.getInstance().noticeDisConect();
            return(false);
        }
    }
예제 #11
0
    private RoomCreateVo sendVo;//创建房间的信息

    // Use this for initialization
    void Start()
    {
        panelChangshaSetting.SetActive(true);

        // 绑定服务端返回创建房间响应委托函数
        SocketEventHandle.getInstance().CreateRoomCallBack += onCreateRoomCallback;
    }
예제 #12
0
    /// <summary>
    /// 发送心跳包
    /// </summary>
    /// *

    public bool sendHeadData()
    {
        //MyDebug.Log("send head data");
        try{
            if (stream != null && tcpclient.Connected)
            {
                stream.Write(headBytes, 0, headBytes.Length);
                GlobalDataScript.getInstance().xinTiaoTime = DateTime.UtcNow;
                return(true);
            }
            else
            {
                isConnected = false;
                SocketEventHandle.getInstance().noticeDisConect();
                return(false);
            }
        }catch (Exception ex) {
            MyDebug.Log(ex.ToString());
            isConnected = false;
            //showMessageTip ("服务器已断开连接,请重新登录");
            isConnected = false;
            SocketEventHandle.getInstance().noticeDisConect();
            return(false);
        }
    }
예제 #13
0
 /// <summary>
 /// 发送数据
 /// </summary>
 private void SendData(byte[] data)
 {
     MyDebug.Log("----------------SendData-----------------");
     //MyDebug.Log ("send data"+data.ToString ());
     try
     {
         if (stream != null)
         {
             MyDebug.Log("----------------SendData----2-------------");
             stream.Write(data, 0, data.Length);
         }
         else
         {
             //	showMessageTip("服务器断开连接,请重新运行程序或稍后再试");
             MyDebug.Log("22222222222222222222222222222");
             isConnected = false;
             SocketEventHandle.getInstance().noticeDisConect();
             //ReConnectScript.getInstance().ReConnectToServer();
             //Connect();
         }
     }
     catch (Exception ex)
     {
         MyDebug.Log(ex.ToString());
         MyDebug.Log("----------------SendData------------------------Exception----------------");
         //	showMessageTip("服务器断开连接,请重新运行程序或稍后再试");
         isConnected = false;
         SocketEventHandle.getInstance().noticeDisConect();
         //ReConnectScript.getInstance().ReConnectToServer();
         //Connect();
     }
 }
예제 #14
0
    /// <summary>
    /// 发送心跳包
    /// </summary>
    /// *

    public bool sendHeadData()
    {
        MyDebug.Log("send head data");
        try{
            if (stream != null && tcpclient.Connected)
            {
                HeadRequest head = new HeadRequest();
                headBytes = head.ToBytes();
                stream.Write(headBytes, 0, headBytes.Length);

                return(true);
            }
            else
            {
                isConnected = false;
                SocketEventHandle.getInstance().noticeDisConect();
                return(false);
            }
        }catch (Exception ex) {
            MyDebug.Log(ex.ToString());
            isConnected = false;
            //showMessageTip ("服务器已断开连接,请重新登录");
            isConnected = false;
            SocketEventHandle.getInstance().noticeDisConect();
            return(false);
        }
    }
예제 #15
0
 public void exitSure_Click()
 {
     SoundCtrl.getInstance().playSoundUI();
     SocketEventHandle.getInstance().gameBackPlayResponse -= gameBackPlayResponse;
     Destroy(this);
     Destroy(gameObject);
 }
예제 #16
0
    private RoomCreateVo sendVo;       //创建房间的信息
    void Start()
    {
        int x = PlayerPrefs.GetInt("userDefaultMJ");

        if (x == 0)
        {
            openZhuanzhuanSeetingPanel();
        }
        else if (x == 1)
        {
            openHuashuiSeetingPanel();
        }
        else if (x == 2)
        {
            //openChangshaSeetingPanel();
            openBoZhouSeetingPanel();
        }
        else if (x == 3)
        {
            openGuangDongSeetingPanel();
        }

        SocketEventHandle.getInstance().CreateRoomCallBack += onCreateRoomCallback;
        //xiazuiBtn.SetActive(false);
        //xiazuiSelect.SetActive(false);
    }
예제 #17
0
 public void serviceErrorNotice(ClientResponse response)
 {
     SocketEventHandle.getInstance().serviceErrorNotice -= serviceErrorNotice;
     watingPanel.gameObject.SetActive(false);
     clear();
     TipsManagerScript.getInstance().setTips(response.message);
 }
예제 #18
0
    public void sureRoomNumber()
    {
        if (inputChars.Count != 6)
        {
            MyDebug.Log("请先完整输入房间号码!");

            TipsManagerScript.getInstance().setTips("请先完整输入房间号码!");
            return;
        }

        if (watingPanel != null)
        {
            watingPanel.gameObject.SetActive(true);
        }


        String roomNumber = inputChars[0] + inputChars[1] + inputChars[2] + inputChars[3] + inputChars[4] + inputChars[5];

        MyDebug.Log(roomNumber + "此处加入房间输入房间号,并发送到服务器判断是否有此房间存在");
        RoomJoinVo roomJoinVo = new RoomJoinVo();

        roomJoinVo.roomId = int.Parse(roomNumber);
        string sendMsg = JsonMapper.ToJson(roomJoinVo);

        StartCoroutine(ConnectTime(4f, 1));
        CustomSocket sok = CustomSocket.getInstance();

        sok.sendMsg(new JoinRoomRequest(sendMsg));

        if (SocketEventHandle.getInstance().serviceErrorNotice != null)
        {
            SocketEventHandle.getInstance().serviceErrorNotice = null;
        }
        SocketEventHandle.getInstance().serviceErrorNotice += serviceErrorNotice;
    }
 public void closeDialog()
 {
     SoundCtrl.getInstance().playSoundUI();
     SocketEventHandle.getInstance().CreateRoomCallBack -= onCreateRoomCallback;
     Destroy(this);
     Destroy(gameObject);
 }
예제 #20
0
    /**
     * 打开分享对话框
     */
    public void openShareDialog()
    {
        SoundCtrl.getInstance().playSoundByActionButton(1);
        loadPerfab("Prefab/Panel_share");

        SocketEventHandle.getInstance().serviceErrorNotice += serviceErrorNotice;
    }
예제 #21
0
    private void readBuffer(BinaryReader buffers)
    {
        int lens = ReadInt(buffers.ReadBytes(4));

        disConnectCount = 0;
        if (!hasStartTimer && lens == 20)
        {
            startTimer();
            hasStartTimer = true;
        }

        Debug.Log("lengs ====>>  " + lens + "  " + buffers.BaseStream.Length);
//		for(int i = 0;i<buffers.BaseStream.Length){
//			Debug.Log("-- " + ReadInt(buffers.ReadBytes(4));
//		}

        if (lens > buffers.BaseStream.Length)
        {
            waitLen = lens;
            isWait  = true;
            buffers.BaseStream.Position = 0;
            byte[] dd   = new byte[buffers.BaseStream.Length];
            byte[] temp = buffers.ReadBytes((int)buffers.BaseStream.Length);
            Array.Copy(temp, 0, dd, 0, (int)buffers.BaseStream.Length);
            if (sources == null)
            {
                sources = dd;
            }
            return;
        }
        int headcode    = ReadInt(buffers.ReadBytes(4));
        int assistId    = ReadInt(buffers.ReadBytes(4));
        int handleCode  = ReadInt(buffers.ReadBytes(4));
        int reserveCode = ReadInt(buffers.ReadBytes(4));

//		string message = Encoding.UTF8.GetString(buffers.ReadBytes(lens - 20));
        ClientResponse response = new ClientResponse();

        response.headCode    = headcode;
        response.assistId    = assistId;
        response.handleCode  = handleCode;
        response.reserveCode = reserveCode;
        if (lens > 27)
        {
            response.bytes = buffers.ReadBytes(lens - 27);
        }
        if (headcode != APIS.HeadRESPONSE)
        {
            Debug.Log("response msg,  head code: " + response.headCode);
        }
        SocketEventHandle.getInstance().addResponse(response);

        buffers.ReadBytes(7);        //read the EOF symbol

        if (buffers.BaseStream.Position < buffers.BaseStream.Length)
        {
            readBuffer(buffers);
        }
    }
예제 #22
0
 public static SocketEventHandle getInstance()
 {
     if (_instance == null)
     {
         _instance = (SocketEventHandle)UnityEngine.Object.FindObjectOfType(typeof(SocketEventHandle));
     }
     return(_instance);
 }
예제 #23
0
파일: ChatSocket.cs 프로젝트: iuvei/PKGame
    private void showMessageTip(string message)
    {
        ClientResponse temp = new ClientResponse();

        temp.headCode = APIS.TIP_MESSAGE;
        temp.message  = message;
        SocketEventHandle.getInstance().addResponse(temp);
    }
예제 #24
0
 public void closeDialog()
 {
     SoundCtrl.getInstance().playSoundByActionButton(1);
     MyDebug.Log("closeDialog");
     SocketEventHandle.getInstance().CreateRoomCallBack -= onCreateRoomCallback;
     Destroy(this);
     Destroy(gameObject);
 }
예제 #25
0
    // Use this for initialization
    void Start()
    {
        ShareTypePanel.SetActive(false);
        UpdateInfo();

        SocketEventHandle.getInstance().inviteGetRewardResponse += InviteGetRewardCallBack;
        SocketEventHandle.getInstance().inviteHistoryResponse   += ShowHistory;
    }
예제 #26
0
 private RoomCreateVo sendVo;  //创建房间的信息
 void Start()
 {
     panelZhuanzhuanSetting.SetActive(true);
     panelChangshaSetting.SetActive(false);
     panelHuashuiSetting.SetActive(false);
     panelDevoloping.SetActive(false);
     SocketEventHandle.getInstance().CreateRoomCallBack += onCreateRoomCallback;
 }
 // 讲事件脚本挂在到一个游戏对象上 游戏运行每一帧都会判断是否有服务器响应信息
 public static SocketEventHandle getInstance()
 {
     if (_instance == null)
     {
         GameObject temp = new GameObject();
         _instance = temp.AddComponent <SocketEventHandle>();
     }
     return(_instance);
 }
예제 #28
0
    //增加服务器返沪数据监听
    public void addListener()
    {
        SocketEventHandle.getInstance().RoomBackResponse    += RoomBackResponse;
        SocketEventHandle.getInstance().cardChangeNotice    += cardChangeNotice;
        SocketEventHandle.getInstance().contactInfoResponse += contactInfoResponse;

        //	SocketEventHandle.getInstance ().gameBroadcastNotice += gameBroadcastNotice;
        CommonEvent.getInstance().DisplayBroadcast += gameBroadcastNotice;
    }
예제 #29
0
 // Use this for initialization
 void Start()
 {
     SocketEventHandle.getInstance().micInputNotice += micInputNotice;
     playAudio = GameObject.Find("GamePlayAudio").GetComponent <AudioSource> ();
     if (playAudio.clip == null)
     {
         playAudio.clip = AudioClip.Create("playRecordClip", 160000, 1, 8000, false, false);
     }
 }
예제 #30
0
 // Use this for initialization
 void Start()
 {
     CustomSocket.hasStartTimer = false;
     // 开始连接服务端
     CustomSocket.getInstance().Connect();
     versionText.text = "版本号:" + Application.version;
     GlobalDataScript.isonLoginPage = true;
     SocketEventHandle.getInstance().LoginCallBack += LoginCallBack;
 }