From 1606c28b5cbd4ebeb595aa8a06eae6d86b3e8cc4 Mon Sep 17 00:00:00 2001 From: JianMiau Date: Mon, 29 Aug 2022 15:17:11 +0800 Subject: [PATCH] [add] Set CocosBridge(Cocos to Web) --- .../CatanEngine/CSharp/System/Action.ts | 250 ++++++------- .../CSharp/System/ActionExample.ts | 168 ++++----- .../CSharp/System/ActionWithType.ts | 332 +++++++++--------- .../CSharp/System/ActionWithType2.ts | 332 +++++++++--------- .../CSharp/System/System_Eevent.ts | 9 + .../CSharp/System/System_Eevent.ts.meta | 10 + .../CSharp/System/Text/Encoding.ts | 170 ++++----- 7 files changed, 645 insertions(+), 626 deletions(-) create mode 100644 assets/Script/Engine/CatanEngine/CSharp/System/System_Eevent.ts create mode 100644 assets/Script/Engine/CatanEngine/CSharp/System/System_Eevent.ts.meta diff --git a/assets/Script/Engine/CatanEngine/CSharp/System/Action.ts b/assets/Script/Engine/CatanEngine/CSharp/System/Action.ts index e681833..d00d7cf 100644 --- a/assets/Script/Engine/CatanEngine/CSharp/System/Action.ts +++ b/assets/Script/Engine/CatanEngine/CSharp/System/Action.ts @@ -1,125 +1,125 @@ -/** - * 回呼函數: fnname (arg: TArg): void - */ -interface ActionCallback { - (arg: TArg): void; -} - -interface Struct { - callback: ActionCallback; - target: any; - once?: boolean; -} - -export class Action { - private _queue: Struct[] = []; - - /** - * 監聽事件 - * @param callback 回呼函數: fnname (arg: TArg): void - * @param bindTarget 回呼時this綁定的對象 - */ - AddCallback(callback: ActionCallback, bindTarget?: any) { - let q = > { - callback: callback, - target: bindTarget - }; - this._queue.push(q); - } - - /** - * 監聽事件 (一次性) - * @param callback 回呼函數: fnname (arg: TArg): void - * @param bindTarget 回呼時this綁定的對象 - */ - AddCallbackOnce(callback: ActionCallback, bindTarget?: any) { - let q = > { - callback: callback, - target: bindTarget, - once: true - }; - this._queue.push(q); - } - - /** - * 移除事件 - * @param callback - */ - RemoveByCallback(callback: ActionCallback) { - let index = this._queue.length; - if (index > 0) { - while (index--) { - let q = this._queue[index]; - if (!q.callback || q.callback === callback) { - q.callback = undefined; - this._queue.splice(index, 1); - } - } - } - } - - /** - * 移除事件 - * @param bindTarget 回呼時this綁定的對象 - */ - RemoveByBindTarget(bindTarget: any) { - let index = this._queue.length; - if (index > 0) { - while (index--) { - let q = this._queue[index]; - if (!q.callback || q.target === bindTarget) { - q.callback = undefined; - this._queue.splice(index, 1); - } - } - } - } - - /** - * 移除全部事件 - */ - RemoveAllCallbacks() { - this._queue.forEach(q => q.callback = undefined); - this._queue.length = 0; - } - - /** - * 發送事件 - * @param arg 參數 - */ - DispatchCallback(arg: TArg) { - let index = this._queue.length; - if (index > 0) { - let cleanRemoved = false; - this._queue.slice().forEach(q => { - if (!q.callback) { - cleanRemoved = true; - return; - } - - if (q.target) { - q.callback.call(q.target, arg); - } else { - q.callback(arg); - } - - if (q.once) { - q.callback = undefined; - cleanRemoved = true; - } - }); - - if (cleanRemoved) { - index = this._queue.length; - if (index > 0) { - while (index--) { - let q = this._queue[index]; - if (!q.callback) { - this._queue.splice(index, 1); - } - } - } - } - } - } -} +/** + * 回呼函數: fnname (arg: TArg): void + */ +interface ActionCallback { + (arg: TArg): void; +} + +interface Struct { + callback: ActionCallback; + target: any; + once?: boolean; +} + +export class Action { + private _queue: Struct[] = []; + + /** + * 監聽事件 + * @param callback 回呼函數: fnname (arg: TArg): void + * @param bindTarget 回呼時this綁定的對象 + */ + AddCallback(callback: ActionCallback, bindTarget?: any) { + let q = > { + callback: callback, + target: bindTarget + }; + this._queue.push(q); + } + + /** + * 監聽事件 (一次性) + * @param callback 回呼函數: fnname (arg: TArg): void + * @param bindTarget 回呼時this綁定的對象 + */ + AddCallbackOnce(callback: ActionCallback, bindTarget?: any) { + let q = > { + callback: callback, + target: bindTarget, + once: true + }; + this._queue.push(q); + } + + /** + * 移除事件 + * @param callback + */ + RemoveByCallback(callback: ActionCallback) { + let index = this._queue.length; + if (index > 0) { + while (index--) { + let q = this._queue[index]; + if (!q.callback || q.callback === callback) { + q.callback = undefined; + this._queue.splice(index, 1); + } + } + } + } + + /** + * 移除事件 + * @param bindTarget 回呼時this綁定的對象 + */ + RemoveByBindTarget(bindTarget: any) { + let index = this._queue.length; + if (index > 0) { + while (index--) { + let q = this._queue[index]; + if (!q.callback || q.target === bindTarget) { + q.callback = undefined; + this._queue.splice(index, 1); + } + } + } + } + + /** + * 移除全部事件 + */ + RemoveAllCallbacks() { + this._queue.forEach(q => q.callback = undefined); + this._queue.length = 0; + } + + /** + * 發送事件 + * @param arg 參數 + */ + DispatchCallback(arg: TArg) { + let index = this._queue.length; + if (index > 0) { + let cleanRemoved = false; + this._queue.slice().forEach(q => { + if (!q.callback) { + cleanRemoved = true; + return; + } + + if (q.target) { + q.callback.call(q.target, arg); + } else { + q.callback(arg); + } + + if (q.once) { + q.callback = undefined; + cleanRemoved = true; + } + }); + + if (cleanRemoved) { + index = this._queue.length; + if (index > 0) { + while (index--) { + let q = this._queue[index]; + if (!q.callback) { + this._queue.splice(index, 1); + } + } + } + } + } + } +} diff --git a/assets/Script/Engine/CatanEngine/CSharp/System/ActionExample.ts b/assets/Script/Engine/CatanEngine/CSharp/System/ActionExample.ts index 90196d5..c49a810 100644 --- a/assets/Script/Engine/CatanEngine/CSharp/System/ActionExample.ts +++ b/assets/Script/Engine/CatanEngine/CSharp/System/ActionExample.ts @@ -1,85 +1,85 @@ -import { Action } from "./Action"; -import { ActionWithType } from "./ActionWithType"; -import { ActionWithType2 } from "./ActionWithType2"; - -const {ccclass, property} = cc._decorator; - -enum CustomType { - Ex1, Ex2 -} - -class CustomEvent extends ActionWithType {} -class CustomEvent2 extends ActionWithType2 {} - -@ccclass -export default class NewClass extends cc.Component { - callback: Action = new Action(); - customCallback: CustomEvent = new CustomEvent(); - customCallback2: CustomEvent2 = new CustomEvent2(); - - private num: number = 0; - - start () { - this.callback.AddCallback(this.CB, this); - this.callback.AddCallbackOnce(this.OnceCB, this); - - this.customCallback.AddCallback(CustomType.Ex1, this.CBType, this); - this.customCallback.AddCallbackOnce(CustomType.Ex2, this.OnceCBType, this); - - this.customCallback2.AddCallback(CustomType.Ex2, this.CBTypeAllin1, this); - this.customCallback2.AddCallbackOnce(CustomType.Ex1, this.CBTypeAllin1, this); - } - - DispatchClick() { - this.num++; - - this.callback.DispatchCallback(this.num); - - this.customCallback.DispatchCallback(CustomType.Ex1, this.num); - this.customCallback.DispatchCallback(CustomType.Ex2, this.num); - - this.customCallback2.DispatchCallback(CustomType.Ex1, this.num); - this.customCallback2.DispatchCallback(CustomType.Ex2, this.num); - } - - RemoveEventClick() { - this.callback.RemoveByCallback(this.CB); - // this.callback.RemoveByCallback(this.OnceCB); - // this.callback.RemoveByBindTarget(this); - // this.callback.RemoveAll(); - - // this.callbackWithType.RemoveByCallback(this.CBType); - // this.callbackWithType.RemoveByCallback(this.OnceCBType); - this.customCallback.RemoveByType(CustomType.Ex1); - // this.callbackWithType.RemoveByType(CustomType.Ex2); - // this.callbackWithType.RemoveByBindTarget(this); - // this.callbackWithType.RemoveAll(); - } - - OnceCB(x: number) { - cc.log(`OnceCB [${this.num}]`); - } - - CB(x: number) { - cc.log(`CB [${this.num}]`); - } - - OnceCBType(x: number) { - cc.log(`OnceCBType [${this.num}]`); - } - - CBType(x: number) { - cc.log(`CBType [${this.num}]`); - } - - CBTypeAllin1(type: CustomType,x: number) { - // switch (type) { - // case CustomType.Ex1: - // break; - // case CustomType.Ex2: - // break; - // } - - cc.log(`CBTypeAllin1 [${CustomType[type]}][${this.num}]`); - } +import { Action } from "./Action"; +import { ActionWithType } from "./ActionWithType"; +import { ActionWithType2 } from "./ActionWithType2"; + +const {ccclass, property} = cc._decorator; + +enum CustomType { + Ex1, Ex2 +} + +class CustomEvent extends ActionWithType {} +class CustomEvent2 extends ActionWithType2 {} + +@ccclass +export default class NewClass extends cc.Component { + callback: Action = new Action(); + customCallback: CustomEvent = new CustomEvent(); + customCallback2: CustomEvent2 = new CustomEvent2(); + + private num: number = 0; + + start () { + this.callback.AddCallback(this.CB, this); + this.callback.AddCallbackOnce(this.OnceCB, this); + + this.customCallback.AddCallback(CustomType.Ex1, this.CBType, this); + this.customCallback.AddCallbackOnce(CustomType.Ex2, this.OnceCBType, this); + + this.customCallback2.AddCallback(CustomType.Ex2, this.CBTypeAllin1, this); + this.customCallback2.AddCallbackOnce(CustomType.Ex1, this.CBTypeAllin1, this); + } + + DispatchClick() { + this.num++; + + this.callback.DispatchCallback(this.num); + + this.customCallback.DispatchCallback(CustomType.Ex1, this.num); + this.customCallback.DispatchCallback(CustomType.Ex2, this.num); + + this.customCallback2.DispatchCallback(CustomType.Ex1, this.num); + this.customCallback2.DispatchCallback(CustomType.Ex2, this.num); + } + + RemoveEventClick() { + this.callback.RemoveByCallback(this.CB); + // this.callback.RemoveByCallback(this.OnceCB); + // this.callback.RemoveByBindTarget(this); + // this.callback.RemoveAll(); + + // this.callbackWithType.RemoveByCallback(this.CBType); + // this.callbackWithType.RemoveByCallback(this.OnceCBType); + this.customCallback.RemoveByType(CustomType.Ex1); + // this.callbackWithType.RemoveByType(CustomType.Ex2); + // this.callbackWithType.RemoveByBindTarget(this); + // this.callbackWithType.RemoveAll(); + } + + OnceCB(x: number) { + cc.log(`OnceCB [${this.num}]`); + } + + CB(x: number) { + cc.log(`CB [${this.num}]`); + } + + OnceCBType(x: number) { + cc.log(`OnceCBType [${this.num}]`); + } + + CBType(x: number) { + cc.log(`CBType [${this.num}]`); + } + + CBTypeAllin1(type: CustomType,x: number) { + // switch (type) { + // case CustomType.Ex1: + // break; + // case CustomType.Ex2: + // break; + // } + + cc.log(`CBTypeAllin1 [${CustomType[type]}][${this.num}]`); + } } \ No newline at end of file diff --git a/assets/Script/Engine/CatanEngine/CSharp/System/ActionWithType.ts b/assets/Script/Engine/CatanEngine/CSharp/System/ActionWithType.ts index 1a078ee..81248da 100644 --- a/assets/Script/Engine/CatanEngine/CSharp/System/ActionWithType.ts +++ b/assets/Script/Engine/CatanEngine/CSharp/System/ActionWithType.ts @@ -1,166 +1,166 @@ -/** - * 回呼函數: fnname (arg: TArg): void - */ -interface ActionCallback { - (arg: TArg): void; -} - -interface Struct { - callback: ActionCallback; - target: any; - type: TType; - once?: boolean; -} - -export class ActionWithType { - private _queue: Struct[] = []; - - /** - * 監聽事件 - * @param callback 回呼函數: fnname (arg: TArg): void - * @param bindTarget 回呼時this綁定的對象 - */ - AddCallback(type: TType, callback: ActionCallback, bindTarget?: any) { - let q = > { - callback: callback, - target: bindTarget, - type: type - }; - this._queue.push(q); - } - - /** - * 監聽事件 (一次性) - * @param callback 回呼函數: fnname (arg: TArg): void - * @param bindTarget 回呼時this綁定的對象 - */ - AddCallbackOnce(type: TType, callback: ActionCallback, bindTarget?: any) { - let q = > { - callback: callback, - target: bindTarget, - type: type, - once: true - }; - this._queue.push(q); - } - - /** - * 移除事件 - * @param callback - */ - RemoveByCallback(callback: ActionCallback) { - let index = this._queue.length; - if (index > 0) { - while (index--) { - let q = this._queue[index]; - if (!q.callback || q.callback === callback) { - q.callback = undefined; - this._queue.splice(index, 1); - } - } - } - } - - /** - * 移除事件 - * @param bindTarget 回呼時this綁定的對象 - */ - RemoveByBindTarget(bindTarget: any) { - let index = this._queue.length; - if (index > 0) { - while (index--) { - let q = this._queue[index]; - if (!q.callback || q.target === bindTarget) { - q.callback = undefined; - this._queue.splice(index, 1); - } - } - } - } - - /** - * 移除事件 - * @param type 事件類型 - */ - RemoveByType(type: TType) { - let index = this._queue.length; - if (index > 0) { - while (index--) { - let q = this._queue[index]; - if (!q.callback || q.type === type) { - q.callback = undefined; - this._queue.splice(index, 1); - } - } - } - } - - /** - * 移除事件 - * @param type 事件類型 - * @param callback - */ - RemoveCallback(type:TType, callback: ActionCallback) { - let index = this._queue.length; - if (index > 0) { - while (index--) { - let q = this._queue[index]; - if (!q.callback || (q.type === type && q.callback === callback)) { - q.callback = undefined; - this._queue.splice(index, 1); - } - } - } - } - - /** - * 移除全部事件 - */ - RemoveAllCallbacks() { - this._queue.forEach(q => q.callback = undefined); - this._queue.length = 0; - } - - /** - * 發送事件 - * @param type 事件類型 - * @param arg 參數 - */ - DispatchCallback(type: TType, arg: TArg) { - let index = this._queue.length; - if (index > 0) { - let cleanRemoved = false; - this._queue.slice().forEach(q => { - if (!q.callback) - { - cleanRemoved = true; - return; - } - if (q.type !== type) return; - - if (q.target) { - q.callback.call(q.target, arg); - } else { - q.callback(arg); - } - - if (q.once) { - q.callback = undefined; - cleanRemoved = true; - } - }); - - if (cleanRemoved) { - index = this._queue.length; - if (index > 0) { - while (index--) { - let q = this._queue[index]; - if (!q.callback) { - this._queue.splice(index, 1); - } - } - } - } - } - } -} +/** + * 回呼函數: fnname (arg: TArg): void + */ +interface ActionCallback { + (arg: TArg): void; +} + +interface Struct { + callback: ActionCallback; + target: any; + type: TType; + once?: boolean; +} + +export class ActionWithType { + private _queue: Struct[] = []; + + /** + * 監聽事件 + * @param callback 回呼函數: fnname (arg: TArg): void + * @param bindTarget 回呼時this綁定的對象 + */ + AddCallback(type: TType, callback: ActionCallback, bindTarget?: any) { + let q = > { + callback: callback, + target: bindTarget, + type: type + }; + this._queue.push(q); + } + + /** + * 監聽事件 (一次性) + * @param callback 回呼函數: fnname (arg: TArg): void + * @param bindTarget 回呼時this綁定的對象 + */ + AddCallbackOnce(type: TType, callback: ActionCallback, bindTarget?: any) { + let q = > { + callback: callback, + target: bindTarget, + type: type, + once: true + }; + this._queue.push(q); + } + + /** + * 移除事件 + * @param callback + */ + RemoveByCallback(callback: ActionCallback) { + let index = this._queue.length; + if (index > 0) { + while (index--) { + let q = this._queue[index]; + if (!q.callback || q.callback === callback) { + q.callback = undefined; + this._queue.splice(index, 1); + } + } + } + } + + /** + * 移除事件 + * @param bindTarget 回呼時this綁定的對象 + */ + RemoveByBindTarget(bindTarget: any) { + let index = this._queue.length; + if (index > 0) { + while (index--) { + let q = this._queue[index]; + if (!q.callback || q.target === bindTarget) { + q.callback = undefined; + this._queue.splice(index, 1); + } + } + } + } + + /** + * 移除事件 + * @param type 事件類型 + */ + RemoveByType(type: TType) { + let index = this._queue.length; + if (index > 0) { + while (index--) { + let q = this._queue[index]; + if (!q.callback || q.type === type) { + q.callback = undefined; + this._queue.splice(index, 1); + } + } + } + } + + /** + * 移除事件 + * @param type 事件類型 + * @param callback + */ + RemoveCallback(type:TType, callback: ActionCallback) { + let index = this._queue.length; + if (index > 0) { + while (index--) { + let q = this._queue[index]; + if (!q.callback || (q.type === type && q.callback === callback)) { + q.callback = undefined; + this._queue.splice(index, 1); + } + } + } + } + + /** + * 移除全部事件 + */ + RemoveAllCallbacks() { + this._queue.forEach(q => q.callback = undefined); + this._queue.length = 0; + } + + /** + * 發送事件 + * @param type 事件類型 + * @param arg 參數 + */ + DispatchCallback(type: TType, arg: TArg) { + let index = this._queue.length; + if (index > 0) { + let cleanRemoved = false; + this._queue.slice().forEach(q => { + if (!q.callback) + { + cleanRemoved = true; + return; + } + if (q.type !== type) return; + + if (q.target) { + q.callback.call(q.target, arg); + } else { + q.callback(arg); + } + + if (q.once) { + q.callback = undefined; + cleanRemoved = true; + } + }); + + if (cleanRemoved) { + index = this._queue.length; + if (index > 0) { + while (index--) { + let q = this._queue[index]; + if (!q.callback) { + this._queue.splice(index, 1); + } + } + } + } + } + } +} diff --git a/assets/Script/Engine/CatanEngine/CSharp/System/ActionWithType2.ts b/assets/Script/Engine/CatanEngine/CSharp/System/ActionWithType2.ts index 33e8c75..1b68673 100644 --- a/assets/Script/Engine/CatanEngine/CSharp/System/ActionWithType2.ts +++ b/assets/Script/Engine/CatanEngine/CSharp/System/ActionWithType2.ts @@ -1,166 +1,166 @@ -/** - * 回呼函數: fnname (type: TType, arg: TArg): void - */ -interface ActionCallback { - (type: TType, arg: TArg): void; -} - -interface Struct { - callback: ActionCallback; - target: any; - type: TType; - once?: boolean; -} - -export class ActionWithType2 { - private _queue: Struct[] = []; - - /** - * 監聽事件 - * @param callback 回呼函數: fnname (type: TType, arg: TArg): void - * @param bindTarget 回呼時this綁定的對象 - */ - AddCallback(type: TType, callback: ActionCallback, bindTarget?: any) { - let q = > { - callback: callback, - target: bindTarget, - type: type - }; - this._queue.push(q); - } - - /** - * 監聽事件 (一次性) - * @param callback 回呼函數: fnname (type: TType, arg: TArg): void - * @param bindTarget 回呼時this綁定的對象 - */ - AddCallbackOnce(type: TType, callback: ActionCallback, bindTarget?: any) { - let q = > { - callback: callback, - target: bindTarget, - type: type, - once: true - }; - this._queue.push(q); - } - - /** - * 移除事件 - * @param callback - */ - RemoveByCallback(callback: ActionCallback) { - let index = this._queue.length; - if (index > 0) { - while (index--) { - let q = this._queue[index]; - if (!q.callback || q.callback === callback) { - q.callback = undefined; - this._queue.splice(index, 1); - } - } - } - } - - /** - * 移除事件 - * @param bindTarget 回呼時this綁定的對象 - */ - RemoveByBindTarget(bindTarget: any) { - let index = this._queue.length; - if (index > 0) { - while (index--) { - let q = this._queue[index]; - if (!q.callback || q.target === bindTarget) { - q.callback = undefined; - this._queue.splice(index, 1); - } - } - } - } - - /** - * 移除事件 - * @param type 事件類型 - */ - RemoveByType(type: TType) { - let index = this._queue.length; - if (index > 0) { - while (index--) { - let q = this._queue[index]; - if (!q.callback || q.type === type) { - q.callback = undefined; - this._queue.splice(index, 1); - } - } - } - } - - /** - * 移除事件 - * @param type 事件類型 - * @param callback - */ - RemoveCallback(type:TType, callback: ActionCallback) { - let index = this._queue.length; - if (index > 0) { - while (index--) { - let q = this._queue[index]; - if (!q.callback || (q.type === type && q.callback === callback)) { - q.callback = undefined; - this._queue.splice(index, 1); - } - } - } - } - - /** - * 移除全部事件 - */ - RemoveAllCallbacks() { - this._queue.forEach(q => q.callback = undefined); - this._queue.length = 0; - } - - /** - * 發送事件 - * @param type 事件類型 - * @param arg 參數 - */ - DispatchCallback(type: TType, arg: TArg) { - let index = this._queue.length; - if (index > 0) { - let cleanRemoved = false; - this._queue.slice().forEach(q => { - if (!q.callback) - { - cleanRemoved = true; - return; - } - if (q.type !== type) return; - - if (q.target) { - q.callback.call(q.target, type, arg); - } else { - q.callback(type, arg); - } - - if (q.once) { - q.callback = undefined; - cleanRemoved = true; - } - }); - - if (cleanRemoved) { - index = this._queue.length; - if (index > 0) { - while (index--) { - let q = this._queue[index]; - if (!q.callback) { - this._queue.splice(index, 1); - } - } - } - } - } - } -} +/** + * 回呼函數: fnname (type: TType, arg: TArg): void + */ +interface ActionCallback { + (type: TType, arg: TArg): void; +} + +interface Struct { + callback: ActionCallback; + target: any; + type: TType; + once?: boolean; +} + +export class ActionWithType2 { + private _queue: Struct[] = []; + + /** + * 監聽事件 + * @param callback 回呼函數: fnname (type: TType, arg: TArg): void + * @param bindTarget 回呼時this綁定的對象 + */ + AddCallback(type: TType, callback: ActionCallback, bindTarget?: any) { + let q = > { + callback: callback, + target: bindTarget, + type: type + }; + this._queue.push(q); + } + + /** + * 監聽事件 (一次性) + * @param callback 回呼函數: fnname (type: TType, arg: TArg): void + * @param bindTarget 回呼時this綁定的對象 + */ + AddCallbackOnce(type: TType, callback: ActionCallback, bindTarget?: any) { + let q = > { + callback: callback, + target: bindTarget, + type: type, + once: true + }; + this._queue.push(q); + } + + /** + * 移除事件 + * @param callback + */ + RemoveByCallback(callback: ActionCallback) { + let index = this._queue.length; + if (index > 0) { + while (index--) { + let q = this._queue[index]; + if (!q.callback || q.callback === callback) { + q.callback = undefined; + this._queue.splice(index, 1); + } + } + } + } + + /** + * 移除事件 + * @param bindTarget 回呼時this綁定的對象 + */ + RemoveByBindTarget(bindTarget: any) { + let index = this._queue.length; + if (index > 0) { + while (index--) { + let q = this._queue[index]; + if (!q.callback || q.target === bindTarget) { + q.callback = undefined; + this._queue.splice(index, 1); + } + } + } + } + + /** + * 移除事件 + * @param type 事件類型 + */ + RemoveByType(type: TType) { + let index = this._queue.length; + if (index > 0) { + while (index--) { + let q = this._queue[index]; + if (!q.callback || q.type === type) { + q.callback = undefined; + this._queue.splice(index, 1); + } + } + } + } + + /** + * 移除事件 + * @param type 事件類型 + * @param callback + */ + RemoveCallback(type:TType, callback: ActionCallback) { + let index = this._queue.length; + if (index > 0) { + while (index--) { + let q = this._queue[index]; + if (!q.callback || (q.type === type && q.callback === callback)) { + q.callback = undefined; + this._queue.splice(index, 1); + } + } + } + } + + /** + * 移除全部事件 + */ + RemoveAllCallbacks() { + this._queue.forEach(q => q.callback = undefined); + this._queue.length = 0; + } + + /** + * 發送事件 + * @param type 事件類型 + * @param arg 參數 + */ + DispatchCallback(type: TType, arg: TArg) { + let index = this._queue.length; + if (index > 0) { + let cleanRemoved = false; + this._queue.slice().forEach(q => { + if (!q.callback) + { + cleanRemoved = true; + return; + } + if (q.type !== type) return; + + if (q.target) { + q.callback.call(q.target, type, arg); + } else { + q.callback(type, arg); + } + + if (q.once) { + q.callback = undefined; + cleanRemoved = true; + } + }); + + if (cleanRemoved) { + index = this._queue.length; + if (index > 0) { + while (index--) { + let q = this._queue[index]; + if (!q.callback) { + this._queue.splice(index, 1); + } + } + } + } + } + } +} diff --git a/assets/Script/Engine/CatanEngine/CSharp/System/System_Eevent.ts b/assets/Script/Engine/CatanEngine/CSharp/System/System_Eevent.ts new file mode 100644 index 0000000..797c87c --- /dev/null +++ b/assets/Script/Engine/CatanEngine/CSharp/System/System_Eevent.ts @@ -0,0 +1,9 @@ + +/** System類型 */ +export enum System_Eevent { + /** SetFCMToken */ + SetFCMToken, + + /** Test */ + Test +} \ No newline at end of file diff --git a/assets/Script/Engine/CatanEngine/CSharp/System/System_Eevent.ts.meta b/assets/Script/Engine/CatanEngine/CSharp/System/System_Eevent.ts.meta new file mode 100644 index 0000000..47c057a --- /dev/null +++ b/assets/Script/Engine/CatanEngine/CSharp/System/System_Eevent.ts.meta @@ -0,0 +1,10 @@ +{ + "ver": "1.1.0", + "uuid": "f0d14145-1175-48fa-b591-4b98f59a0e04", + "importer": "typescript", + "isPlugin": false, + "loadPluginInWeb": true, + "loadPluginInNative": true, + "loadPluginInEditor": false, + "subMetas": {} +} \ No newline at end of file diff --git a/assets/Script/Engine/CatanEngine/CSharp/System/Text/Encoding.ts b/assets/Script/Engine/CatanEngine/CSharp/System/Text/Encoding.ts index bf63568..cea6877 100644 --- a/assets/Script/Engine/CatanEngine/CSharp/System/Text/Encoding.ts +++ b/assets/Script/Engine/CatanEngine/CSharp/System/Text/Encoding.ts @@ -1,86 +1,86 @@ -export module Encoding.UTF8 { - - export function GetBytes(str: string) { - let len = str.length, resPos = -1; - let resArr = new Uint8Array(len * 3); - for (let point = 0, nextcode = 0, i = 0; i !== len;) { - point = str.charCodeAt(i), i += 1; - if (point >= 0xD800 && point <= 0xDBFF) { - if (i === len) { - resArr[resPos += 1] = 0xef; - resArr[resPos += 1] = 0xbf; - resArr[resPos += 1] = 0xbd; - break; - } - - nextcode = str.charCodeAt(i); - if (nextcode >= 0xDC00 && nextcode <= 0xDFFF) { - point = (point - 0xD800) * 0x400 + nextcode - 0xDC00 + 0x10000; - i += 1; - if (point > 0xffff) { - resArr[resPos += 1] = (0x1e << 3) | (point >>> 18); - resArr[resPos += 1] = (0x2 << 6) | ((point >>> 12) & 0x3f); - resArr[resPos += 1] = (0x2 << 6) | ((point >>> 6) & 0x3f); - resArr[resPos += 1] = (0x2 << 6) | (point & 0x3f); - continue; - } - } else { - resArr[resPos += 1] = 0xef; - resArr[resPos += 1] = 0xbf; - resArr[resPos += 1] = 0xbd; - continue; - } - } - if (point <= 0x007f) { - resArr[resPos += 1] = (0x0 << 7) | point; - } else if (point <= 0x07ff) { - resArr[resPos += 1] = (0x6 << 5) | (point >>> 6); - resArr[resPos += 1] = (0x2 << 6) | (point & 0x3f); - } else { - resArr[resPos += 1] = (0xe << 4) | (point >>> 12); - resArr[resPos += 1] = (0x2 << 6) | ((point >>> 6) & 0x3f); - resArr[resPos += 1] = (0x2 << 6) | (point & 0x3f); - } - } - return resArr.subarray(0, resPos + 1); - } - - export function GetString(array: Uint8Array) { - let str = ""; - let i = 0, len = array.length; - while (i < len) { - let c = array[i++]; - switch (c >> 4) { - case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: - str += String.fromCharCode(c); - break; - case 12: case 13: - str += String.fromCharCode(((c & 0x1F) << 6) | (array[i++] & 0x3F)); - break; - case 14: - str += String.fromCharCode(((c & 0x0F) << 12) | ((array[i++] & 0x3F) << 6) | ((array[i++] & 0x3F) << 0)); - break; - } - } - return str; - } - - export function b64EncodeUnicode(str) { - return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) { - return String.fromCharCode('0x' + p1); - })); - } - export function b64DecodeUnicode(str) { - return decodeURIComponent(atob(str).split('').map(function (c) { - return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); - }).join('')); - } - export function isBase64(str) { - if (str === '' || str.trim() === '') { return false; } - try { - return btoa(atob(str)) == str; - } catch (err) { - return false; - } - } +export module Encoding.UTF8 { + + export function GetBytes(str: string) { + let len = str.length, resPos = -1; + let resArr = new Uint8Array(len * 3); + for (let point = 0, nextcode = 0, i = 0; i !== len;) { + point = str.charCodeAt(i), i += 1; + if (point >= 0xD800 && point <= 0xDBFF) { + if (i === len) { + resArr[resPos += 1] = 0xef; + resArr[resPos += 1] = 0xbf; + resArr[resPos += 1] = 0xbd; + break; + } + + nextcode = str.charCodeAt(i); + if (nextcode >= 0xDC00 && nextcode <= 0xDFFF) { + point = (point - 0xD800) * 0x400 + nextcode - 0xDC00 + 0x10000; + i += 1; + if (point > 0xffff) { + resArr[resPos += 1] = (0x1e << 3) | (point >>> 18); + resArr[resPos += 1] = (0x2 << 6) | ((point >>> 12) & 0x3f); + resArr[resPos += 1] = (0x2 << 6) | ((point >>> 6) & 0x3f); + resArr[resPos += 1] = (0x2 << 6) | (point & 0x3f); + continue; + } + } else { + resArr[resPos += 1] = 0xef; + resArr[resPos += 1] = 0xbf; + resArr[resPos += 1] = 0xbd; + continue; + } + } + if (point <= 0x007f) { + resArr[resPos += 1] = (0x0 << 7) | point; + } else if (point <= 0x07ff) { + resArr[resPos += 1] = (0x6 << 5) | (point >>> 6); + resArr[resPos += 1] = (0x2 << 6) | (point & 0x3f); + } else { + resArr[resPos += 1] = (0xe << 4) | (point >>> 12); + resArr[resPos += 1] = (0x2 << 6) | ((point >>> 6) & 0x3f); + resArr[resPos += 1] = (0x2 << 6) | (point & 0x3f); + } + } + return resArr.subarray(0, resPos + 1); + } + + export function GetString(array: Uint8Array) { + let str = ""; + let i = 0, len = array.length; + while (i < len) { + let c = array[i++]; + switch (c >> 4) { + case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: + str += String.fromCharCode(c); + break; + case 12: case 13: + str += String.fromCharCode(((c & 0x1F) << 6) | (array[i++] & 0x3F)); + break; + case 14: + str += String.fromCharCode(((c & 0x0F) << 12) | ((array[i++] & 0x3F) << 6) | ((array[i++] & 0x3F) << 0)); + break; + } + } + return str; + } + + export function b64EncodeUnicode(str) { + return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) { + return String.fromCharCode('0x' + p1); + })); + } + export function b64DecodeUnicode(str) { + return decodeURIComponent(atob(str).split('').map(function (c) { + return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); + }).join('')); + } + export function isBase64(str) { + if (str === '' || str.trim() === '') { return false; } + try { + return btoa(atob(str)) == str; + } catch (err) { + return false; + } + } } \ No newline at end of file