[add] Engine
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { CoroutineV2 } from "../../CoroutineV2/CoroutineV2";
|
||||
import { INetResponse } from "../Core/INetResponse";
|
||||
import { NetConnector } from "../NetConnector";
|
||||
import { NetManager } from "../NetManager";
|
||||
import { Slot1_SpinRequestExample } from "./Slot1_SpinRequestExample";
|
||||
|
||||
const {ccclass, property} = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
export default class NetTester extends cc.Component {
|
||||
|
||||
onConnectClicked() {
|
||||
CoroutineV2.StartCoroutine(this.ConnectAsync());
|
||||
}
|
||||
|
||||
*ConnectAsync() {
|
||||
if (!NetManager.HasInit) {
|
||||
let conn = new NetConnector("192.168.7.165", 9005);
|
||||
conn.OnDataReceived.AddCallback(this.OnNetDataReceived, this);
|
||||
conn.OnDisconnected.AddCallback(this.OnNetDisconnected, this);
|
||||
conn.OnLoadUIMask.AddCallback(this.OnLoadUIMask, this);
|
||||
|
||||
NetManager.Initialize(conn);
|
||||
}
|
||||
|
||||
cc.log("連線中...");
|
||||
yield NetManager.ConnectAsync(); // 同個connector要再次連線, 可以不用叫CasinoNetManager.Initialize(), 但要先叫CasinoNetManager.Disconnect()
|
||||
cc.log(`連線狀態: ${NetManager.IsConnected}`);
|
||||
}
|
||||
|
||||
onDisconnectClicked() {
|
||||
cc.log("中斷連線中...");
|
||||
NetManager.Disconnect(); // 中斷連線
|
||||
}
|
||||
|
||||
onSendMessageClicked1() {
|
||||
cc.log("發送訊息(不使用協程)");
|
||||
let req = new Slot1_SpinRequestExample(401);
|
||||
req.Send();
|
||||
// CasinoNetManager.Send(req);
|
||||
}
|
||||
|
||||
onSendMessageClicked2() {
|
||||
CoroutineV2.StartCoroutine(this.SendAsync());
|
||||
}
|
||||
|
||||
*SendAsync() {
|
||||
cc.log("發送訊息中(使用協程)...");
|
||||
let req = new Slot1_SpinRequestExample(399);
|
||||
yield req.SendAsync();
|
||||
// yield CasinoNetManager.SendAsync(req);
|
||||
|
||||
let resp = req.Result;
|
||||
cc.log(`發送協程完畢, Server回應: ${resp.Method}(${JSON.stringify(resp.Data)}), 狀態: ${resp.Status}`);
|
||||
// cc.log(`使用介面資料: ${resp.Data.slot}`);
|
||||
}
|
||||
|
||||
private OnNetDisconnected() {
|
||||
cc.log("[事件] 收到連線中斷事件");
|
||||
}
|
||||
|
||||
private OnNetDataReceived(resp: INetResponse<any>) {
|
||||
cc.log(`[事件] 收到server呼叫: ${resp.Method}(${JSON.stringify(resp.Data)}), 狀態: ${resp.Status}`);
|
||||
}
|
||||
|
||||
private OnLoadUIMask(value: boolean) {
|
||||
cc.log(`[事件] LoadUIMask: ${value}`);
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"uuid": "0cb7df7a-d0e7-4ce1-832e-4583cf3385e5",
|
||||
"importer": "typescript",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
import { NetRequest } from "../NetRequest";
|
||||
|
||||
// 送給server的結構
|
||||
interface Request {
|
||||
pay: number;
|
||||
}
|
||||
|
||||
// server回應的結構
|
||||
interface Response {
|
||||
pay: [[number, number]];
|
||||
/**拉霸結果 */
|
||||
slot: number[];
|
||||
get: any[];
|
||||
}
|
||||
|
||||
// class Account_CreateRequest extends CasinoRequest<number, any> { // 也可以是基本類或any, 但不建議用any, 使用介面ts才會有提示
|
||||
export class Slot1_SpinRequestExample extends NetRequest<Request, Response> {
|
||||
get Method(): string {
|
||||
return "slot1.spin";
|
||||
}
|
||||
|
||||
// MethodBack預設回傳Method, 不一樣才需要覆寫
|
||||
// get MethodBack(): string {
|
||||
// return "slot1.freespin";
|
||||
// }
|
||||
|
||||
constructor(totalBet: number) {
|
||||
super();
|
||||
|
||||
// 原本的SingleValue拿掉, 統一使用Data來存送出結構
|
||||
|
||||
// this.Data = 2;
|
||||
this.Data = {
|
||||
pay: totalBet,
|
||||
};
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"uuid": "1af9e6af-3dc3-4d02-8b24-481adc07932a",
|
||||
"importer": "typescript",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
Reference in New Issue
Block a user