将此代码添加到编辑器窗口脚本,通过脚本添加对象,然后尝试创建新场景。为什么团结在打开新场景之前不要求保存场景?
Event e = Event.current;
switch (e.type)
{
case EventType.keyDown:
{
if (e.keyCode == KeyCode.Escape)
{
GameObject b = new GameObject();
b.transform.position = new Vector3(0,0,0);
}
e.Use();
}
break;
}
答案 0 :(得分:3)
我不知道这对于Unity 5中的脏位是否有帮助
你必须:
using UnityEditor.SceneManagement;
位于代码顶部。然后使用:
EditorSceneManager.MarkAllScenesDirty(); //or mark individual scenes as dirty
如果您有自定义编辑器脚本动态实例化游戏对象,则绝对必要。 (我有一个创建基于图块的地图。在编辑器中看起来很棒。我会保存场景并玩游戏。它已经消失了......)
我不能完全相信这个发现,然而旧的统一4帖子指出了我正确的方向。
答案 1 :(得分:1)
http://answers.unity3d.com/questions/336751/is-editorutilitysetdirty-restricted-to-prefabs-or.html
这个男孩是个天才。当我们更新时,我们究竟应该发现这样的事情会发生变化吗?
答案 2 :(得分:0)
创建对象后,(或对场景中的对象执行任何操作)需要调用EditorUtility.SetDirty(b);
如果更改了编写的脚本的值,则需要将其标记为脏以及改变的持续性。
答案 3 :(得分:0)
使用此代码
import React, { PropTypes } from 'react';
import Counter from './Counter';
const Player = props => (
<div className="player">
<div className="player-name" onClick={() => props.selectPlayer(props.index)}>
<a className="remove-player"
onClick={() => props.removePlayer(props.index)}>
✖
</a>
{props.name}
</div>
<div className="player-score">
<Counter
index={props.index}
updatePlayerScore={props.updatePlayerScore}
score={props.score}
/>
</div>
</div>
);
调整当前场景