コード例 #1
0
ファイル: Connection.cs プロジェクト: raomuqi/vstgit
    void Send(byte[] data, ProtoType msgType)
    {
        if (data == null)
        {
            Debug.LogError("发送数据错误");
            return;
        }
        switch (msgType)
        {
        case ProtoType.Importance:
            client.SendMsg(data);
            break;

        case ProtoType.Unimportance:
            if (differentUdpPort)
            {
                foreach (var ip in broadCastList)
                {
                    multidataConnection.SendTo(data, ip.Value);
                }
            }
            else
            {
                multidataConnection.BroadCast(data);
            }
            break;
        }
    }
コード例 #2
0
    public void OnUpdate()
    {
        switch (gameStatus)
        {
        case GameStatus.WaitConnect:
            CheckPlayerConnetTime();
            break;

        case GameStatus.EnterScene:
            CheckEnterScene();
            break;

        case GameStatus.Running:
            break;
        }

        //处理接收消息
        HandleHostDataMsg();
        //检测client状态变化
        UpdateClientStatus();

        //发送同步IP
        if (broadcastSelf == true)
        {
            int broadCastInterval = broadCastIntervalRate;
            if (curBroadCastFrame >= broadCastInterval)
            {
                curBroadCastFrame = 0;
                syncIpConnection.BroadCast(broadcastSelfData);
            }
            else
            {
                curBroadCastFrame++;
            }
        }
    }