ET 7 入門文檔(登錄)
目錄
一. 客戶端
????1.編譯運(yùn)行
????2.創(chuàng)建UI
????3.編寫UI代碼
????4.發(fā)送接收消息
? ? 5.編寫協(xié)議
二. 服務(wù)器
????1.發(fā)送接收消息

一.客戶端
1.編譯運(yùn)行
1.1打開 ET 打包工具
????·如圖1-1,在 Unity?頂部菜單選擇 ET -> Build Tool,打開 ET.BuildEditor 窗口.

1.2編譯? ?
如圖1-2,CodeMode 選擇 ClientServer, 點(diǎn)擊 BuildModelAndHotfix.

????如圖1-3,顯示編譯成功.

1.3運(yùn)行?? ????
????如圖1-4,在 Assets/Scenes 下 雙擊打開 Init 場景.

????如圖1-5,點(diǎn)擊運(yùn)行按鈕,可以看到正常打開了 Login?界面.

2.創(chuàng)建UI
????如圖1-6,打開 Asset/Bundles/UI,點(diǎn)擊 UILogin ,Ctr + C 進(jìn)行拷貝.

????如圖1-7,在??Asset/Bundles/UI 目錄下創(chuàng)建目錄 Demo/Login,Ctr + V 將 UILogin?拷貝進(jìn)來,并改名為 UILoginNew.

????如圖1-8,點(diǎn)擊?UILoginNew,在其?Inspector 窗口最底部,找到 AssetBundle,點(diǎn)擊 uilogin.unity3d.

????如圖1-9,彈出選項(xiàng),點(diǎn)擊 New... ,并取名為 uiloginnew.unity3d.

????結(jié)果,如圖1-10.

3.編寫UI代碼
3.1打開代碼工程
????如圖1-11,在項(xiàng)目根目錄,雙擊打開 ET.sln.

3.2編寫?UIComponent????
????如圖1-12,打開 ET/Unity/Unity.ModelView/Assets/Scripts/Codes/ModeView/Client/
Demo/UI,創(chuàng)建一個(gè)文件夾,取名 UILoginNew,拷貝 UILoginComponent 到 UILoginNew,更改文件名為 UILoginNewComponent.

????雙擊?UILoginNewComponent.cs,將 UILoginComponent 替換為 UILoginNewComponet:
3.3編寫?UIComponentSystem? ??????
????如圖1-13,打開?ET/Unity/Unity.HotfixView/Assets/Scripts/Codes/HotfixView/Client/
Demo/UI,創(chuàng)建一個(gè)文件夾,取名 UILoginNew??截?
????LoginFinish_RemoveLoginUI ->?LoginFinish_RemoveLoginNewUI?
????UILoginComponentSystem ->?UILoginComponentNewSystem?
????UILoginEvent -> UILoginNewEvent

????雙擊打開?UILoginNewEvent,不需要了解該部分代碼,將對應(yīng)名字進(jìn)行全部替換:
?????UILoginEvent -> UILoginNew
????UIType.UILogin?->?UIType.UILoginNew,
????ui.AddComponent<UILoginComponent> ->?ui.AddComponent<UILoginNewComponent>
? ? 此時(shí) UIType.UILoginNew 不存在,找到 ET/Unity/Unity.ModelView/Assets/Scripts/
Codes/ModeView/Client/Demo/UI/UIType.cs,在底部添加代碼:
????public const string UILoginNew = "UILoginNew";
????雙擊打開?LoginFinish_RemoveLoginNewUI?,不需要了解該部分代碼,將對應(yīng)名字全部進(jìn)行替換:
? ? LoginFinish_RemoveLoginUI -> LoginNewFinish_RemoveLoginNewUI
????UIType.UILogin ->?UIType.UILoginNew
? ? 雙擊打開 UILoginComponentSystem,不需要了解該部分代碼,將對應(yīng)名字全部進(jìn)行替換:
????UILoginComponentSystem ->?UILoginComponentNewSystem
????UILoginComponentAwakeSystem ->?UILoginComponentNewAwakeSystem?
????UILoginComponent ->?UILoginNewComponent
????LoginHelper.Login -> LoginHelper.LoginNew
4.客戶端發(fā)送接收消息??? ??
????此時(shí) LoginHelper.LoginNew() 還不存在,找到ET/Unity/Unity.Hotfix/Assets/Scripts/
Codes/Hotfix/Client/Demo/Login/LoginHelper.cs,在里面添加一個(gè)新的方法:
5.編寫協(xié)議?
????此時(shí)C2R_LoginNew 和?R2C_LoginNew 不存在。如圖1-14,找到 Assets/Config/Proto,右鍵在VsCode 的打開 OutMessage_C_10001.proto,這里編寫外網(wǎng)消息.

????在最底下添加下列代碼:?
? ? 如圖1-15 打開 ET.BuildEditor,點(diǎn)擊 Proto2CS,生成協(xié)議的 C# 代碼。此時(shí)?LoginHelper 中的?C2R_LoginNew 和?R2C_LoginNew 將不報(bào)錯(cuò).

二.服務(wù)端
1.發(fā)送接收消息? ??
????如圖2-1,打開 ET/Unity/Unity.Hotfix/Assets/Scripts/Codes/Hotfix/Server/Demo/
Scenes/Realm,拷貝C2R_LoginHandler -> C2RLoginNewHandler

????更改相應(yīng)名字,刪除內(nèi)部實(shí)現(xiàn),替換為:
????response.Message = "這是一條服務(wù)器消息";
????await ETTask.CompletedTask;
????至此,所有代碼均編寫完成,返回 Unity ,點(diǎn)擊??ET.BuildEditor 的 BuildModelAndHotfix 按鈕,重寫編譯程序.
????點(diǎn)擊運(yùn)行,點(diǎn)擊登錄按鈕,如圖2-2:即可在控制臺看到客戶端與服務(wù)器的消息傳輸,并成功在客戶端接收到服務(wù)器的消息反饋

