fix:编辑器文件导入. add:example,runtime
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import AnimatorAnimation from "../../animator/AnimatorAnimation";
|
||||
import AnimatorStateLogic from "../../animator/core/AnimatorStateLogic";
|
||||
import SheepHit from "./SheepHit";
|
||||
import SheepIdle from "./SheepIdle";
|
||||
import SheepRun from "./SheepRun";
|
||||
|
||||
const { ccclass, property } = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
export default class AnimationScene extends cc.Component {
|
||||
@property(AnimatorAnimation) Animator: AnimatorAnimation = null;
|
||||
|
||||
public speed: number = 0;
|
||||
|
||||
protected onLoad() {
|
||||
let map: Map<string, AnimatorStateLogic> = new Map();
|
||||
map.set('sheep_idle', new SheepIdle());
|
||||
map.set('sheep_run', new SheepRun());
|
||||
map.set('sheep_hit', new SheepHit(this));
|
||||
this.Animator.onInit(map);
|
||||
|
||||
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
|
||||
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
|
||||
}
|
||||
|
||||
protected update(dt: number) {
|
||||
let delt = this.Animator.curStateName === 'sheep_hit' ? 0 : this.speed * -this.Animator.node.scaleX * dt;
|
||||
this.Animator.node.x = cc.misc.clampf(this.Animator.node.x + delt, -1000, 1000);
|
||||
}
|
||||
|
||||
protected lateUpdate() {
|
||||
this.Animator.setNumber('speed', this.speed);
|
||||
this.Animator.manualUpdate();
|
||||
}
|
||||
|
||||
protected onDestroy() {
|
||||
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
|
||||
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
|
||||
}
|
||||
|
||||
private onKeyDown(event: cc.Event.EventKeyboard) {
|
||||
let code: cc.macro.KEY = event.keyCode;
|
||||
switch (code) {
|
||||
case cc.macro.KEY.left:
|
||||
this.Animator.node.scaleX = 1;
|
||||
this.speed = 100;
|
||||
break;
|
||||
case cc.macro.KEY.right:
|
||||
this.Animator.node.scaleX = -1;
|
||||
this.speed = 100;
|
||||
break;
|
||||
case cc.macro.KEY.k:
|
||||
this.Animator.setTrigger('hit');
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private onKeyUp(event: cc.Event.EventKeyboard) {
|
||||
let code: cc.macro.KEY = event.keyCode;
|
||||
switch (code) {
|
||||
case cc.macro.KEY.left:
|
||||
case cc.macro.KEY.right:
|
||||
this.speed = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "14db7554-9454-4338-a487-150523459aca",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
import AnimatorStateLogic from "../../animator/core/AnimatorStateLogic";
|
||||
import AnimationScene from "./AnimationScene";
|
||||
|
||||
export default class SheepHit extends AnimatorStateLogic {
|
||||
private _ctr: AnimationScene = null;
|
||||
|
||||
public constructor(ctr: AnimationScene) {
|
||||
super();
|
||||
this._ctr = ctr;
|
||||
}
|
||||
|
||||
public onEntry() {
|
||||
this._ctr.speed = 0;
|
||||
cc.log('hit entry');
|
||||
}
|
||||
|
||||
public onUpdate() {
|
||||
this._ctr.speed = 0;
|
||||
cc.log('hit update');
|
||||
}
|
||||
|
||||
public onExit() {
|
||||
cc.log('hit exit');
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "b1e94d2a-165f-4350-8035-c4e0ce55221b",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
import AnimatorStateLogic from "../../animator/core/AnimatorStateLogic";
|
||||
|
||||
export default class SheepIdle extends AnimatorStateLogic {
|
||||
|
||||
public onEntry() {
|
||||
cc.log('idle entry');
|
||||
}
|
||||
|
||||
public onUpdate() {
|
||||
cc.log('idle update');
|
||||
}
|
||||
|
||||
public onExit() {
|
||||
cc.log('idle exit');
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "ffe798df-0253-48ab-bdcc-31b7c2ddc3c7",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
import AnimatorStateLogic from "../../animator/core/AnimatorStateLogic";
|
||||
|
||||
export default class SheepRun extends AnimatorStateLogic {
|
||||
|
||||
public onEntry() {
|
||||
cc.log('run entry');
|
||||
}
|
||||
|
||||
public onUpdate() {
|
||||
cc.log('run update');
|
||||
}
|
||||
|
||||
public onExit() {
|
||||
cc.log('run exit');
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "249d7306-946e-4f59-9446-b6ecc1d456a4",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
Reference in New Issue
Block a user