国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Unity進(jìn)階–通過PhotonServer實(shí)現(xiàn)聯(lián)網(wǎng)登錄注冊功能(客戶端)–PhotonServer(三)

這篇具有很好參考價值的文章主要介紹了Unity進(jìn)階–通過PhotonServer實(shí)現(xiàn)聯(lián)網(wǎng)登錄注冊功能(客戶端)–PhotonServer(三)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

Unity進(jìn)階–通過PhotonServer實(shí)現(xiàn)聯(lián)網(wǎng)登錄注冊功能(客戶端)–PhotonServer(三)

前情提要

  • 單例泛型類

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class MyrSingletonBase<T> : MonoBehaviour where T : MonoBehaviour
    {
        private static T instance;
        public static T Instance {
            get
            {
                return instance;
            }
        }
    
        protected virtual void Awake() {
            instance = this as T;
        }
    
        protected virtual void OnDestroy() {
            instance = null;
        }
    }
    
    
  • ManagerBase

    using System.Collections;
    using System.Collections.Generic;
    using Net;
    using UnityEngine;
    
    public abstract class ManagerBase : MyrSingletonBase<ManagerBase>
    {
       public List<MoonBase> Monos = new List<MoonBase>();
    
       public void Register(MoonBase mono){
        if (!Monos.Contains(mono)){
            Monos.Add(mono);
        }
       }
       
       public virtual void ReceiveMessage(Message message){
        if (message.Type != GetMessageType()){
            return;
        } 
        foreach (var mono in Monos){
            mono.ReceiveMessage(message);
        }
       }
    
       
       public abstract byte GetMessageType();
    }
    
    
    • 消息中心

      using System.Collections;
      using System.Collections.Generic;
      using Net;
      using UnityEngine;
      
      public class MessageCenter : MyrSingletonBase<MessageCenter>
      {
          public static List<ManagerBase> Managers = new List<ManagerBase>();
      
          public void Register(ManagerBase manager){
              if (!Managers.Contains(manager)){
                  Managers.Add(manager);
              }
          }
      
          public void SendCustomMessage(Message message){
              foreach(var manager in Managers){
                  manager.ReceiveMessage(message);
              }
          }
      
          public static void SendMessage(Message message){
               foreach(var manager in Managers){
                  manager.ReceiveMessage(message);
              }
          }
      }
      
      
      • manager下的組件基礎(chǔ)

        using System.Collections;
        using System.Collections.Generic;
        using Net;
        using UnityEngine;
        
        public class MoonBase : MonoBehaviour
        {
            public virtual void ReceiveMessage(Message message){
                
            }
        }
        
        
      • uiManager(綁在canvas上)

        using System.Collections;
        using System.Collections.Generic;
        using Net;
        using UnityEngine;
        
        public class UiManager : ManagerBase
        {
            void Start()
            {
                MessageCenter.Instance.Register(this);
            }
        
          public override byte GetMessageType()
            {
                return MessageType.Type_UI;
            }
            
        }
        
        
        
  • PhotonManager

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using ExitGames.Client.Photon;
    using Net;
    
    public class PhotonManager : MyrSingletonBase<PhotonManager>, IPhotonPeerListener
    {
        private  PhotonPeer peer;
        
        void Awake() {
            base.Awake();
            DontDestroyOnLoad(this);
        }
        // Start is called before the first frame update
        void Start()
        {
            peer = new PhotonPeer(this, ConnectionProtocol.Tcp);
            peer.Connect("127.0.0.1:4530", "PhotonServerFirst");
        }
    
        void Update()
        {
            peer.Service();
        }
    
        private void OnDestroy() {
            base.OnDestroy();
            //斷開連接
            peer.Disconnect();    
        }
    
        public void DebugReturn(DebugLevel level, string message)
        {
    
        }
    
        /// <summary>
        /// 接收服務(wù)器事件
        /// </summary>
        /// <param name="eventData"></param>
        public void OnEvent(EventData eventData)
        {
            //拆包
            Message msg = new Message();
            msg.Type = (byte)eventData.Parameters[0];
            msg.Command = (int)eventData. Parameters[1];
            List<object> list = new List<object>();
            for (byte i = 2; i < eventData.Parameters.Count; i++){
                list.Add(eventData.Parameters[i]);
            }
            msg.Content = list.ToArray();
            MessageCenter.SendMessage(msg);
        }
    
        /// <summary>
        /// 接收服務(wù)器響應(yīng)
        /// </summary>
        /// <param name="operationResponse"></param>
        public void OnOperationResponse(OperationResponse operationResponse)
        {
            if (operationResponse.OperationCode == 1){
                Debug.Log(operationResponse.Parameters[1]);
            }
    
        }
    
        /// <summary>
        /// 狀態(tài)改變
        /// </summary>
        /// <param name="statusCode"></param>
        public void OnStatusChanged(StatusCode statusCode)
        {
            Debug.Log(statusCode);
        }
    
        /// <summary>
        /// 發(fā)送消息
        /// </summary>
        public void Send(byte type, int command, params object[] objs)
        {
            Dictionary<byte, object> dic = new Dictionary<byte,object>();
            dic.Add(0,type);
            dic.Add(1,command);
            byte i = 2;
            foreach (object o in objs){
                dic.Add(i++, o);
            }
            peer.OpCustom(0, dic, true);
        }
    
    }
    
    

客戶端部分

  1. 搭個頁面

    Unity進(jìn)階–通過PhotonServer實(shí)現(xiàn)聯(lián)網(wǎng)登錄注冊功能(客戶端)–PhotonServer(三),unity游戲開發(fā),unity,java,游戲引擎

  2. panel上掛上腳本

    using System.Collections;
    using System.Collections.Generic;
    using Net;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class LoginPanel : MoonBase
    {
        //賬號和密碼輸入框
        public InputField AccountField;
        public InputField PasswordField;
        // Start is called before the first frame update
        void Start()
        {
            UiManager.Instance.Register(this);
        }
    
        // Update is called once per frame
        void Update()
        {
            
        }
    
        public override void ReceiveMessage(Message message){
            //判斷是否是自己該傳遞的消息
            base.ReceiveMessage(message);
            //判斷消息命令
            switch (message.Command)
            {
                case MessageType.Account_Register_Res:
                    Debug.Log("注冊成功");
                    break;
                case MessageType.Account_Login_res:
                    Destroy(gameObject);
                    break;
            }
        }
    
        //注冊
        public void Register(){
            PhotonManager.Instance.Send(MessageType.Type_Account, MessageType.Account_Register, AccountField.text, PasswordField.text);
        }
    
        //登錄
        public void Login() {
            PhotonManager.Instance.Send(MessageType.Type_Account, MessageType.Account_Login, AccountField.text, PasswordField.text);
        }
    }
    
    
  3. 綁定對象,綁定事件

Unity進(jìn)階–通過PhotonServer實(shí)現(xiàn)聯(lián)網(wǎng)登錄注冊功能(客戶端)–PhotonServer(三),unity游戲開發(fā),unity,java,游戲引擎

Unity進(jìn)階–通過PhotonServer實(shí)現(xiàn)聯(lián)網(wǎng)登錄注冊功能(客戶端)–PhotonServer(三),unity游戲開發(fā),unity,java,游戲引擎文章來源地址http://www.zghlxwxcb.cn/news/detail-660372.html

到了這里,關(guān)于Unity進(jìn)階–通過PhotonServer實(shí)現(xiàn)聯(lián)網(wǎng)登錄注冊功能(客戶端)–PhotonServer(三)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Unity使用leancloud開發(fā)弱數(shù)據(jù)聯(lián)網(wǎng)游戲(注冊、登錄和云端數(shù)據(jù)存讀)

    Unity使用leancloud開發(fā)弱數(shù)據(jù)聯(lián)網(wǎng)游戲(注冊、登錄和云端數(shù)據(jù)存讀)

    最近,由于開發(fā)需要數(shù)據(jù)存儲服務(wù),就跑去Bmob看看,不看不要緊,發(fā)現(xiàn)自己以前創(chuàng)建的應(yīng)用的數(shù)據(jù)存儲服務(wù)居然變成非永久的了,只有一年的免費(fèi)時間,而且還過期了。這對于我將要開發(fā)的軟件時很不友好的;因此,我就只能去找與Bmob同類型的后端云服務(wù),就是我接下來要

    2023年04月23日
    瀏覽(20)
  • Unity實(shí)現(xiàn)賬號登錄,注冊功能

    Unity實(shí)現(xiàn)賬號登錄,注冊功能

    制作了用戶登錄界面 ?關(guān)于彈窗使用了DOTween插件,實(shí)現(xiàn)漸隱漸顯效果。 關(guān)于賬號使用了本地Json讀取, 默認(rèn)賬號:YSQS/YSQS1 密碼:admin/admin1 注冊功能其實(shí)應(yīng)該重構(gòu)的因?yàn)橛卸巫x流的問題存在。 賬號注冊加入了邀請碼(其實(shí)就一個if) ?接下來就是我那臭死了的源碼。 GameSt

    2024年02月11日
    瀏覽(24)
  • Unity實(shí)現(xiàn)登錄/注冊/審核功能
  • 【Unity+MySQL】實(shí)現(xiàn)注冊登錄系統(tǒng)(封裝版)

    【Unity+MySQL】實(shí)現(xiàn)注冊登錄系統(tǒng)(封裝版)

    接著 上篇文章的注冊登錄系統(tǒng),這篇文章將MySQL相關(guān)操作封裝,在Unity交互腳本中直接調(diào)用封裝的方法。 編寫一個DBConnector腳本,封裝MySQL中常用的操作,如連接數(shù)據(jù)庫、關(guān)閉數(shù)據(jù)庫、查詢數(shù)據(jù)庫、除查詢外的插入、更新、刪除等操作。 編寫一個User腳本用于封裝用戶注冊、登

    2024年02月05日
    瀏覽(17)
  • 【Unity+MySQL】實(shí)現(xiàn)簡單的注冊登錄系統(tǒng)

    【Unity+MySQL】實(shí)現(xiàn)簡單的注冊登錄系統(tǒng)

    確保這兩個軟件都能夠在你的計(jì)算機(jī)上良好地運(yùn)行。 鏡像地址:http://mirrors.sohu.com/mysql/MySQL-8.0/ 下載完成后雙擊運(yùn)行msi文件。 Next→ Next→ 選擇自定義安裝, Next→ 選擇安裝路徑, Next→ Install安裝, 安裝完成,F(xiàn)inish。 此電腦→計(jì)算機(jī)→屬性, 關(guān)于→高級系統(tǒng)設(shè)置, 高級→環(huán)

    2024年02月05日
    瀏覽(36)
  • 【Unity+MySQL】實(shí)現(xiàn)注冊登錄系統(tǒng)(升級版)

    【Unity+MySQL】實(shí)現(xiàn)注冊登錄系統(tǒng)(升級版)

    接著 上篇文章所談到的系統(tǒng)缺陷,這篇文章進(jìn)行升級解決。 問題 :注冊界面與登錄界面是同一個界面,導(dǎo)致用戶輸入用戶密碼進(jìn)行注冊后,即可點(diǎn)擊登錄。 解決 :在同一個場景中分別創(chuàng)建注冊界面和登錄界面,使用SetActive控制注冊/登錄成功后UI的顯示與隱藏。 整體的UI框

    2024年02月09日
    瀏覽(18)
  • Unity3D制作注冊登錄界面,并實(shí)現(xiàn)場景跳轉(zhuǎn)

    Unity3D制作注冊登錄界面,并實(shí)現(xiàn)場景跳轉(zhuǎn)

    效果預(yù)覽圖片: 效果預(yù)覽視頻: 一、新建項(xiàng)目工程 1、打開Unity3D,新建一個項(xiàng)目,將其命名為“Login”。我這里用的版本是Unity2018.4.2f1,不同版本制作過程中的界面可能稍有不同,但是不影響具體功能的實(shí)現(xiàn)。 2、可以將樣例場景SampleScene重命名為Login,最好做到見名知意。

    2024年02月03日
    瀏覽(141)
  • Unity3D實(shí)現(xiàn)MySql數(shù)據(jù)庫登錄與注冊功能

    Unity3D實(shí)現(xiàn)MySql數(shù)據(jù)庫登錄與注冊功能

    1、界面布局如下: 2、界面控件 1、封裝MySql 2、編寫登錄、注冊功能腳本 掛載LoginPanel腳本,并將控件映射到公共屬性如下: 有問題請指出,謝謝!

    2024年02月11日
    瀏覽(25)
  • 基于Unity客戶端與服務(wù)端實(shí)現(xiàn)登錄與注冊以及多人在線聊天

    1.在Unity下,創(chuàng)建一個GameManager空對象,用于啟動客戶端連接以及實(shí)例化一個登錄頁面LoginView的Prefab,并將腳本LoginView掛載在上面。 2.創(chuàng)建一個Client類,用于客戶端向服務(wù)端發(fā)起連接請求,并且發(fā)送給服務(wù)端消息以及接收服務(wù)端的響應(yīng) 3.創(chuàng)建一個腳本LoginView掛載在LoginView對象上

    2024年04月16日
    瀏覽(25)
  • 手把手教你實(shí)現(xiàn):Android注冊登錄功能,通過本地服務(wù)器保存用戶賬號密碼到數(shù)據(jù)庫

    手把手教你實(shí)現(xiàn):Android注冊登錄功能,通過本地服務(wù)器保存用戶賬號密碼到數(shù)據(jù)庫

    代碼我放到文章最后面了 首先你需要電腦一臺:如果沒有電腦將會很難辦呢 -----沃茲基碩德 下載并安裝以下開發(fā)工具 Android Studio 官網(wǎng)最新版 用來開發(fā) 安卓App IntelliJ IDEA 官網(wǎng)最新版 用來開發(fā) 后端 ,處理安卓APP的請求 Navicat for MySql 官網(wǎng)最新版 數(shù)據(jù)庫可視化工具,用來查看數(shù)

    2024年01月16日
    瀏覽(30)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包