77 lines
2.0 KiB
JavaScript
77 lines
2.0 KiB
JavaScript
|
|
"use strict";
|
||
|
|
cc._RF.push(module, '14b424JkUVBqoi3t7IwZ+i4', 'nx.actor.suspending');
|
||
|
|
// Scripts/nx/cmp/actor/nx.actor.suspending.js
|
||
|
|
|
||
|
|
"use strict";
|
||
|
|
|
||
|
|
/******************************************************************
|
||
|
|
* Copyright(C) 2019 - 2020 Nx Studio
|
||
|
|
*
|
||
|
|
* NX 行为器插件 -- 悬浮
|
||
|
|
*
|
||
|
|
* 2018.05.18
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
var DEF_DELAY = 2;
|
||
|
|
var DEF_HEIGHT = 10;
|
||
|
|
cc.Class({
|
||
|
|
"extends": cc.Component,
|
||
|
|
properties: {
|
||
|
|
delay: {
|
||
|
|
"default": 0,
|
||
|
|
displayName: "随机时间(秒)"
|
||
|
|
},
|
||
|
|
height: {
|
||
|
|
"default": 0,
|
||
|
|
displayName: "浮动高度"
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 编辑器特性
|
||
|
|
editor: {
|
||
|
|
// 允许当前组件在编辑器模式下运行
|
||
|
|
executeInEditMode: false,
|
||
|
|
// requireComponent 参数用来指定当前组件的依赖组件
|
||
|
|
requireComponent: null,
|
||
|
|
// 当本组件添加到节点上后,禁止同类型(含子类)的组件再添加到同一个节点,防止逻辑发生冲突
|
||
|
|
disallowMultiple: true,
|
||
|
|
// menu 用来将当前组件添加到组件菜单中,方便用户查找
|
||
|
|
menu: "Nx/行为器|悬浮模拟"
|
||
|
|
},
|
||
|
|
// 显示
|
||
|
|
onLoad: function onLoad() {
|
||
|
|
// 原始位置
|
||
|
|
this.rawpos = this.node.position;
|
||
|
|
|
||
|
|
// 默认开始
|
||
|
|
if (this.delay > 0 && this.height > 0) {
|
||
|
|
this.start();
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 关闭
|
||
|
|
onDestroy: function onDestroy() {
|
||
|
|
this.stop();
|
||
|
|
},
|
||
|
|
// 开启
|
||
|
|
start: function start(_delay, _height) {
|
||
|
|
this.stop();
|
||
|
|
this.delay = _delay || DEF_DELAY;
|
||
|
|
this.height = _height || DEF_HEIGHT;
|
||
|
|
this.rawpos = this.rawpos || this.node.position;
|
||
|
|
var tar = cc.v2(this.rawpos.x, this.rawpos.y + this.height);
|
||
|
|
this.handler = cc.tween(this.node).repeatForever(cc.tween().delay(Math.random() * this.delay).to(1, {
|
||
|
|
position: tar
|
||
|
|
}).to(1, {
|
||
|
|
position: this.rawpos
|
||
|
|
})).start();
|
||
|
|
},
|
||
|
|
// 停止
|
||
|
|
stop: function stop() {
|
||
|
|
if (this.handler) {
|
||
|
|
this.handler.stop();
|
||
|
|
delete this.handler;
|
||
|
|
this.handler = null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
cc._RF.pop();
|