• 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);
            
        }
    
    }
    

      

  • 相关阅读:
    Java的jmap命令使用详解
    Linux常用文件管理命令详解
    Java的jps命令使用详解
    快速整明白Redis中的整数集合到底是个啥
    Java的jinfo命令使用详解
    Java的jstack命令使用详解
    快速整明白Redis中的字典到底是个啥
    Java的jstat命令使用详解
    Linux常用系统管理命令详解
    详解ElasticAPM实现微服务的链路追踪(NET)
  • 原文地址:https://www.cnblogs.com/liuke-1264746554/p/10775095.html
Copyright © 2020-2023  润新知