Skip to content

Commit

Permalink
Fix access to registered game clock from other threads (#7)
Browse files Browse the repository at this point in the history
Replaces registered game clock with own copy of Time.realtimeSinceStartup
  • Loading branch information
LaserHydra authored and lukespragg committed Feb 15, 2019
1 parent ad2dfeb commit 8b48864
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/UnityExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Oxide.Core.Unity.Plugins;
using System;
using System.Reflection;
using UnityEngine;

namespace Oxide.Core.Unity
{
Expand Down Expand Up @@ -51,7 +50,7 @@ public override void Load()
{
Manager.RegisterPluginLoader(new UnityPluginLoader());

Interface.Oxide.RegisterEngineClock(() => Time.realtimeSinceStartup);
Interface.Oxide.RegisterEngineClock(() => UnityScript.RealtimeSinceStartup);

// Register our MonoBehaviour
UnityScript.Create();
Expand Down
11 changes: 10 additions & 1 deletion src/UnityScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Oxide.Core.Unity
public class UnityScript : MonoBehaviour
{
public static GameObject Instance { get; private set; }

public static float RealtimeSinceStartup { get; private set; }

public static void Create()
{
Expand All @@ -22,6 +24,8 @@ public static void Create()

private void Awake()
{
RealtimeSinceStartup = Time.realtimeSinceStartup;

oxideMod = Interface.Oxide;

EventInfo eventInfo = typeof(Application).GetEvent("logMessageReceived");
Expand Down Expand Up @@ -50,7 +54,12 @@ private void Awake()
}
}

private void Update() => oxideMod.OnFrame(Time.deltaTime);
private void Update()
{
RealtimeSinceStartup = Time.realtimeSinceStartup;

oxideMod.OnFrame(Time.deltaTime);
}

private void OnDestroy()
{
Expand Down

0 comments on commit 8b48864

Please sign in to comment.