fix:编辑器文件导入. add:example,runtime

This commit is contained in:
YipLee
2021-01-24 19:29:37 +08:00
parent c232a91a41
commit 91f4d8011b
214 changed files with 41328 additions and 120 deletions

View File

@@ -0,0 +1,63 @@
import { Component, EventKeyboard, macro, misc, SystemEvent, systemEvent, _decorator } from 'cc';
import AnimatorAnimation from '../../animator/AnimatorAnimation';
const { ccclass, property } = _decorator;
@ccclass('Sheep')
export class Sheep extends Component {
public _animator: AnimatorAnimation = null!;
public speed: number = 0;
protected start() {
this._animator = this.getComponent(AnimatorAnimation)!;
systemEvent.on(SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
systemEvent.on(SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
}
protected update(dt: number) {
let delt = this._animator.curStateName === 'sheep_hit' ? 0 : this.speed * -this._animator.node.scale.x * dt;
let x = misc.clampf(this._animator.node.position.x + delt, -1000, 1000);
this._animator.node.setPosition(x, this._animator.node.position.y, this._animator.node.position.z);
}
protected lateUpdate() {
this._animator.setNumber('speed', this.speed);
this._animator.manualUpdate();
}
protected onDestroy() {
systemEvent.off(SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
systemEvent.off(SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
}
private onKeyDown(event: EventKeyboard) {
let code: number = event.keyCode;
switch (code) {
case macro.KEY.left:
this._animator.node.setScale(1, this._animator.node.scale.y, this._animator.node.scale.z);
this.speed = 100;
break;
case macro.KEY.right:
this._animator.node.setScale(-1, this._animator.node.scale.y, this._animator.node.scale.z);
this.speed = 100;
break;
case macro.KEY.k:
this._animator.setTrigger('hit');
default:
break;
}
}
private onKeyUp(event: EventKeyboard) {
let code: number = event.keyCode;
switch (code) {
case macro.KEY.left:
case macro.KEY.right:
this.speed = 0;
break;
default:
break;
}
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.21",
"importer": "typescript",
"imported": true,
"uuid": "af622b40-cc81-43ee-92f4-6914165ddaea",
"files": [],
"subMetas": {},
"userData": {}
}