重命名物体事件。

This commit is contained in:
liteng 2018-06-17 09:22:34 +08:00
parent 84d659c5d1
commit b43df85df0
4 changed files with 39 additions and 7 deletions

View File

@ -61,11 +61,8 @@ Editor.prototype = {
this.app.call('moveObject', this, object, parent, before);
},
nameObject: function (object, name) {
object.name = name;
this.signals.sceneGraphChanged.dispatch();
nameObject: function (object, name) { // 重命名物体
this.app.call('nameObject', this, object, name);
},
removeObject: function (object) {

View File

@ -15,6 +15,7 @@ import SetThemeEvent from './editor/SetThemeEvent';
import SetSceneEvent from './editor/SetSceneEvent';
import AddObjectEvent from './editor/AddObjectEvent';
import MoveObjectEvent from './editor/MoveObjectEvent';
import NameObjectEvent from './editor/NameObjectEvent';
/**
* 事件执行器
@ -40,6 +41,7 @@ function EventDispatcher(app) {
new SetSceneEvent(this.app),
new AddObjectEvent(this.app),
new MoveObjectEvent(this.app),
new NameObjectEvent(this.app),
];
}

View File

@ -19,8 +19,9 @@ var EventList = [
// editor事件
'setTheme', // 设置编辑器主题
'setScene', // 设置编辑器场景
'addObject', //向编辑器添加物体
'moveObject', // 移动编辑器中的物体
'addObject', // 添加物体
'moveObject', // 移动物体
'nameObject', // 重命名物体
];
export default EventList;

View File

@ -0,0 +1,32 @@
import BaseEvent from '../BaseEvent';
/**
* 重命名物体事件
* @param {*} app
*/
function NameObjectEvent(app) {
BaseEvent.call(this, app);
}
NameObjectEvent.prototype = Object.create(BaseEvent.prototype);
NameObjectEvent.prototype.constructor = NameObjectEvent;
NameObjectEvent.prototype.start = function () {
var _this = this;
this.app.on('nameObject.' + this.id, function (object, name) {
_this.onNameObject(object);
});
};
NameObjectEvent.prototype.stop = function () {
this.app.on('nameObject.' + this.id, null);
};
NameObjectEvent.prototype.onNameObject = function (object, name) {
var editor = this.app.editor;
object.name = name;
editor.signals.sceneGraphChanged.dispatch();
};
export default NameObjectEvent;