com.wallstop-studios.unity-helpers 2.0.0-rc53 → 2.0.0-rc55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,24 +63,23 @@
63
63
  TaskCompletionSource<T[]> taskCompletionSource = new();
64
64
 
65
65
  SceneLoadScope sceneScope = new(scenePath, OnSceneLoaded);
66
- return await taskCompletionSource.Task.ContinueWith(result =>
67
- {
68
- return new DeferredDisposalResult<T[]>(
69
- result.Result,
70
- async () =>
71
- {
72
- TaskCompletionSource<bool> disposalComplete = new();
73
- UnityMainThreadDispatcher.Instance.RunOnMainThread(
74
- () =>
75
- sceneScope
76
- .DisposeAsync()
77
- .ContinueWith(_ => disposalComplete.SetResult(true))
78
- );
66
+ T[] result = await taskCompletionSource.Task;
79
67
 
80
- await disposalComplete.Task;
81
- }
82
- );
83
- });
68
+ return new DeferredDisposalResult<T[]>(
69
+ result,
70
+ () =>
71
+ {
72
+ TaskCompletionSource<bool> disposalComplete = new();
73
+ UnityMainThreadDispatcher.Instance.RunOnMainThread(
74
+ () =>
75
+ sceneScope
76
+ .DisposeAsync()
77
+ .ContinueWith(_ => disposalComplete.SetResult(true))
78
+ );
79
+
80
+ return disposalComplete.Task;
81
+ }
82
+ );
84
83
 
85
84
  void OnSceneLoaded(Scene scene, LoadSceneMode mode)
86
85
  {
@@ -102,7 +101,7 @@
102
101
  return go.scene == scene;
103
102
  })
104
103
  .ToArray();
105
- taskCompletionSource.TrySetResult(foundObjects);
104
+ taskCompletionSource.SetResult(foundObjects);
106
105
  }
107
106
  }
108
107
 
@@ -2,18 +2,66 @@
2
2
  {
3
3
  using System;
4
4
  using System.Collections.Concurrent;
5
+ using UnityEditor;
5
6
  using UnityEngine;
6
7
  using Utils;
7
8
 
9
+ [ExecuteAlways]
8
10
  public sealed class UnityMainThreadDispatcher : RuntimeSingleton<UnityMainThreadDispatcher>
9
11
  {
10
12
  private readonly ConcurrentQueue<Action> _actions = new();
11
13
 
14
+ #if UNITY_EDITOR
15
+ private readonly EditorApplication.CallbackFunction _update;
16
+ private bool _attachedEditorUpdate;
17
+ #endif
18
+
19
+ public UnityMainThreadDispatcher()
20
+ {
21
+ #if UNITY_EDITOR
22
+ _update = Update;
23
+ #endif
24
+ }
25
+
12
26
  public void RunOnMainThread(Action action)
13
27
  {
14
28
  _actions.Enqueue(action);
15
29
  }
16
30
 
31
+ private void OnEnable()
32
+ {
33
+ #if UNITY_EDITOR
34
+ if (!_attachedEditorUpdate)
35
+ {
36
+ EditorApplication.update += _update;
37
+ _attachedEditorUpdate = true;
38
+ }
39
+ #endif
40
+ }
41
+
42
+ private void OnDisable()
43
+ {
44
+ #if UNITY_EDITOR
45
+ if (_attachedEditorUpdate)
46
+ {
47
+ EditorApplication.update -= _update;
48
+ _attachedEditorUpdate = false;
49
+ }
50
+ #endif
51
+ }
52
+
53
+ protected override void OnDestroy()
54
+ {
55
+ #if UNITY_EDITOR
56
+ if (_attachedEditorUpdate)
57
+ {
58
+ EditorApplication.update -= _update;
59
+ _attachedEditorUpdate = false;
60
+ }
61
+ #endif
62
+ base.OnDestroy();
63
+ }
64
+
17
65
  private void Update()
18
66
  {
19
67
  while (_actions.TryDequeue(out Action action))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc53",
3
+ "version": "2.0.0-rc55",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},