TaidouChatServer(客户端)

代码块

代码块语法遵循标准markdown代码,例如:

Unity内需要添加Photon3Unity3D.dll(在unity的Plugin里)




using UnityEngine;
using System.Collections;
using ExitGames.Client.Photon;
using System.Collections.Generic;


public class PhotonServerEngine2 : MonoBehaviour,IPhotonPeerListener {


    private PhotonPeer peer;
    private bool isConnected = false;


// Use this for initialization
void Start () {
         peer = new PhotonPeer(this,ConnectionProtocol.Tcp);
         peer.Connect("127.0.0.1:4530", "ChatServer");
}

// Update is called once per frame
void Update () {
        peer.Service();
}


    void OnGUI()
    {
        if (isConnected)
        {
            if (GUILayout.Button("Send a operation."))
            {
                Dictionary<byte, object> dict = new Dictionary<byte, object>();
                dict.Add(1, "username");
                dict.Add(2, "password");
                peer.OpCustom(1, dict, true);
            }
        }




    }
//主要是输出一些日志信息的
    public void DebugReturn(DebugLevel level, string message)
    {
        Debug.Log(level + ":" + message);
    }


    public void OnEvent(EventData eventData)
    {

    }


    public void OnOperationResponse(OperationResponse operationResponse)
    {
        Dictionary<byte, object> dict = operationResponse.Parameters;


        object v = null;
        dict.TryGetValue(1, out v);


        Debug.Log("Get value from server:" + v.ToString()); //unity里输出要用Debug.Log
    }


    public void OnStatusChanged(StatusCode statusCode)
    {
        switch (statusCode)
        { 
            case StatusCode.Connect:
                isConnected = true;
                Debug.Log("Connected success.");
                break;        
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值