所以基本上我的问题是:有什么方法可以从场景模式切换到游戏模式脚本吗?
我想从脚本中获得的图像
我基本上是在问,因为我想对加载到场景中的资产进行截图。
我的代码:
using UnityEngine;
using UnityEngine.SceneManagement;
public class NewBehaviourScript : MonoBehaviour {
// Use this for initialization
void Start () {
Debug.Log("HELLO");
var rss = AssetBundle.LoadFromFile(@"//MyFileLocation");
Debug.Log(SceneManager.GetActiveScene().name);
foreach (var asset in rss.LoadAllAssets<GameObject>())//<Texture2D>())
{
GameObject obj = Instantiate(asset, transform);
}
Debug.Log(transform.position);
Application.CaptureScreenshot(@"//MyScreenshotlocation");
Debug.Log("captured");
}
// Update is called once per frame
void Update () {
}
}
感谢您的帮助!谢谢!
答案 0 :(得分:3)
您可以使用EditorWindow.FocusWindowIfItsOpen
功能切换到任何窗口。要切换到场景视图,请向其传递SceneView
。您可以使用EditorApplication.playModeStateChanged
确定何时进入播放模式。
这是一个编辑器插件,必须放置在名为“编辑器”的文件夹中。创建一个名为SceneSwitcher
的脚本,并复制其中下面的所有内容。单击播放按钮时,它应该自动切换到“场景视图”。
using UnityEditor;
[InitializeOnLoadAttribute]
public static class SceneSwitcher
{
static SceneSwitcher()
{
EditorApplication.playModeStateChanged += LogPlayModeState;
}
private static void LogPlayModeState(PlayModeStateChange state)
{
if (state == PlayModeStateChange.EnteredPlayMode)
SwitchToSceneView();
}
static void SwitchToSceneView()
{
EditorWindow.FocusWindowIfItsOpen<SceneView>();
/////OR
//SceneView sceneView = EditorWindow.GetWindow<SceneView>(); ;
//Type type = sceneView.GetType();
//EditorWindow.FocusWindowIfItsOpen(type);
}
}