Skip to content

Commit 516a66f

Browse files
committed
updated to later unity and wrapped webgl stuff behind an ifdef
1 parent c42e4f2 commit 516a66f

File tree

6 files changed

+35
-24
lines changed

6 files changed

+35
-24
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ AutoSaver.meta
5252
out/
5353
logs/
5454
build-process/
55+
Assets/Plugins/Editor/JetBrains/*
56+
.idea/*

Assets/UnityLoader/Scripts/LoadManager.cs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System.Collections;
22
using UnityEngine;
33
using System.Collections.Generic;
4+
5+
#if UNITY_WEBGL
46
using System.Runtime.InteropServices;
7+
#endif
58

69
namespace UnityGameLoader
710
{
@@ -11,6 +14,7 @@ namespace UnityGameLoader
1114
public class LoadManager : MonoBehaviour
1215
{
1316
#region public
17+
1418
/// <summary>
1519
/// The amount of time the loader will execute before yield to a new frame.
1620
/// </summary>
@@ -33,7 +37,7 @@ public class LoadManager : MonoBehaviour
3337
/// </summary>
3438
public float progress
3539
{
36-
get { return (float)_currentStep / _totalSteps; }
40+
get { return (float) _currentStep / _totalSteps; }
3741
}
3842

3943
/// <summary>
@@ -52,7 +56,7 @@ public static LoadManager instance
5256
LogErrorFormat(
5357
"No instance of {0} can be found! Add the {0} component to a GameObject or invoke {0}.{1}().",
5458
typeof(LoadManager),
55-
((System.Action<float, int, bool>)CreateManager).Method.Name);
59+
((System.Action<float, int, bool>) CreateManager).Method.Name);
5660
}
5761
}
5862

@@ -202,7 +206,7 @@ public void LoadRegistered(System.Action onLoadComplete)
202206
onLoadComplete();
203207
}
204208
}
205-
,
209+
,
206210
stepsFromLoads));
207211
}
208212

@@ -311,6 +315,7 @@ public void IncrementLoadStep()
311315
}
312316

313317
#endregion
318+
314319
#region private
315320

316321
private int _totalSteps;
@@ -331,8 +336,12 @@ public void IncrementLoadStep()
331336
private const int DEFAULT_LOADING_STEPS = 1;
332337
private const string LOG_HEADER = "[Unity Loader]";
333338
private const string CREATED_NAME = "[Unity Loader]";
334-
private const string METHOD_INVOKE_DURING_LOADING_WARNING = "{0}.{1} invoked in the middle of a load! This isn't allowed. Invoke after the load finishes.";
335-
private const string METHOD_INVOKE_NOT_LOADING_WARNING = "{0}.{1} invoked when not loading! This will be ignored.";
339+
340+
private const string METHOD_INVOKE_DURING_LOADING_WARNING =
341+
"{0}.{1} invoked in the middle of a load! This isn't allowed. Invoke after the load finishes.";
342+
343+
private const string METHOD_INVOKE_NOT_LOADING_WARNING =
344+
"{0}.{1} invoked when not loading! This will be ignored.";
336345

337346
private struct LoaderStep
338347
{
@@ -346,12 +355,13 @@ public LoaderStep(IEnumerator enumerator, int additionalSteps)
346355
}
347356
}
348357

358+
#if UNITY_WEBGL
349359
[DllImport("__Internal", EntryPoint = "ulInitialize")]
350360
private static extern void JSInitialize();
351361

352362
[DllImport("__Internal", EntryPoint = "ulIsTabActive")]
353363
private static extern bool JSIsTabActive();
354-
364+
#endif
355365
private void Awake()
356366
{
357367
if (_instance != null)
@@ -365,11 +375,13 @@ private void Awake()
365375

366376
_instance = this;
367377

368-
if (Application.platform == RuntimePlatform.WebGLPlayer && !Application.isEditor && !_webglInitialized)
378+
#if UNITY_WEBGL
379+
if (!Application.isEditor && !_webglInitialized)
369380
{
370381
JSInitialize();
371382
_webglInitialized = true;
372383
}
384+
#endif
373385
}
374386

375387
private void OnApplicationFocus(bool focus)
@@ -457,7 +469,7 @@ private IEnumerator LoadRegisteredEnumerators()
457469
{
458470
LogWarningFormat(
459471
"Progress step count mismatch! Expecting {0} to be invoked the same number supplied during registration! Fixing.",
460-
((System.Action)IncrementLoadStep).Method.Name);
472+
((System.Action) IncrementLoadStep).Method.Name);
461473

462474
_currentStep = preEnumSteps + _loaders[i].additionalSteps;
463475
}
@@ -466,15 +478,15 @@ private IEnumerator LoadRegisteredEnumerators()
466478

467479
if (verboseLogging)
468480
{
469-
LogFormat("Loading {0} - Time: {1}", _loaders[i].enumerator, Time.realtimeSinceStartup - assetLoadTimeStart);
481+
LogFormat("Loading {0} - Time: {1}", _loaders[i].enumerator,
482+
Time.realtimeSinceStartup - assetLoadTimeStart);
470483
}
471484
}
472485
}
473486

474487
private bool ShouldYield(float frameStartTime)
475488
{
476-
if (Application.platform == RuntimePlatform.WebGLPlayer)
477-
{
489+
#if UNITY_WEBGL
478490
if (!Application.isEditor)
479491
{
480492
if (System.GC.GetTotalMemory(false) > memoryThresholdForYield)
@@ -492,20 +504,18 @@ private bool ShouldYield(float frameStartTime)
492504
return false;
493505
}
494506
}
495-
}
496-
else
507+
#else
508+
if (!Application.isEditor && !_hasFocus)
497509
{
498-
if (!Application.isEditor && !_hasFocus)
510+
if (Time.realtimeSinceStartup - frameStartTime >= NO_FOCUS_SECONDS_PER_FRAME)
499511
{
500-
if (Time.realtimeSinceStartup - frameStartTime >= NO_FOCUS_SECONDS_PER_FRAME)
501-
{
502-
return true;
503-
}
504-
505-
// We don't have focus, go nuts.
506-
return false;
512+
return true;
507513
}
514+
515+
// We don't have focus, go nuts.
516+
return false;
508517
}
518+
#endif
509519

510520
if ((Time.realtimeSinceStartup - frameStartTime) >= secondsAllowedPerFrame)
511521
{
@@ -532,4 +542,4 @@ private static void LogErrorFormat(string msg, params object[] args)
532542

533543
#endregion
534544
}
535-
}
545+
}

ProjectSettings/PresetManager.asset

4.01 KB
Binary file not shown.

ProjectSettings/ProjectVersion.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
m_EditorVersion: 5.4.0f3
2-
m_StandardAssetsVersion: 0
1+
m_EditorVersion: 2018.3.1f1
136 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)