• PhotonServer(4)


    unity客户端搭建

    创建UnityClient工程

    导入Photon3Unity3D.dll到Plugin文件夹

    创建PhotonEngine.cs   与服务段交互

    using System.Collections;
    using System.Collections.Generic;
    using ExitGames.Client.Photon;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class PhotonEngine : MonoBehaviour,IPhotonPeerListener
    {
        public static PhotonPeer Peer
        {
            get { return peer; }
        }
        private static PhotonEngine Instance;
        private static PhotonPeer peer = null;
    
    
        void Awake()
        {
            if (Instance==null)
            {
                Instance = this;
                DontDestroyOnLoad(this.gameObject);
            }
            else if (Instance!=this)
            {
                Destroy(this.gameObject );
                return;
            }    
        }
    
        //void CallConnect()
        //{
    
        //}
    // Start is called before the first frame update
        void Start()
        {
            //通过listener接受服务段响应
            peer = new PhotonPeer(this, ConnectionProtocol.Udp);
            peer.Connect("127.0.0.1:5055", "MyGame1");
            //peer.OpCustom()
        }
    
        // Update is called once per frame
        void Update()
        {
            peer.Service();
        }
    
        void OnDestroy()
        {
            if (peer!=null&&peer.PeerState==PeerStateValue.Disconnected)
            {
                peer.Disconnect();
            }
        }
    
        public void DebugReturn(DebugLevel level, string message)
        {
            //throw new System.NotImplementedException();
        }
    
        public void OnEvent(EventData eventData)
        {
            //throw new System.NotImplementedException();
        }
    
        public void OnOperationResponse(OperationResponse operationResponse)
        {
            //throw new System.NotImplementedException();
        }
    
        public void OnStatusChanged(StatusCode statusCode)
        {
            //throw new System.NotImplementedException();
            Debug.Log(statusCode);
            
        }
    
    }
    

      

  • 相关阅读:
    《挑战程序设计竞赛》 一二章部分代码题解
    动态规划之矩阵连乘和POJ 1651
    关于图片的重绘,从而进行压缩
    iOS开发:读取pdf文件
    如何改变tableview的section的颜色
    端口的作用
    Mac 下,配置SVN
    cocoaPods 的安装和使用
    关于如何调用苹果自带的地图APP
    关于 HTTP 请求头的内容
  • 原文地址:https://www.cnblogs.com/liuke-1264746554/p/10775095.html
Copyright © 2020-2023  润新知