|
|
@@ -1,14 +1,25 @@
|
|
|
#include "BsPlayInEditorManager.h"
|
|
|
#include "BsScriptGameObjectManager.h"
|
|
|
#include "BsTime.h"
|
|
|
+#include "BsSceneManager.h"
|
|
|
+#include "BsSceneObject.h"
|
|
|
|
|
|
namespace BansheeEngine
|
|
|
{
|
|
|
PlayInEditorManager::PlayInEditorManager()
|
|
|
- :mState(PlayInEditorState::Stopped), mFrameStepActive(false)
|
|
|
+ :mState(PlayInEditorState::Stopped), mNextState(PlayInEditorState::Stopped),
|
|
|
+ mFrameStepActive(false), mScheduledStateChange(false), mPausableTime(0.0f)
|
|
|
{ }
|
|
|
|
|
|
void PlayInEditorManager::setState(PlayInEditorState state)
|
|
|
+ {
|
|
|
+ // Delay state change to next frame as this method could be called in middle of object update, in which case
|
|
|
+ // part of the objects before this call would receive different state than other objects.
|
|
|
+ mScheduledStateChange = true;
|
|
|
+ mNextState = state;
|
|
|
+ }
|
|
|
+
|
|
|
+ void PlayInEditorManager::setStateImmediate(PlayInEditorState state)
|
|
|
{
|
|
|
if (mState == state)
|
|
|
return;
|
|
|
@@ -22,7 +33,10 @@ namespace BansheeEngine
|
|
|
{
|
|
|
mFrameStepActive = false;
|
|
|
mPausableTime = 0.0f;
|
|
|
- // TODO - Load saved scene from prefab
|
|
|
+
|
|
|
+ mSavedScene->_instantiate();
|
|
|
+ gSceneManager()._setRootNode(mSavedScene);
|
|
|
+ mSavedScene = nullptr;
|
|
|
}
|
|
|
break;
|
|
|
case PlayInEditorState::Playing:
|
|
|
@@ -33,7 +47,8 @@ namespace BansheeEngine
|
|
|
}
|
|
|
else // Was stopped
|
|
|
{
|
|
|
- // TODO - Save current scene in a prefab
|
|
|
+ mSavedScene = SceneManager::instance().getRootNode()->clone(false);
|
|
|
+ ScriptGameObjectManager::instance().sendComponentInitializeEvents();
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
@@ -42,7 +57,8 @@ namespace BansheeEngine
|
|
|
mFrameStepActive = false;
|
|
|
if (oldState == PlayInEditorState::Stopped)
|
|
|
{
|
|
|
- // TODO - Save current scene in a prefab
|
|
|
+ mSavedScene = SceneManager::instance().getRootNode()->clone(false);
|
|
|
+ ScriptGameObjectManager::instance().sendComponentInitializeEvents();
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
@@ -69,6 +85,16 @@ namespace BansheeEngine
|
|
|
if (mState == PlayInEditorState::Playing)
|
|
|
mPausableTime += gTime().getFrameDelta();
|
|
|
|
|
|
- // TODO - disable framestep once a frame has passed
|
|
|
+ if (mScheduledStateChange)
|
|
|
+ {
|
|
|
+ setStateImmediate(mNextState);
|
|
|
+ mScheduledStateChange = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mFrameStepActive)
|
|
|
+ {
|
|
|
+ setState(PlayInEditorState::Paused);
|
|
|
+ mFrameStepActive = false;
|
|
|
+ }
|
|
|
}
|
|
|
}
|