[add] Engine
This commit is contained in:
44
assets/Script/Engine/Component/Editbox/EditboxEx.ts
Normal file
44
assets/Script/Engine/Component/Editbox/EditboxEx.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
const { ccclass, menu, requireComponent } = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
// @menu("Plug-in/EditBox/EditboxEx")
|
||||
@requireComponent(cc.EditBox)
|
||||
export default class EditboxEx extends cc.Component {
|
||||
|
||||
//#region private
|
||||
|
||||
private _worldPos: cc.Vec2 = null;
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region Lifecycle
|
||||
|
||||
protected onLoad(): void {
|
||||
if (CC_DEV || cc.sys.isNative) {
|
||||
let editbox: cc.EditBox = this.node.getComponent(cc.EditBox);
|
||||
this._worldPos = this.node.GetWorldPosition();
|
||||
editbox.node.on("editing-did-began", this._onEditDidBegan, this);
|
||||
editbox.node.on("editing-did-ended", this._onEditDidEnded, this);
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region EventListener
|
||||
|
||||
private _onEditDidBegan(editbox: cc.EditBox, customEventData: string): void {
|
||||
let winSizeHeight: number = cc.winSize.height;
|
||||
let nodeSizeHeight: number = this.node.height / 2;
|
||||
let targetHeight: number = winSizeHeight - nodeSizeHeight;
|
||||
let worldPos: cc.Vec2 = cc.v2(this.node.GetWorldPosition().x, targetHeight);
|
||||
this.node.SetWorldPosition(worldPos);
|
||||
}
|
||||
|
||||
// 假设这个回调是给 editingDidEnded 事件的
|
||||
private _onEditDidEnded(editbox: cc.EditBox, customEventData: string): void {
|
||||
this.node.SetWorldPosition(this._worldPos);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
}
|
10
assets/Script/Engine/Component/Editbox/EditboxEx.ts.meta
Normal file
10
assets/Script/Engine/Component/Editbox/EditboxEx.ts.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"uuid": "1e6b0467-4516-4f10-a876-473c8894ff17",
|
||||
"importer": "typescript",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
Reference in New Issue
Block a user