Skip to content

Commit 156646d

Browse files
Use a temporary file to enable hot reloading on Windows
1 parent a04c190 commit 156646d

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

Unity/Assets/NativeScript/Bindings.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,9 @@ public ReusableWaitForSecondsRealtime(float time)
292292
const string PLUGIN_PATH = "/Plugins/Editor/libNativeScript.so";
293293
#elif UNITY_EDITOR_WIN
294294
const string PLUGIN_PATH = "/Plugins/Editor/NativeScript.dll";
295+
const string PLUGIN_TEMP_PATH = "/Plugins/Editor/NativeScript_temp.dll";
295296
#endif
296-
297+
297298
enum InitMode : byte
298299
{
299300
FirstBoot,
@@ -1517,6 +1518,9 @@ IntPtr systemComponentModelDesignComponentRenameEventHandlerInvoke
15171518
/*END DELEGATE TYPES*/
15181519

15191520
private static readonly string pluginPath = Application.dataPath + PLUGIN_PATH;
1521+
#if UNITY_EDITOR_WIN
1522+
private static readonly string pluginTempPath = Application.dataPath + PLUGIN_TEMP_PATH;
1523+
#endif
15201524
public static Exception UnhandledCppException;
15211525
public static SetCsharpExceptionDelegate SetCsharpException;
15221526
private static IntPtr memory;
@@ -1602,8 +1606,16 @@ ReusableWaitForSecondsRealtime poll
16021606
private static void OpenPlugin(InitMode initMode)
16031607
{
16041608
#if UNITY_EDITOR
1609+
string loadPath;
1610+
#if UNITY_EDITOR_WIN
1611+
// Copy native library to temporary file
1612+
File.Copy(pluginPath, pluginTempPath);
1613+
loadPath = pluginTempPath;
1614+
#else
1615+
loadPath = pluginPath;
1616+
#endif
16051617
// Open native library
1606-
libraryHandle = OpenLibrary(pluginPath);
1618+
libraryHandle = OpenLibrary(loadPath);
16071619
InitDelegate Init = GetDelegate<InitDelegate>(
16081620
libraryHandle,
16091621
"Init");
@@ -1967,6 +1979,9 @@ private static void ClosePlugin()
19671979
#if UNITY_EDITOR
19681980
CloseLibrary(libraryHandle);
19691981
libraryHandle = IntPtr.Zero;
1982+
#endif
1983+
#if UNITY_EDITOR_WIN
1984+
File.Delete(pluginTempPath);
19701985
#endif
19711986
}
19721987

Unity/CppSource/Game/Game.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void MyGame::MonoBehaviours::AnotherScript::Update()
9797
{
9898
Transform transform = GetTransform();
9999
Vector3 pos = transform.GetPosition();
100-
const float speed = 1.2f;
100+
const float speed = 0.0012f;
101101
const float min = -1.5f;
102102
const float max = 1.5f;
103103
Vector3 offset(Time::GetDeltaTime() * speed * gameState->Dir, 0, 0);
@@ -106,11 +106,19 @@ void MyGame::MonoBehaviours::AnotherScript::Update()
106106
{
107107
gameState->Dir *= -1.0f;
108108
newPos.x = max - (newPos.x - max);
109+
if (newPos.x < min)
110+
{
111+
newPos.x = min;
112+
}
109113
}
110114
else if (newPos.x < min)
111115
{
112116
gameState->Dir *= -1.0f;
113117
newPos.x = min + (min - newPos.x);
118+
if (newPos.x > max)
119+
{
120+
newPos.x = max;
121+
}
114122
}
115123
transform.SetPosition(newPos);
116124
}

0 commit comments

Comments
 (0)