├── .gitignore
├── Packages
├── com.enderlook.unity.async
│ ├── Runtime.meta
│ ├── Runtime
│ │ ├── Enderlook.Unity.Async.asmdef
│ │ ├── Enderlook.Unity.Async.asmdef.meta
│ │ ├── Thread Switcher.meta
│ │ └── Thread Switcher
│ │ │ ├── IThreadSwitcher.cs
│ │ │ ├── IThreadSwitcher.cs.meta
│ │ │ ├── Switch.cs
│ │ │ ├── Switch.cs.meta
│ │ │ ├── ThreadSwitcherBackground.cs
│ │ │ ├── ThreadSwitcherBackground.cs.meta
│ │ │ ├── ThreadSwitcherLongBackground.cs
│ │ │ ├── ThreadSwitcherLongBackground.cs.meta
│ │ │ ├── ThreadSwitcherUnity.cs
│ │ │ └── ThreadSwitcherUnity.cs.meta
│ ├── package.json
│ └── package.json.meta
├── com.enderlook.unity.coroutines
│ ├── Editor.meta
│ ├── Editor
│ │ ├── AutomaticCoroutineScheduler.cs
│ │ ├── AutomaticCoroutineScheduler.cs.meta
│ │ ├── CoroutinesInfo.cs
│ │ ├── CoroutinesInfo.cs.meta
│ │ ├── Enderlook.Unity.Coroutines-Editor.asmdef
│ │ ├── Enderlook.Unity.Coroutines-Editor.asmdef.meta
│ │ ├── GlobalCoroutinesManagerUnitEditor.cs
│ │ └── GlobalCoroutinesManagerUnitEditor.cs.meta
│ ├── Runtime.meta
│ ├── Runtime
│ │ ├── EditorPoolContainer.cs
│ │ ├── EditorPoolContainer.cs.meta
│ │ ├── Enderlook.Unity.Coroutines.asmdef
│ │ ├── Enderlook.Unity.Coroutines.asmdef.meta
│ │ ├── InternalsVisibleTo.cs
│ │ ├── InternalsVisibleTo.cs.meta
│ │ ├── Unity Coroutines.meta
│ │ ├── Unity Coroutines
│ │ │ ├── CoroutineAwaiter.cs
│ │ │ ├── CoroutineAwaiter.cs.meta
│ │ │ ├── CoroutineAwaiterExtension.cs
│ │ │ ├── CoroutineAwaiterExtension.cs.meta
│ │ │ ├── Wait.cs
│ │ │ ├── Wait.cs.meta
│ │ │ ├── WaitForJobComplete.cs
│ │ │ ├── WaitForJobComplete.cs.meta
│ │ │ ├── WaitForSecondsRealtimePooled.cs
│ │ │ ├── WaitForSecondsRealtimePooled.cs.meta
│ │ │ ├── WaitForTaskComplete.cs
│ │ │ ├── WaitForTaskComplete.cs.meta
│ │ │ ├── WaitForTaskComplete`1.cs
│ │ │ ├── WaitForTaskComplete`1.cs.meta
│ │ │ ├── WaitForUpdate.cs
│ │ │ ├── WaitForUpdate.cs.meta
│ │ │ ├── WaitForValueTaskComplete.cs
│ │ │ ├── WaitForValueTaskComplete.cs.meta
│ │ │ ├── WaitForValueTaskComplete`1.cs
│ │ │ ├── WaitForValueTaskComplete`1.cs.meta
│ │ │ ├── WaitUntilPooled.cs
│ │ │ ├── WaitUntilPooled.cs.meta
│ │ │ ├── WaitWhilePooled.cs
│ │ │ └── WaitWhilePooled.cs.meta
│ │ ├── Utility.meta
│ │ ├── Utility
│ │ │ ├── PackList.cs
│ │ │ ├── PackList.cs.meta
│ │ │ ├── PackQueue.cs
│ │ │ ├── PackQueue.cs.meta
│ │ │ ├── ReadWriterLock.cs
│ │ │ └── ReadWriterLock.cs.meta
│ │ ├── Value Coroutines.meta
│ │ └── Value Coroutines
│ │ │ ├── CoroutineScheduler.meta
│ │ │ ├── CoroutineScheduler
│ │ │ ├── AutomaticCoroutineScheduler.cs
│ │ │ ├── AutomaticCoroutineScheduler.cs.meta
│ │ │ ├── CoroutineExtensions.cs
│ │ │ ├── CoroutineExtensions.cs.meta
│ │ │ ├── CoroutineManager.ManagerBase.cs
│ │ │ ├── CoroutineManager.ManagerBase.cs.meta
│ │ │ ├── CoroutineManager.NestedEnumerator.cs
│ │ │ ├── CoroutineManager.NestedEnumerator.cs.meta
│ │ │ ├── CoroutineManager.NestedEnumeratorBackground.cs
│ │ │ ├── CoroutineManager.NestedEnumeratorBackground.cs.meta
│ │ │ ├── CoroutineManager.On.cs
│ │ │ ├── CoroutineManager.On.cs.meta
│ │ │ ├── CoroutineManager.Starts.cs
│ │ │ ├── CoroutineManager.Starts.cs.meta
│ │ │ ├── CoroutineManager.TypedManager.INextCallback.cs
│ │ │ ├── CoroutineManager.TypedManager.INextCallback.cs.meta
│ │ │ ├── CoroutineManager.TypedManager.cs
│ │ │ ├── CoroutineManager.TypedManager.cs.meta
│ │ │ ├── CoroutineManager.cs
│ │ │ ├── CoroutineManager.cs.meta
│ │ │ ├── GlobalCoroutinesManagerUnit.cs
│ │ │ ├── GlobalCoroutinesManagerUnit.cs.meta
│ │ │ ├── ThreadMode.cs
│ │ │ └── ThreadMode.cs.meta
│ │ │ ├── IValueCoroutine.meta
│ │ │ ├── IValueCoroutine
│ │ │ ├── IValueCoroutineEnumerator.cs
│ │ │ ├── IValueCoroutineEnumerator.cs.meta
│ │ │ ├── UnityCoroutineEnumerator.cs
│ │ │ ├── UnityCoroutineEnumerator.cs.meta
│ │ │ ├── ValueCoroutineEnumerator.cs
│ │ │ ├── ValueCoroutineEnumerator.cs.meta
│ │ │ ├── ValueCoroutineEnumeratorWithState.cs
│ │ │ └── ValueCoroutineEnumeratorWithState.cs.meta
│ │ │ ├── IValueCoroutineState.meta
│ │ │ ├── IValueCoroutineState
│ │ │ ├── CancellationTokenFinalizer.cs
│ │ │ ├── CancellationTokenFinalizer.cs.meta
│ │ │ ├── GameObjectFinalizeWhenNullAndSuspendWhenIsNotActive.cs
│ │ │ ├── GameObjectFinalizeWhenNullAndSuspendWhenIsNotActive.cs.meta
│ │ │ ├── IValueCoroutineState.cs
│ │ │ ├── IValueCoroutineState.cs.meta
│ │ │ ├── MonoBehaviourFinalizeWhenNullAndSuspendWhenGameObjectIsDisabled.cs
│ │ │ ├── MonoBehaviourFinalizeWhenNullAndSuspendWhenGameObjectIsDisabled.cs.meta
│ │ │ ├── MonoBehaviourFinalizeWhenNullAndSuspendWhenIsNotActiveNorEnabled.cs
│ │ │ ├── MonoBehaviourFinalizeWhenNullAndSuspendWhenIsNotActiveNorEnabled.cs.meta
│ │ │ ├── UnityObjectFinalizeWhenNull.cs
│ │ │ ├── UnityObjectFinalizeWhenNull.cs.meta
│ │ │ ├── ValueCoroutineState.cs
│ │ │ ├── ValueCoroutineState.cs.meta
│ │ │ ├── ValueCoroutineStateBoxed.cs
│ │ │ ├── ValueCoroutineStateBoxed.cs.meta
│ │ │ ├── ValueCoroutineStateHelper.cs
│ │ │ └── ValueCoroutineStateHelper.cs.meta
│ │ │ ├── ValueCoroutine.meta
│ │ │ ├── ValueCoroutine
│ │ │ ├── ValueCoroutine.Enumerator.cs
│ │ │ ├── ValueCoroutine.Enumerator.cs.meta
│ │ │ ├── ValueCoroutine.Handle.cs
│ │ │ ├── ValueCoroutine.Handle.cs.meta
│ │ │ ├── ValueCoroutine.Starts.cs
│ │ │ ├── ValueCoroutine.Starts.cs.meta
│ │ │ ├── ValueCoroutine.cs
│ │ │ └── ValueCoroutine.cs.meta
│ │ │ ├── ValueYieldInstruction.cs
│ │ │ ├── ValueYieldInstruction.cs.meta
│ │ │ ├── Yield.cs
│ │ │ └── Yield.cs.meta
│ ├── package.json
│ ├── package.json.bak
│ ├── package.json.bak.meta
│ └── package.json.meta
├── com.enderlook.unity.jobs
│ ├── Editor.meta
│ ├── Editor
│ │ ├── Enderlook.Unity.Jobs-Editor.asmdef
│ │ ├── Enderlook.Unity.Jobs-Editor.asmdef.meta
│ │ ├── JobsInfo.cs
│ │ └── JobsInfo.cs.meta
│ ├── Runtime.meta
│ ├── Runtime
│ │ ├── Enderlook.Unity.Jobs.asmdef
│ │ ├── Enderlook.Unity.Jobs.asmdef.meta
│ │ ├── GlobalDictionary`1.cs
│ │ ├── GlobalDictionary`1.cs.meta
│ │ ├── InternalsVisibleTo.cs
│ │ ├── InternalsVisibleTo.cs.meta
│ │ ├── JobHandleAwaiter.meta
│ │ ├── JobHandleAwaiter
│ │ │ ├── JobHandleAwaiter.cs
│ │ │ ├── JobHandleAwaiter.cs.meta
│ │ │ ├── JobHandleAwaiterExtension.cs
│ │ │ └── JobHandleAwaiterExtension.cs.meta
│ │ ├── JobManager.meta
│ │ ├── JobManager
│ │ │ ├── JobManager.JobHandleCompleter.cs
│ │ │ ├── JobManager.JobHandleCompleter.cs.meta
│ │ │ ├── JobManager.JobTask.cs
│ │ │ ├── JobManager.JobTask.cs.meta
│ │ │ ├── JobManager.JobTasksManager.cs
│ │ │ ├── JobManager.JobTasksManager.cs.meta
│ │ │ ├── JobManager.cs
│ │ │ └── JobManager.cs.meta
│ │ ├── Managed.meta
│ │ └── Managed
│ │ │ ├── IManagedJob.meta
│ │ │ ├── IManagedJob
│ │ │ ├── IManagedJob.cs
│ │ │ ├── IManagedJob.cs.meta
│ │ │ ├── IManagedJobExtensions.Delegates.cs
│ │ │ ├── IManagedJobExtensions.Delegates.cs.meta
│ │ │ ├── IManagedJobExtensions.cs
│ │ │ ├── IManagedJobExtensions.cs.meta
│ │ │ ├── ManagedJob.cs
│ │ │ └── ManagedJob.cs.meta
│ │ │ ├── IManagedJobParallelFor.meta
│ │ │ └── IManagedJobParallelFor
│ │ │ ├── IManagedJobParallelFor.cs
│ │ │ ├── IManagedJobParallelFor.cs.meta
│ │ │ ├── IManagedJobParallelForExtensions.cs
│ │ │ ├── IManagedJobParallelForExtensions.cs.meta
│ │ │ ├── ManagedJobParallelFor.cs
│ │ │ └── ManagedJobParallelFor.cs.meta
│ ├── package.json
│ └── package.json.meta
├── com.enderlook.unity.threading
│ ├── Runtime.meta
│ ├── Runtime
│ │ ├── Enderlook.Unity.Threading.asmdef
│ │ ├── Enderlook.Unity.Threading.asmdef.meta
│ │ ├── InternalsVisibleTo.cs
│ │ ├── InternalsVisibleTo.cs.meta
│ │ ├── Unity Thread.meta
│ │ ├── Unity Thread
│ │ │ ├── UnitySynchronizationContextUtility.cs
│ │ │ ├── UnitySynchronizationContextUtility.cs.meta
│ │ │ ├── UnityThread.cs
│ │ │ └── UnityThread.cs.meta
│ │ ├── Utility.meta
│ │ └── Utility
│ │ │ ├── Manager.cs
│ │ │ ├── Manager.cs.meta
│ │ │ ├── Tuple2.cs
│ │ │ ├── Tuple2.cs.meta
│ │ │ ├── Tuple3.cs
│ │ │ └── Tuple3.cs.meta
│ ├── package.json
│ └── package.json.meta
├── manifest.json
├── packages-lock.git.json
└── packages-lock.json
├── ProjectSettings
├── AudioManager.asset
├── ClusterInputManager.asset
├── DynamicsManager.asset
├── EditorBuildSettings.asset
├── EditorSettings.asset
├── GraphicsSettings.asset
├── InputManager.asset
├── NavMeshAreas.asset
├── Physics2DSettings.asset
├── PresetManager.asset
├── ProjectSettings.asset
├── ProjectVersion.txt
├── QualitySettings.asset
├── TagManager.asset
├── TimeManager.asset
├── UnityConnectSettings.asset
├── VFXManager.asset
└── XRSettings.asset
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | # This .gitignore file should be placed at the root of your Unity project directory
2 | #
3 | # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
4 | #
5 | /[Ll]ibrary/
6 | /[Tt]emp/
7 | /[Oo]bj/
8 | /[Bb]uild/
9 | /[Bb]uilds/
10 | /[Ll]ogs/
11 | /[Mm]emoryCaptures/
12 |
13 | # Asset meta data should only be ignored when the corresponding asset is also ignored
14 | !/[Aa]ssets/**/*.meta
15 |
16 | # Uncomment this line if you wish to ignore the asset store tools plugin
17 | # /[Aa]ssets/AssetStoreTools*
18 |
19 | # Autogenerated Jetbrains Rider plugin
20 | [Aa]ssets/Plugins/Editor/JetBrains*
21 |
22 | # Visual Studio cache directory
23 | .vs/
24 |
25 | # Gradle cache directory
26 | .gradle/
27 |
28 | # Autogenerated VS/MD/Consulo solution and project files
29 | ExportedObj/
30 | .consulo/
31 | *.csproj
32 | *.unityproj
33 | *.sln
34 | *.suo
35 | *.tmp
36 | *.user
37 | *.userprefs
38 | *.pidb
39 | *.booproj
40 | *.svd
41 | *.pdb
42 | *.mdb
43 | *.opendb
44 | *.VC.db
45 |
46 | # Unity3D generated meta files
47 | *.pidb.meta
48 | *.pdb.meta
49 | *.mdb.meta
50 |
51 | # Unity3D generated file on crash reports
52 | sysinfo.txt
53 |
54 | # Builds
55 | *.apk
56 | *.unitypackage
57 |
58 | # Crashlytics generated file
59 | crashlytics-build.properties
60 |
61 | # Custom
62 | *.autogenerated.cs
63 |
64 | # Used by GitDependencyResolverForUnity
65 | Packages/.*
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/Runtime.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ed474c3363aa2b94f872c1e20fa1b209
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/Runtime/Enderlook.Unity.Async.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Enderlook.Unity.Async",
3 | "references": [
4 | "GUID:12965892c664bf44cbd63f6568ef40da"
5 | ],
6 | "includePlatforms": [],
7 | "excludePlatforms": [],
8 | "allowUnsafeCode": false,
9 | "overrideReferences": false,
10 | "precompiledReferences": [],
11 | "autoReferenced": true,
12 | "defineConstraints": [],
13 | "versionDefines": []
14 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/Runtime/Enderlook.Unity.Async.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b9985c1548fef4e4e8622349dc1d0d91
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/Runtime/Thread Switcher.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d4ae1437a0a33c84580da8a5b03e87ef
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/Runtime/Thread Switcher/IThreadSwitcher.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | namespace Enderlook.Unity.Threading
4 | {
5 | ///
6 | /// Defines an object that switches to a thread.
7 | ///
8 | public interface IThreadSwitcher : INotifyCompletion
9 | {
10 | // https://stackoverflow.com/a/58470597/7655838 from https://stackoverflow.com/questions/58469468/what-does-unitymainthreaddispatcher-do
11 |
12 | ///
13 | /// Determines if this task has completed.
14 | ///
15 | bool IsCompleted { get; }
16 |
17 | ///
18 | /// Returns the awaiter of this task.
19 | ///
20 | /// Awaiter of this task.
21 | IThreadSwitcher GetAwaiter();
22 |
23 | ///
24 | /// Get the result of the task.
25 | ///
26 | /// Whenever we switched of thread or not (either because we already were in the requested thread or it was not possible, for example: in WebGL platform threading is not supported).
27 | bool GetResult();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/Runtime/Thread Switcher/IThreadSwitcher.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0cbd653e42cb0fb4da2fcec09fb4821c
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/Runtime/Thread Switcher/Switch.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Enderlook.Unity.Threading
4 | {
5 | ///
6 | /// A helper class which allows to switch to a particular thread.
7 | ///
8 | public static class Switch
9 | {
10 | // https://stackoverflow.com/a/58470597/7655838 from https://stackoverflow.com/questions/58469468/what-does-unitymainthreaddispatcher-do
11 |
12 | ///
13 | /// Switches to a background pool thread.
14 | ///
15 | /// Object which switched to the thread.
16 | public static ThreadSwitcherBackground ToBackground => new ThreadSwitcherBackground();
17 |
18 | ///
19 | /// Switches to a background long duration thread.
20 | ///
21 | /// Object which switched to the thread.
22 | public static ThreadSwitcherLongBackground ToLongBackground => new ThreadSwitcherLongBackground();
23 |
24 | #if UNITY_EDITOR
25 | ///
26 | /// Switches to a background pool thread using the editor preferences instead of the standalone platform.
27 | /// This API only exists inside the Unity Editor.
28 | ///
29 | /// Object which switched to the thread.
30 | public static ThreadSwitcherBackground ToBackgroundEditor => new ThreadSwitcherBackground(true);
31 |
32 | ///
33 | /// Switches to a background long duration thread using the editor preferences instead of the standalone platform.
34 | /// This API only exists inside the Unity Editor.
35 | ///
36 | /// Object which switched to the thread.
37 | public static ThreadSwitcherLongBackground ToLongBackgroundEditor => new ThreadSwitcherLongBackground(true);
38 | #endif
39 |
40 | ///
41 | /// Switch to the Unity thread.
42 | ///
43 | /// Object which switched to the thread.
44 | public static ThreadSwitcherUnity ToUnity => new ThreadSwitcherUnity();
45 |
46 | internal static void ThrowArgumentNullException_Continuation()
47 | => throw new ArgumentNullException("continuation");
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/Runtime/Thread Switcher/Switch.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 03ca00c18f86aa4419cd45547d0ac340
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/Runtime/Thread Switcher/ThreadSwitcherBackground.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 | using System.Threading.Tasks;
4 |
5 | using UnityEngine;
6 |
7 | namespace Enderlook.Unity.Threading
8 | {
9 | ///
10 | /// Defines a switcher to jump to a pooled task thread.
11 | ///
12 | public struct ThreadSwitcherBackground : IThreadSwitcher
13 | {
14 | // https://stackoverflow.com/a/58470597/7655838 from https://stackoverflow.com/questions/58469468/what-does-unitymainthreaddispatcher-do
15 |
16 | // Alternatively we may do something like https://github.com/svermeulen/Unity3dAsyncAwaitUtil/blob/master/UnityProject/Assets/Plugins/AsyncAwaitUtil/Source/WaitForBackgroundThread.cs
17 |
18 | private static readonly IThreadSwitcher hasSwitchedGlobal = new ThreadSwitcherBackground() { hasSwitched = true };
19 | #if !UNITY_WEBGL || UNITY_EDITOR
20 | private static readonly IThreadSwitcher hasNotSwitchedGlobal = new ThreadSwitcherBackground();
21 | #endif
22 |
23 | private bool hasSwitched;
24 |
25 | #if UNITY_EDITOR
26 | #if UNITY_WEBGL
27 | private bool useEditorPreference;
28 | #endif
29 |
30 | internal ThreadSwitcherBackground(bool useEditorPreference)
31 | {
32 | #if UNITY_WEBGL
33 | this.useEditorPreference = useEditorPreference;
34 | #endif
35 | hasSwitched = default;
36 | }
37 | #endif
38 |
39 | ///
40 | public ThreadSwitcherBackground GetAwaiter() => this;
41 |
42 | ///
43 | public bool IsCompleted {
44 | get {
45 | #if UNITY_WEBGL
46 | #if UNITY_EDITOR
47 | if (useEditorPreference)
48 | return !UnityThread.IsMainThread;
49 | #endif
50 | #if DEBUG
51 | Debug.LogWarning("Threading is not supported on this platform. A fallback to main thread has been used. Be warned that this may produce deadlocks very easily.");
52 | #endif
53 | return true;
54 | #else
55 | return !UnityThread.IsMainThread;
56 | #endif
57 | }
58 | }
59 |
60 | ///
61 | public bool GetResult() => hasSwitched;
62 |
63 | ///
64 | public void OnCompleted(Action continuation)
65 | {
66 | if (continuation is null)
67 | Switch.ThrowArgumentNullException_Continuation();
68 |
69 | #if UNITY_WEBGL
70 | #if UNITY_EDITOR
71 | if (useEditorPreference)
72 | goto other;
73 | #endif
74 | Debug.Assert(!hasSwitched);
75 | #if DEBUG
76 | Debug.LogWarning("Threading is not supported on this platform. A fallback to main thread has been used. Be warned that this may produce deadlocks very easily.");
77 | #endif
78 | continuation();
79 | return;
80 | other:
81 | #endif
82 |
83 | hasSwitched = UnityThread.IsMainThread;
84 | if (hasSwitched)
85 | Task.Factory.StartNew(continuation);
86 | else
87 | {
88 | #if DEBUG
89 | Debug.Log("Already in a non-main thread, we don't need to change of thread so we will not.");
90 | #endif
91 | continuation();
92 | }
93 | }
94 |
95 | ///
96 | IThreadSwitcher IThreadSwitcher.GetAwaiter()
97 | {
98 | #if UNITY_WEBGL
99 | #if UNITY_EDITOR
100 |
101 | if (useEditorPreference && hasSwitched)
102 | return hasSwitchedGlobal;
103 | #endif
104 | return hasSwitchedGlobal;
105 | #else
106 | return hasSwitched ? hasSwitchedGlobal : hasNotSwitchedGlobal;
107 | #endif
108 | }
109 | }
110 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/Runtime/Thread Switcher/ThreadSwitcherBackground.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d067678ac3842344ab43442ad849896b
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/Runtime/Thread Switcher/ThreadSwitcherLongBackground.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 | using System.Threading.Tasks;
4 |
5 | using UnityEngine;
6 |
7 | namespace Enderlook.Unity.Threading
8 | {
9 | ///
10 | /// Defines a switcher to jump to a long task thread.
11 | ///
12 | public struct ThreadSwitcherLongBackground : IThreadSwitcher
13 | {
14 | // https://stackoverflow.com/a/58470597/7655838 from https://stackoverflow.com/questions/58469468/what-does-unitymainthreaddispatcher-do
15 |
16 | // Alternatively we may do something like https://github.com/svermeulen/Unity3dAsyncAwaitUtil/blob/master/UnityProject/Assets/Plugins/AsyncAwaitUtil/Source/WaitForBackgroundThread.cs
17 |
18 | private static readonly IThreadSwitcher hasSwitchedGlobal = new ThreadSwitcherLongBackground() { hasSwitched = true };
19 | #if !UNITY_WEBGL || UNITY_EDITOR
20 | private static readonly IThreadSwitcher hasNotSwitchedGlobal = new ThreadSwitcherLongBackground();
21 | #endif
22 |
23 | private bool hasSwitched;
24 |
25 | #if UNITY_EDITOR
26 | #if UNITY_WEBGL
27 | private bool useEditorPreference;
28 | #endif
29 |
30 | internal ThreadSwitcherLongBackground(bool useEditorPreference)
31 | {
32 | #if UNITY_WEBGL
33 | this.useEditorPreference = useEditorPreference;
34 | #endif
35 | hasSwitched = default;
36 | }
37 | #endif
38 |
39 | ///
40 | public ThreadSwitcherLongBackground GetAwaiter() => this;
41 |
42 | ///
43 | public bool IsCompleted {
44 | get {
45 | #if UNITY_WEBGL
46 | #if UNITY_EDITOR
47 | if (useEditorPreference)
48 | return !UnityThread.IsMainThread;
49 | #endif
50 | #if DEBUG
51 | Debug.LogWarning("Threading is not supported on this platform. A fallback to main thread has been used. Be warned that this may produce deadlocks very easily.");
52 | #endif
53 | return true;
54 | #else
55 | return !UnityThread.IsMainThread;
56 | #endif
57 | }
58 | }
59 |
60 | ///
61 | public bool GetResult() => hasSwitched;
62 |
63 | ///
64 | public void OnCompleted(Action continuation)
65 | {
66 | if (continuation is null)
67 | Switch.ThrowArgumentNullException_Continuation();
68 |
69 | #if UNITY_WEBGL
70 | if (useEditorPreference)
71 | goto other;
72 | Debug.Assert(!hasSwitched);
73 | #if DEBUG
74 | Debug.LogWarning("Threading is not supported on this platform. A fallback to main thread has been used. Be warned that this may produce deadlocks very easily.");
75 | #endif
76 | continuation();
77 | return;
78 | other:
79 | #endif
80 |
81 | hasSwitched = true;
82 | // We always spawn a new thread regardless if we are already in a background thread
83 | // because maybe that thread is from a pool and so it's not suitable for long running tasks.
84 | Task.Factory.StartNew(continuation, TaskCreationOptions.LongRunning);
85 | }
86 |
87 | ///
88 | IThreadSwitcher IThreadSwitcher.GetAwaiter()
89 | {
90 | #if UNITY_WEBGL
91 | #if UNITY_EDITOR
92 |
93 | if (useEditorPreference && hasSwitched)
94 | return hasSwitchedGlobal;
95 | #endif
96 | return hasSwitchedGlobal;
97 | #else
98 | return hasSwitched ? hasSwitchedGlobal : hasNotSwitchedGlobal;
99 | #endif
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/Runtime/Thread Switcher/ThreadSwitcherLongBackground.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 60d29ff68a1de974986c60d1fcfee2e9
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/Runtime/Thread Switcher/ThreadSwitcherUnity.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 |
4 | using UnityEngine;
5 |
6 | namespace Enderlook.Unity.Threading
7 | {
8 | ///
9 | /// Defines a switcher to jump to the Unity thread.
10 | ///
11 | public struct ThreadSwitcherUnity : IThreadSwitcher
12 | {
13 | // https://stackoverflow.com/a/58470597/7655838 from https://stackoverflow.com/questions/58469468/what-does-unitymainthreaddispatcher-do
14 |
15 | private static readonly IThreadSwitcher hasSwitchedGlobal = new ThreadSwitcherUnity() { hasSwitched = true };
16 | #if !UNITY_WEBGL
17 | private static readonly IThreadSwitcher hasNotSwitchedGlobal = new ThreadSwitcherUnity();
18 | #endif
19 |
20 | private bool hasSwitched;
21 |
22 | ///
23 | public ThreadSwitcherUnity GetAwaiter() => this;
24 |
25 | ///
26 | public bool IsCompleted => UnityThread.IsMainThread;
27 |
28 | ///
29 | public bool GetResult() => hasSwitched;
30 |
31 | ///
32 | public void OnCompleted(Action continuation)
33 | {
34 | if (continuation is null)
35 | Switch.ThrowArgumentNullException_Continuation();
36 |
37 | hasSwitched = !UnityThread.IsMainThread;
38 | if (!hasSwitched)
39 | {
40 | #if DEBUG
41 | Debug.Log("Already in main thread, this will do nothing.");
42 | #endif
43 | continuation();
44 | }
45 | else
46 | UnityThread.RunLater(continuation);
47 | }
48 |
49 | ///
50 | IThreadSwitcher IThreadSwitcher.GetAwaiter()
51 | {
52 | #if UNITY_WEBGL
53 | return hasSwitchedGlobal;
54 | #else
55 | return hasSwitched ? hasSwitchedGlobal : hasNotSwitchedGlobal;
56 | #endif
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/Runtime/Thread Switcher/ThreadSwitcherUnity.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: bc62494b485c0cd4aa666909c64ee0d1
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.enderlook.unity.async",
3 | "version": "0.2.5",
4 | "displayName": "Enderlook Unity Async",
5 | "description": "Provides utility methods for working with async/await.",
6 | "unity": "2019.2",
7 | "keywords": [
8 | "utility",
9 | "threading",
10 | "async",
11 | "await"
12 | ],
13 | "dependencies": {
14 | "com.enderlook.unity.threading": "https://github.com/Enderlook/Unity-Threading.git?/path=Packages/com.enderlook.unity.threading#com.enderlook.unity.threading/v0.7.7",
15 | "com.system.threading.tasks.extensions": "https://github.com/Enderlook/Unity-Net-Packages?path=Packages/com.system.threading.tasks.extensions#com.system.threading.tasks.extensions/v4.5.4"
16 | },
17 | "author": {
18 | "name": "Enderlook",
19 | "url": "https://github.com/Enderlook"
20 | }
21 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.async/package.json.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1d7db97af2c64ce41af941fc5e0fe61e
3 | PackageManifestImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3d643baf4ca660d43a1d29ccb023e68f
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Editor/AutomaticCoroutineScheduler.cs:
--------------------------------------------------------------------------------
1 | using UnityEditor;
2 |
3 | namespace Enderlook.Unity.Coroutines
4 | {
5 | [CustomEditor(typeof(AutomaticCoroutineScheduler))]
6 | internal sealed class AutomaticCoroutineSchedulerEditor : Editor
7 | {
8 | private SerializedProperty milisecondsExecutedPerFrameOnPoll;
9 | private SerializedProperty minimumPercentOfExecutionsPerFrameOnPoll;
10 |
11 | private void OnEnable()
12 | {
13 | SerializedProperty manager = serializedObject.FindProperty("manager");
14 | milisecondsExecutedPerFrameOnPoll = manager.FindPropertyRelative("milisecondsExecutedPerFrameOnPoll");
15 | minimumPercentOfExecutionsPerFrameOnPoll = manager.FindPropertyRelative("minimumPercentOfExecutionsPerFrameOnPoll");
16 | }
17 |
18 | public override void OnInspectorGUI()
19 | {
20 | base.OnInspectorGUI();
21 |
22 | EditorGUI.BeginChangeCheck();
23 | EditorGUILayout.PropertyField(milisecondsExecutedPerFrameOnPoll);
24 | EditorGUILayout.PropertyField(minimumPercentOfExecutionsPerFrameOnPoll);
25 | if (EditorGUI.EndChangeCheck())
26 | serializedObject.ApplyModifiedProperties();
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Editor/AutomaticCoroutineScheduler.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 48b2795b454a6bf4ca0ccfdb6d8ebe3c
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Editor/CoroutinesInfo.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 50e3710d2453cfb47b460e2aed428206
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Editor/Enderlook.Unity.Coroutines-Editor.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Enderlook.Unity.Coroutines-Editor",
3 | "references": [
4 | "GUID:7a7cdaeabbbb3ab4cb575ce2a8443842",
5 | "GUID:70bb7604d926506479be15f5272e3957",
6 | "GUID:12965892c664bf44cbd63f6568ef40da"
7 | ],
8 | "includePlatforms": [
9 | "Editor"
10 | ],
11 | "excludePlatforms": [],
12 | "allowUnsafeCode": false,
13 | "overrideReferences": false,
14 | "precompiledReferences": [],
15 | "autoReferenced": true,
16 | "defineConstraints": [],
17 | "versionDefines": []
18 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Editor/Enderlook.Unity.Coroutines-Editor.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d1143f8ae07f3c1429d292ac7b10d2a4
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Editor/GlobalCoroutinesManagerUnitEditor.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Unity.Toolset.Utils;
2 |
3 | using UnityEditor;
4 |
5 | using UnityEngine;
6 |
7 | namespace Enderlook.Unity.Coroutines
8 | {
9 | [CustomEditor(typeof(GlobalCoroutinesManagerUnit))]
10 | internal sealed class GlobalCoroutinesManagerUnitEditor : Editor
11 | {
12 | private SerializedProperty milisecondsExecutedPerFrameOnPoll;
13 | private GUIContent milisecondsExecutedPerFrameOnPollGUI;
14 |
15 | private SerializedProperty minimumPercentOfExecutionsPerFrameOnPoll;
16 | private GUIContent minimumPercentOfExecutionsPerFrameOnPollGUI;
17 |
18 | private void OnEnable()
19 | {
20 | milisecondsExecutedPerFrameOnPoll = serializedObject.FindProperty("milisecondsExecutedPerFrameOnPoll");
21 | milisecondsExecutedPerFrameOnPollGUI = new GUIContent(milisecondsExecutedPerFrameOnPoll.displayName, milisecondsExecutedPerFrameOnPoll.tooltip);
22 | minimumPercentOfExecutionsPerFrameOnPoll = serializedObject.FindProperty("minimumPercentOfExecutionsPerFrameOnPoll");
23 | minimumPercentOfExecutionsPerFrameOnPollGUI = new GUIContent(minimumPercentOfExecutionsPerFrameOnPoll.displayName, minimumPercentOfExecutionsPerFrameOnPoll.tooltip);
24 | }
25 |
26 | public override void OnInspectorGUI()
27 | {
28 | this.DrawScriptField();
29 |
30 | CoroutineManager shared = CoroutineManager.Shared;
31 | if (shared is null)
32 | {
33 | EditorGUI.BeginChangeCheck();
34 | {
35 | EditorGUILayout.PropertyField(milisecondsExecutedPerFrameOnPoll);
36 | EditorGUILayout.PropertyField(minimumPercentOfExecutionsPerFrameOnPoll);
37 | }
38 | if (EditorGUI.EndChangeCheck())
39 | serializedObject.ApplyModifiedProperties();
40 | }
41 | else
42 | {
43 | int milisecondsExecutedPerFrameOnPoll = shared.MilisecondsExecutedPerFrameOnPoll;
44 | int newMilisecondsExecutedPerFrameOnPoll = EditorGUILayout.IntField(milisecondsExecutedPerFrameOnPollGUI, milisecondsExecutedPerFrameOnPoll);
45 | newMilisecondsExecutedPerFrameOnPoll = Mathf.Max(newMilisecondsExecutedPerFrameOnPoll, 0);
46 | if (newMilisecondsExecutedPerFrameOnPoll != milisecondsExecutedPerFrameOnPoll)
47 | shared.MilisecondsExecutedPerFrameOnPoll = newMilisecondsExecutedPerFrameOnPoll;
48 |
49 | float minimumPercentOfExecutionsPerFrameOnPoll = shared.MinimumPercentOfExecutionsPerFrameOnPoll;
50 | float newMinimumPercentOfExecutionsPerFrameOnPoll = EditorGUILayout.Slider(minimumPercentOfExecutionsPerFrameOnPollGUI, minimumPercentOfExecutionsPerFrameOnPoll, 0, 1);
51 | if (newMinimumPercentOfExecutionsPerFrameOnPoll != minimumPercentOfExecutionsPerFrameOnPoll)
52 | shared.MinimumPercentOfExecutionsPerFrameOnPoll = newMinimumPercentOfExecutionsPerFrameOnPoll;
53 |
54 | EditorGUILayout.HelpBox("Modifications done will not be serialized in the scriptable object.", MessageType.Warning);
55 | }
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Editor/GlobalCoroutinesManagerUnitEditor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 35cfc1dea83270b46b2d08dbad91bab8
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ab33dddda64a17f458d48a4bf08b968d
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/EditorPoolContainer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Enderlook.Unity.Threading
4 | {
5 | #if UNITY_EDITOR
6 | ///
7 | /// Unity Editor Only.
8 | ///
9 | internal struct EditorPoolContainer : IComparable
10 | {
11 | private readonly string Name;
12 | private readonly Func count;
13 | private int currentCount;
14 | private string countString;
15 |
16 | public EditorPoolContainer(string name, Func count)
17 | {
18 | Name = name;
19 | this.count = count;
20 | int c = count();
21 | currentCount = c;
22 | countString = c.ToString();
23 | }
24 |
25 | public void Get(out string name, out string count)
26 | {
27 | name = Name;
28 | int c = this.count();
29 | if (currentCount != c)
30 | {
31 | currentCount = c;
32 | countString = c.ToString();
33 | }
34 | count = countString;
35 | }
36 |
37 | int IComparable.CompareTo(EditorPoolContainer other) => Name.CompareTo(other.Name);
38 | }
39 | #endif
40 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/EditorPoolContainer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5e4d6a687ba79084f8f6b3b286095f2b
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Enderlook.Unity.Coroutines.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Enderlook.Unity.Coroutines",
3 | "references": [
4 | "GUID:12965892c664bf44cbd63f6568ef40da"
5 | ],
6 | "includePlatforms": [],
7 | "excludePlatforms": [],
8 | "allowUnsafeCode": false,
9 | "overrideReferences": false,
10 | "precompiledReferences": [],
11 | "autoReferenced": true,
12 | "defineConstraints": [],
13 | "versionDefines": []
14 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Enderlook.Unity.Coroutines.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7a7cdaeabbbb3ab4cb575ce2a8443842
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/InternalsVisibleTo.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | [assembly: InternalsVisibleTo("Enderlook.Unity.Coroutines-Editor")]
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/InternalsVisibleTo.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a3b935b392d6f47439f3421f49c40b9f
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: af4ed8d11cb8add48b652b372d3f5ed4
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/CoroutineAwaiter.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Pools;
2 | using Enderlook.Unity.Threading;
3 |
4 | using System;
5 | using System.Collections;
6 | using System.Runtime.CompilerServices;
7 |
8 | using UnityEngine;
9 |
10 | namespace Enderlook.Unity.Coroutines
11 | {
12 | ///
13 | /// An awaiter for
14 | ///
15 | public readonly struct CoroutineAwaiter : INotifyCompletion
16 | {
17 | private readonly Handle handle;
18 | private readonly uint generation;
19 |
20 | private class Handle
21 | {
22 | public Action onCompleted;
23 |
24 | public bool isCompleted;
25 |
26 | public uint generation;
27 | }
28 |
29 | ///
30 | /// Creates an awaiter for the given .
31 | ///
32 | /// Job handle to await for.
33 | public CoroutineAwaiter(Coroutine coroutine)
34 | {
35 | Handle handle = ObjectPool.Shared.Rent();
36 | this.handle = handle;
37 | generation = handle.generation;
38 | Manager.Shared.StartCoroutine(Work());
39 | IEnumerator Work()
40 | {
41 | yield return coroutine;
42 | handle.isCompleted = true;
43 | handle.onCompleted?.Invoke();
44 | handle.generation++;
45 | ObjectPool.Shared.Return(handle);
46 | }
47 | }
48 |
49 | ///
50 | /// Return self.
51 | ///
52 | /// Self.
53 | public CoroutineAwaiter GetAwaiter() => this;
54 |
55 | ///
56 | /// Whenever the job handle has completed or not.
57 | ///
58 | public bool IsCompleted => generation != handle.generation || handle.isCompleted;
59 |
60 | ///
61 | /// Determines the action to run after the job handle has completed.
62 | ///
63 | /// Action to run.
64 | public void OnCompleted(Action continuation)
65 | {
66 | if (generation != handle.generation)
67 | continuation();
68 | if (IsCompleted)
69 | continuation();
70 | else
71 | handle.onCompleted += continuation;
72 | }
73 |
74 | ///
75 | /// Does nothing.
76 | ///
77 | public void GetResult() { }
78 | }
79 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/CoroutineAwaiter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7b08b5fe1d571f84e89bc1225abcea22
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/CoroutineAwaiterExtension.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace Enderlook.Unity.Coroutines
4 | {
5 | ///
6 | /// Allow get awaiter from .
7 | ///
8 | public static class CoroutineAwaiterExtension
9 | {
10 | ///
11 | /// Convert a to a task.
12 | ///
13 | /// Coroutine to convert.
14 | /// Task wrapper of a Unity coroutine.
15 | public static CoroutineAwaiter GetAwaiter(this Coroutine coroutine) => new CoroutineAwaiter(coroutine);
16 | }
17 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/CoroutineAwaiterExtension.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d945ab628e4cb704c9e5135efcb07d16
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/Wait.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Unity.Threading;
2 |
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Runtime.CompilerServices;
6 | using System.Threading.Tasks;
7 |
8 | using Unity.Jobs;
9 |
10 | using UnityEngine;
11 |
12 | namespace Enderlook.Unity.Coroutines
13 | {
14 | ///
15 | /// Provides a pool of waiters for Unity coroutines.
16 | ///
17 | public static class Wait
18 | {
19 | // https://github.com/svermeulen/Unity3dAsyncAwaitUtil/blob/master/UnityProject/Assets/Plugins/AsyncAwaitUtil/Source/Awaiters.cs
20 |
21 | ///
22 | public static readonly WaitForEndOfFrame ForEndOfFrame = new WaitForEndOfFrame();
23 |
24 | ///
25 | public static readonly WaitForFixedUpdate ForFixedUpdate = new WaitForFixedUpdate();
26 |
27 | ///
28 | public static readonly WaitForUpdate ForUpdate = new WaitForUpdate();
29 |
30 | private static readonly Dictionary waitForSeconds = new Dictionary();
31 | private static bool requestClear;
32 | private static float timeToNextClear;
33 |
34 | ///
35 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
36 | public static WaitForSeconds ForSeconds(float seconds)
37 | {
38 | if (!waitForSeconds.TryGetValue(seconds, out WaitForSeconds wait))
39 | return ForSecondsSlowPath(seconds);
40 | return wait;
41 | }
42 |
43 | static Wait()
44 | {
45 | Application.lowMemory += () => waitForSeconds.Clear();
46 | Manager.OnUpdate += () => {
47 | float realtimeSinceStartup = Time.realtimeSinceStartup;
48 | if (requestClear && realtimeSinceStartup > timeToNextClear)
49 | {
50 | requestClear = false;
51 | timeToNextClear = realtimeSinceStartup + 30;
52 | waitForSeconds.Clear();
53 | }
54 | };
55 | GCCallback _ = new GCCallback();
56 | }
57 |
58 | private sealed class GCCallback
59 | {
60 | private readonly StrongBox isQuitting;
61 |
62 | public GCCallback()
63 | {
64 | StrongBox isQuitting = new StrongBox();
65 | Application.quitting += () => isQuitting.Value = true;
66 | this.isQuitting = isQuitting;
67 | }
68 |
69 | ~GCCallback()
70 | {
71 | requestClear = true;
72 | if (!isQuitting.Value)
73 | GC.ReRegisterForFinalize(this);
74 | }
75 | }
76 |
77 | private static WaitForSeconds ForSecondsSlowPath(float seconds)
78 | {
79 | WaitForSeconds wait = new WaitForSeconds(seconds);
80 | waitForSeconds[seconds] = wait;
81 | return wait;
82 | }
83 |
84 | // TODO: shall we pool them?
85 |
86 | ///
87 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
88 | public static WaitUntilPooled Until(Func predicate)
89 | => WaitUntilPooled.Create(predicate);
90 |
91 | ///
92 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
93 | public static WaitWhilePooled While(Func predicate)
94 | => WaitWhilePooled.Create(predicate);
95 |
96 | ///
97 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
98 | public static WaitForJobComplete For(JobHandle handle)
99 | => WaitForJobComplete.Create(handle);
100 |
101 | ///
102 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
103 | public static WaitForTaskComplete For(Task task)
104 | => WaitForTaskComplete.Create(task);
105 |
106 | ///
107 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
108 | public static WaitForTaskComplete For(Task task)
109 | => WaitForTaskComplete.Create(task);
110 |
111 | ///
112 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
113 | public static WaitForValueTaskComplete For(ValueTask task)
114 | => WaitForValueTaskComplete.Create(task);
115 |
116 | ///
117 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
118 | public static WaitForValueTaskComplete For(ValueTask task)
119 | => WaitForValueTaskComplete.Create(task);
120 |
121 | ///
122 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
123 | public static WaitForSecondsRealtimePooled ForRealtime(float seconds)
124 | => WaitForSecondsRealtimePooled.Create(seconds);
125 |
126 | #if UNITY_EDITOR
127 | ///
128 | /// Unity Editor Only.
129 | ///
130 | internal static int ForSecondsCount => waitForSeconds.Count;
131 |
132 | ///
133 | /// Unity Editor Only.
134 | ///
135 | internal static void ForSecondsClear() => waitForSeconds.Clear();
136 |
137 | private static readonly SortedSet waitForTaskComplete = new SortedSet();
138 |
139 | ///
140 | /// Unity Editor Only.
141 | ///
142 | internal static IReadOnlyCollection ForTaskAndValueTaskComplete => waitForTaskComplete;
143 |
144 | ///
145 | /// Unity Editor Only.
146 | ///
147 | internal static void AddWaitForTaskComplete(string name, Func count)
148 | => waitForTaskComplete.Add(new EditorPoolContainer(name, count));
149 | #endif
150 | }
151 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/Wait.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d1b5c0ae7b57ded49a617c395d8c7c9f
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitForJobComplete.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Pools;
2 |
3 | using System.Runtime.CompilerServices;
4 |
5 | using Unity.Jobs;
6 |
7 | using UnityEngine;
8 |
9 | namespace Enderlook.Unity.Coroutines
10 | {
11 | ///
12 | /// Suspend the coroutine execution until the supplied job handles is completed.
13 | ///
14 | public sealed class WaitForJobComplete : CustomYieldInstruction
15 | {
16 | private JobHandle handle;
17 |
18 | public override bool keepWaiting {
19 | get {
20 | if (handle.IsCompleted)
21 | {
22 | handle.Complete();
23 | handle = default;
24 | ObjectPool.Shared.Return(this);
25 | return false;
26 | }
27 | return true;
28 | }
29 | }
30 |
31 | #if UNITY_EDITOR
32 | ///
33 | /// Unity Editor Only.
34 | ///
35 | internal static int Count => ObjectPool.Shared.ApproximateCount();
36 | #endif
37 |
38 | ///
39 | /// Suspend the coroutine execution until the supplied job handles is completed.
40 | /// The instance is draw from a pool.
41 | ///
42 | /// Job handle to wait.
43 | /// A waiter.
44 | internal static WaitForJobComplete Create(JobHandle handle)
45 | {
46 | WaitForJobComplete waiter = ObjectPool.Shared.Rent();
47 | waiter.handle = handle;
48 | return waiter;
49 | }
50 |
51 | ///
52 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
53 | public static implicit operator WaitForJobComplete(JobHandle handle) => Create(handle);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitForJobComplete.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 192be9b702c1a38499ef6a4ab4e9146e
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitForSecondsRealtimePooled.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Pools;
2 |
3 | using UnityEngine;
4 |
5 | namespace Enderlook.Unity.Coroutines
6 | {
7 | ///
8 | /// Suspend the coroutine execution until the supplied seconds in realtime has passed.
9 | ///
10 | public sealed class WaitForSecondsRealtimePooled : CustomYieldInstruction
11 | {
12 | internal float waitUntil;
13 |
14 | public override bool keepWaiting {
15 | get {
16 | if (Time.realtimeSinceStartup >= waitUntil)
17 | {
18 | ObjectPool.Shared.Return(this);
19 | return false;
20 | }
21 | return true;
22 | }
23 | }
24 |
25 | #if UNITY_EDITOR
26 | ///
27 | /// Unity Editor Only.
28 | ///
29 | internal static int Count => ObjectPool.Shared.ApproximateCount();
30 | #endif
31 |
32 | ///
33 | /// Suspend the coroutine execution until the supplied seconds in realtime has passed.
34 | /// The instance is draw from a pool.
35 | ///
36 | /// Time in seconds to wait.
37 | /// A waiter.
38 | internal static WaitForSecondsRealtimePooled Create(float seconds)
39 | {
40 | WaitForSecondsRealtimePooled waiter = ObjectPool.Shared.Rent();
41 | waiter.waitUntil = seconds + Time.realtimeSinceStartup;
42 | return waiter;
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitForSecondsRealtimePooled.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 352c79b0cc9ca1e4a94851094dab1834
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitForTaskComplete.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Pools;
2 |
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.ExceptionServices;
5 | using System.Threading.Tasks;
6 |
7 | using UnityEngine;
8 |
9 | namespace Enderlook.Unity.Coroutines
10 | {
11 | ///
12 | /// Suspend the coroutine execution until the supplied task is completed.
13 | ///
14 | public sealed class WaitForTaskComplete : CustomYieldInstruction
15 | {
16 | private Task task;
17 |
18 | public override bool keepWaiting {
19 | get {
20 | if (task.IsCompleted)
21 | {
22 | Task task = this.task;
23 | this.task = default;
24 | ObjectPool.Shared.Return(this);
25 | if (task.IsFaulted)
26 | ExceptionDispatchInfo.Capture(task.Exception).Throw();
27 | return false;
28 | }
29 | return true;
30 | }
31 | }
32 |
33 | #if UNITY_EDITOR
34 | ///
35 | /// Unity Editor Only.
36 | ///
37 | internal static int Count => ObjectPool.Shared.ApproximateCount();
38 | #endif
39 |
40 | ///
41 | /// Suspend the coroutine execution until the supplied task is completed.
42 | /// Object is drawn from a pool.
43 | ///
44 | /// Task to wait.
45 | /// A waiter.
46 | internal static WaitForTaskComplete Create(Task task)
47 | {
48 | WaitForTaskComplete waiter = ObjectPool.Shared.Rent();
49 | waiter.task = task;
50 | return waiter;
51 | }
52 |
53 | ///
54 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
55 | public static implicit operator WaitForTaskComplete(Task task) => Create(task);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitForTaskComplete.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c1ab514a9c9a4a64db1b30f1fbd8d433
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitForTaskComplete`1.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Pools;
2 |
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.ExceptionServices;
5 | using System.Threading.Tasks;
6 |
7 | using UnityEngine;
8 |
9 | namespace Enderlook.Unity.Coroutines
10 | {
11 | ///
12 | /// Suspend the coroutine execution until the supplied task is completed.
13 | ///
14 | /// Return type of task.
15 | public sealed class WaitForTaskComplete : CustomYieldInstruction
16 | {
17 | private Task task;
18 |
19 | public override bool keepWaiting {
20 | get {
21 | if (task.IsCompleted)
22 | {
23 | Task task = this.task;
24 | this.task = default;
25 | ObjectPool>.Shared.Return(this);
26 | if (task.IsFaulted)
27 | ExceptionDispatchInfo.Capture(task.Exception).Throw();
28 | return false;
29 | }
30 | return true;
31 | }
32 | }
33 |
34 | #if UNITY_EDITOR
35 | static WaitForTaskComplete()
36 | => Wait.AddWaitForTaskComplete($"Wait.For({typeof(WaitForTaskComplete).Name})", () => ObjectPool>.Shared.ApproximateCount());
37 | #endif
38 |
39 | ///
40 | /// Suspend the coroutine execution until the supplied task is completed.
41 | /// Object is drawn from a pool.
42 | ///
43 | /// Task to wait.
44 | /// A waiter.
45 | internal static WaitForTaskComplete Create(Task task)
46 | {
47 | WaitForTaskComplete waiter = ObjectPool>.Shared.Rent();
48 | waiter.task = task;
49 | return waiter;
50 | }
51 |
52 | ///
53 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
54 | public static implicit operator WaitForTaskComplete(Task task)
55 | => Create(task);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitForTaskComplete`1.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f10fffb2a1ef54e4387c95c85688e3c0
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitForUpdate.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace Enderlook.Unity.Coroutines
4 | {
5 | ///
6 | /// Wait until the next frame, same as passing to a coroutine.
7 | ///
8 | public sealed class WaitForUpdate : CustomYieldInstruction
9 | {
10 | // https://github.com/svermeulen/Unity3dAsyncAwaitUtil/blob/master/UnityProject/Assets/Plugins/AsyncAwaitUtil/Source/WaitForUpdate.cs
11 |
12 | ///
13 | public override bool keepWaiting => false;
14 |
15 | internal WaitForUpdate() { }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitForUpdate.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d2d71c158c83d4147a325ae98df24efd
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitForValueTaskComplete.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Pools;
2 |
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.ExceptionServices;
5 | using System.Threading.Tasks;
6 |
7 | using UnityEngine;
8 |
9 | namespace Enderlook.Unity.Coroutines
10 | {
11 | ///
12 | /// Suspend the coroutine execution until the supplied task is completed.
13 | ///
14 | public sealed class WaitForValueTaskComplete : CustomYieldInstruction
15 | {
16 | private ValueTask task;
17 |
18 | public override bool keepWaiting {
19 | get {
20 | if (task.IsCompleted)
21 | {
22 | ValueTask task = this.task;
23 | this.task = default;
24 | ObjectPool.Shared.Return(this);
25 | if (task.IsFaulted)
26 | ExceptionDispatchInfo.Capture(task.AsTask().Exception).Throw();
27 | return false;
28 | }
29 | return true;
30 | }
31 | }
32 |
33 | #if UNITY_EDITOR
34 | ///
35 | /// Unity Editor Only.
36 | ///
37 | internal static int Count => ObjectPool.Shared.ApproximateCount();
38 | #endif
39 |
40 | ///
41 | /// Suspend the coroutine execution until the supplied task is completed.
42 | /// Object is drawn from a pool.
43 | ///
44 | /// Task to wait.
45 | /// A waiter.
46 | internal static WaitForValueTaskComplete Create(ValueTask task)
47 | {
48 | WaitForValueTaskComplete waiter = ObjectPool.Shared.Rent();
49 | waiter.task = task;
50 | return waiter;
51 | }
52 |
53 | ///
54 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
55 | public static implicit operator WaitForValueTaskComplete(ValueTask task) => Create(task);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitForValueTaskComplete.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fbbaaa304d25abb4885cb989f38bc1b1
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitForValueTaskComplete`1.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Collections.LowLevel;
2 | using Enderlook.Pools;
3 |
4 | using System;
5 | using System.Runtime.CompilerServices;
6 | using System.Runtime.ExceptionServices;
7 | using System.Threading.Tasks;
8 |
9 | using UnityEngine;
10 |
11 | namespace Enderlook.Unity.Coroutines
12 | {
13 | ///
14 | /// Suspend the coroutine execution until the supplied task is completed.
15 | ///
16 | /// Return type of task.
17 | public sealed class WaitForValueTaskComplete : CustomYieldInstruction
18 | {
19 | private ValueTask task;
20 |
21 | public override bool keepWaiting {
22 | get {
23 | if (task.IsCompleted)
24 | {
25 | ValueTask task = this.task;
26 | this.task = default;
27 | ObjectPool>.Shared.Return(this);
28 | if (task.IsFaulted)
29 | ExceptionDispatchInfo.Capture(task.AsTask().Exception).Throw();
30 | return false;
31 | }
32 | return true;
33 | }
34 | }
35 |
36 | #if UNITY_EDITOR
37 | static WaitForValueTaskComplete()
38 | {
39 | Wait.AddWaitForTaskComplete($"Wait.For({typeof(WaitForValueTaskComplete).Name})", () => ObjectPool>.Shared.ApproximateCount());
40 | }
41 | #endif
42 |
43 | ///
44 | /// Suspend the coroutine execution until the supplied task is completed.
45 | /// Object is drawn from a pool.
46 | ///
47 | /// Task to wait.
48 | /// A waiter.
49 | internal static WaitForValueTaskComplete Create(ValueTask task)
50 | {
51 | WaitForValueTaskComplete waiter = ObjectPool>.Shared.Rent();
52 | waiter.task = task;
53 | return waiter;
54 | }
55 |
56 | ///
57 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
58 | public static implicit operator WaitForValueTaskComplete(ValueTask task)
59 | => Create(task);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitForValueTaskComplete`1.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f1380cd52c0e4b84792d33a91cb2b5d6
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitUntilPooled.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Pools;
2 |
3 | using System;
4 |
5 | using UnityEngine;
6 |
7 | namespace Enderlook.Unity.Coroutines
8 | {
9 | ///
10 | /// Suspend the coroutine execution until the supplied delegate evaluates to .
11 | ///
12 | public sealed class WaitUntilPooled : CustomYieldInstruction
13 | {
14 | private Func predicate;
15 |
16 | ///
17 | public override bool keepWaiting {
18 | get {
19 | if (predicate())
20 | {
21 | predicate = null;
22 | ObjectPool.Shared.Return(this);
23 | return false;
24 | }
25 | return true;
26 | }
27 | }
28 |
29 | #if UNITY_EDITOR
30 | ///
31 | /// Unity Editor Only.
32 | ///
33 | internal static int Count => ObjectPool.Shared.ApproximateCount();
34 | #endif
35 |
36 | ///
37 | /// Suspend the coroutine execution until the supplied delegate evaluates to .
38 | /// Object is drawn from a pool.
39 | ///
40 | /// Delegate to evaluate.
41 | /// A waiter.
42 | internal static WaitUntilPooled Create(Func predicate)
43 | {
44 | WaitUntilPooled waiter = ObjectPool.Shared.Rent();
45 | waiter.predicate = predicate;
46 | return waiter;
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitUntilPooled.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ff7eeaa1f6c33c54490c6872caf91604
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitWhilePooled.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Collections.LowLevel;
2 | using Enderlook.Pools;
3 |
4 | using System;
5 |
6 | using UnityEngine;
7 |
8 | namespace Enderlook.Unity.Coroutines
9 | {
10 | ///
11 | /// Suspend the coroutine execution until the supplied delegate evaluates to .
12 | ///
13 | public sealed class WaitWhilePooled : CustomYieldInstruction
14 | {
15 | private Func predicate;
16 |
17 | ///
18 | public override bool keepWaiting {
19 | get {
20 | if (!predicate())
21 | {
22 | predicate = null;
23 | ObjectPool.Shared.Return(this);
24 | return false;
25 | }
26 | return true;
27 | }
28 | }
29 |
30 | #if UNITY_EDITOR
31 | ///
32 | /// Unity Editor Only.
33 | ///
34 | internal static int Count => ObjectPool.Shared.ApproximateCount();
35 | #endif
36 |
37 | ///
38 | /// Suspend the coroutine execution until the supplied delegate evaluates to .
39 | /// Object is drawn from a pool.
40 | ///
41 | /// Delegate to evaluate.
42 | /// A waiter.
43 | internal static WaitWhilePooled Create(Func predicate)
44 | {
45 | WaitWhilePooled waiter = ObjectPool.Shared.Rent();
46 | waiter.predicate = predicate;
47 | return waiter;
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Unity Coroutines/WaitWhilePooled.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6686891f0d7cb814fb432cb0a664ebe7
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Utility.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 990efe386edb50a40bb0398fcd7aedb0
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Utility/PackList.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Collections.LowLevel;
2 | using Enderlook.Unity.Threading;
3 |
4 | using System;
5 | using System.Collections.Concurrent;
6 | using System.Runtime.CompilerServices;
7 |
8 | using UnityEngine;
9 |
10 | namespace Enderlook.Unity.Coroutines
11 | {
12 | internal struct PackList
13 | {
14 | // This can't be a property because the struct would be copied instead of being mutated.
15 | // Instead if this is a field, mutations would be on the reference.
16 | public RawList List;
17 |
18 | #if !UNITY_WEBGL
19 | public ConcurrentBag Concurrent { get; private set; }
20 | #endif
21 |
22 | #if UNITY_WEBGL
23 | public int Count => List.Count;
24 | #else
25 | public int Count => List.Count + Concurrent.Count;
26 | #endif
27 |
28 | public static PackList Create() => new PackList()
29 | {
30 | List = RawList.Create(),
31 | #if !UNITY_WEBGL
32 | Concurrent = new ConcurrentBag(),
33 | #endif
34 | };
35 |
36 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
37 | public RawList Swap(RawList list)
38 | {
39 | // This is not atomic. However it does't matter since `List` and `Swap` are only used in the main thread.
40 | RawList old = List;
41 | List = list;
42 | return old;
43 | }
44 |
45 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
46 | public void Add(T element)
47 | {
48 | #if DEBUG
49 | if (!UnityThread.IsMainThread)
50 | Debug.LogError("This function can only be executed in the Unity thread. This has produced undefined behaviour. This message will not shown on release.");
51 | #endif
52 | List.Add(element);
53 | }
54 |
55 | #if !UNITY_WEBGL
56 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
57 | public void ConcurrentAdd(T element)
58 | {
59 | #if DEBUG
60 | if (UnityThread.IsMainThread)
61 | Debug.LogWarning("This function was executed in the main thread. This is not an error, thought it's more perfomant to call the non-concurrent version instead. This message will not shown on release.");
62 | #endif
63 | Concurrent.Add(element);
64 | }
65 | #endif
66 | }
67 |
68 | internal static class PackList
69 | {
70 | public static void Dispose(this ref PackList pack) where T : IDisposable
71 | {
72 | RawList list = pack.List;
73 | for (int i = 0; i < list.Count; i++)
74 | list[i].Dispose();
75 | pack.List.Clear();
76 |
77 | #if !UNITY_WEBGL
78 | ConcurrentBag bag = pack.Concurrent;
79 | while (bag.TryTake(out T result))
80 | result.Dispose();
81 | #endif
82 | }
83 |
84 | public static void Dispose(this ref PackList<(U, T)> pack) where T : IDisposable
85 | {
86 | RawList<(U, T)> list = pack.List;
87 | for (int i = 0; i < list.Count; i++)
88 | list[i].Item2.Dispose();
89 | pack.List.Clear();
90 |
91 | #if !UNITY_WEBGL
92 | ConcurrentBag<(U, T)> bag = pack.Concurrent;
93 | while (bag.TryTake(out (U, T) result))
94 | result.Item2.Dispose();
95 | #endif
96 | }
97 | }
98 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Utility/PackList.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: efee94e00bd41404d81ec019753ea59b
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Utility/PackQueue.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Collections.LowLevel;
2 | using Enderlook.Unity.Threading;
3 |
4 | using System;
5 | using System.Collections.Concurrent;
6 | using System.Runtime.CompilerServices;
7 |
8 | using UnityEngine;
9 |
10 | namespace Enderlook.Unity.Coroutines
11 | {
12 | internal struct PackQueue
13 | {
14 | // This can't be a property because the struct would be copied instead of being mutated.
15 | // Instead if this is a field, mutations would be on the reference.
16 | public RawQueue Queue;
17 |
18 | #if !UNITY_WEBGL
19 | public ConcurrentQueue Concurrent { get; private set; }
20 | #endif
21 |
22 | #if UNITY_WEBGL
23 | public int Count => Queue.Count;
24 | #else
25 | public int Count => Queue.Count + Concurrent.Count;
26 | #endif
27 |
28 | public static PackQueue Create() => new PackQueue()
29 | {
30 | Queue = RawQueue.Create(),
31 | #if !UNITY_WEBGL
32 | Concurrent = new ConcurrentQueue(),
33 | #endif
34 | };
35 |
36 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
37 | public RawQueue Swap(RawQueue queue)
38 | {
39 | // This is not atomic. However it does't matter since `Queue` and `Swap` are only used in the main thread.
40 | RawQueue old = Queue;
41 | Queue = queue;
42 | return old;
43 | }
44 |
45 | #if !UNITY_WEBGL
46 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
47 | public void DrainConcurrent()
48 | {
49 | ConcurrentQueue queue = Concurrent;
50 | RawQueue local = Queue;
51 | while (queue.TryDequeue(out T routine))
52 | local.Enqueue(routine);
53 | Queue = local;
54 | }
55 | #endif
56 |
57 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
58 | public void Enqueue(T element)
59 | {
60 | #if DEBUG
61 | if (!UnityThread.IsMainThread)
62 | Debug.LogError("This function can only be executed in the Unity thread. This has produced undefined behaviour. This message will not shown on release.");
63 | #endif
64 | Queue.Enqueue(element);
65 | }
66 |
67 | #if !UNITY_WEBGL
68 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
69 | public void ConcurrentEnqueue(T element)
70 | {
71 | #if DEBUG
72 | if (UnityThread.IsMainThread)
73 | Debug.LogWarning("This function was executed in the main thread. This is not an error, thought it's more perfomant to call the non-concurrent version instead. This message will not shown on release.");
74 | #endif
75 | Concurrent.Enqueue(element);
76 | }
77 | #endif
78 | }
79 |
80 | internal static class PackQueue
81 | {
82 | public static void Dispose(this ref PackQueue pack) where T : IDisposable
83 | {
84 | RawQueue queue = pack.Queue;
85 | while (queue.TryDequeue(out T result))
86 | result.Dispose();
87 | pack.Queue = queue;
88 |
89 | #if !UNITY_WEBGL
90 | ConcurrentQueue concurrentQueue = pack.Concurrent;
91 | while (concurrentQueue.TryDequeue(out T result))
92 | result.Dispose();
93 | #endif
94 | }
95 | }
96 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Utility/PackQueue.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cdd349c9625c2c049a6149535c6a7248
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Utility/ReadWriterLock.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 |
3 | namespace Enderlook.Unity.Coroutines
4 | {
5 | internal struct ReadWriterLock
6 | {
7 | private int locked;
8 | private int readers;
9 |
10 | private void Lock()
11 | {
12 | while (Interlocked.Exchange(ref locked, 1) != 0) ;
13 | }
14 |
15 | private void Unlock() => locked = 0;
16 |
17 | public void ReadBegin()
18 | {
19 | Lock();
20 | readers++;
21 | Unlock();
22 | }
23 |
24 | public void ReadEnd()
25 | {
26 | Lock();
27 | readers--;
28 | Unlock();
29 | }
30 |
31 | public void WriteBegin()
32 | {
33 | while (true)
34 | {
35 | Lock();
36 | if (readers > 0)
37 | Unlock();
38 | else
39 | break;
40 | }
41 | }
42 |
43 | public void WriteEnd() => Unlock();
44 | }
45 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Utility/ReadWriterLock.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 485f2b84745c3a64883e0af17485b31b
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4f5b36b7b0bf74c40b7f2e2037f8d0f7
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7fd35f1db4442db48b7b22787c45fad3
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/AutomaticCoroutineScheduler.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2e3f34a16bce32547bd4db7d30a5675e
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/CoroutineExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.ComponentModel;
3 | using System.Runtime.CompilerServices;
4 |
5 | using UnityEngine;
6 |
7 | namespace Enderlook.Unity.Coroutines
8 | {
9 | ///
10 | /// Aditional methods for value coroutines.
11 | ///
12 | [EditorBrowsable(EditorBrowsableState.Never)]
13 | public static class CoroutineExtensions
14 | {
15 | ///
16 | [EditorBrowsable(EditorBrowsableState.Never)]
17 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
18 | public static void StartValueCoroutine(this GameObject source, T routine)
19 | where T : IEnumerator
20 | => CoroutineManager.Shared.Start(routine, source);
21 |
22 | ///
23 | [EditorBrowsable(EditorBrowsableState.Never)]
24 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
25 | public static ValueCoroutine StartValueCoroutineWithValueHandle(this GameObject source, T routine)
26 | where T : IEnumerator
27 | => CoroutineManager.Shared.StartWithHandle(routine, source);
28 |
29 | ///
30 | [EditorBrowsable(EditorBrowsableState.Never)]
31 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
32 | public static void StartValueCoroutine(this MonoBehaviour source, T routine, bool suspendWhenSourceIsDisabled = false)
33 | where T : IEnumerator
34 | => CoroutineManager.Shared.Start(routine, source, suspendWhenSourceIsDisabled);
35 |
36 | ///
37 | [EditorBrowsable(EditorBrowsableState.Never)]
38 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
39 | public static ValueCoroutine StartValueCoroutineWithValueHandle(this MonoBehaviour source, T routine, bool suspendWhenSourceIsDisabled = false)
40 | where T : IEnumerator
41 | => CoroutineManager.Shared.StartWithHandle(routine, source, suspendWhenSourceIsDisabled);
42 | }
43 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/CoroutineExtensions.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e2651dea72d9ca644b8655051bad5b63
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/CoroutineManager.ManagerBase.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Collections.LowLevel;
2 |
3 | using System.Threading.Tasks;
4 |
5 | namespace Enderlook.Unity.Coroutines
6 | {
7 | public sealed partial class CoroutineManager
8 | {
9 | private abstract class ManagerBase
10 | {
11 | public abstract void OnUpdate();
12 |
13 | public abstract void OnFixedUpdate();
14 |
15 | public abstract void OnLateUpdate();
16 |
17 | public abstract void OnEndOfFrame();
18 |
19 | public abstract int PollCount { get; }
20 |
21 | public abstract void OnPoll(int until, bool guaranteMinimumExecution);
22 |
23 | #if !UNITY_WEBGL
24 | public abstract void BackgroundResume();
25 | #endif
26 |
27 | public abstract void Dispose(ref RawQueue tasks);
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/CoroutineManager.ManagerBase.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a33b711dbfa243149b392b18aab5dabf
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/CoroutineManager.NestedEnumerator.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | using UnityEngine;
4 |
5 | namespace Enderlook.Unity.Coroutines
6 | {
7 | public sealed partial class CoroutineManager
8 | {
9 | private struct NestedEnumerator : IValueCoroutineEnumerator
10 | where TEnumerator1 : IValueCoroutineEnumerator
11 | where TEnumerator2 : IValueCoroutineEnumerator
12 | where TCallback : INextCallback
13 | {
14 | private readonly TypedManager parentManager;
15 | private TEnumerator1 parent;
16 | private TEnumerator2 child;
17 | private TCallback callback;
18 |
19 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
20 | public NestedEnumerator(TypedManager parentManager, TEnumerator1 parent, TEnumerator2 child, TCallback callback)
21 | {
22 | this.parentManager = parentManager;
23 | this.parent = parent;
24 | this.child = child;
25 | this.callback = callback;
26 | }
27 |
28 | public ValueCoroutineState State {
29 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
30 | get => ValueCoroutineStateHelper.Merge(parent.State, child.State);
31 | }
32 |
33 | #if !UNITY_WEBGL
34 | public ValueCoroutineState ConcurrentState {
35 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
36 | get => ValueCoroutineStateHelper.Merge(parent.ConcurrentState, child.State);
37 | }
38 | #endif
39 |
40 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
41 | public void Dispose()
42 | {
43 | if (parent.State == ValueCoroutineState.Finalized)
44 | parent.Dispose();
45 | child.Dispose();
46 | }
47 |
48 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
49 | public ValueYieldInstruction Next()
50 | {
51 | switch (parent.State)
52 | {
53 | case ValueCoroutineState.Finalized:
54 | return Yield.Finalized;
55 | case ValueCoroutineState.Suspended:
56 | return Yield.Suspended;
57 | case ValueCoroutineState.Continue:
58 | ValueYieldInstruction instruction = child.Next();
59 | if (instruction.Mode == ValueYieldInstruction.Type.Finalized)
60 | parentManager.Next(parent, callback);
61 | return instruction;
62 | default:
63 | Debug.Assert(false, "Impossible state.");
64 | goto case ValueCoroutineState.Continue;
65 | }
66 | }
67 |
68 | #if !UNITY_WEBGL
69 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
70 | public ValueYieldInstruction ConcurrentNext(ThreadMode mode)
71 | {
72 | switch (parent.ConcurrentState)
73 | {
74 | case ValueCoroutineState.Finalized:
75 | return Yield.Finalized;
76 | case ValueCoroutineState.Suspended:
77 | return Yield.Suspended;
78 | case ValueCoroutineState.Continue:
79 | ValueYieldInstruction instruction = child.ConcurrentNext(mode);
80 | if (instruction.Mode == ValueYieldInstruction.Type.Finalized)
81 | parentManager.NextBackground(parent, callback, mode);
82 | return instruction;
83 | default:
84 | Debug.Assert(false, "Impossible state.");
85 | goto case ValueCoroutineState.Continue;
86 | }
87 | }
88 | #endif
89 | }
90 | }
91 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/CoroutineManager.NestedEnumerator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 07b5daeee447aba419afcf2df2f6fac4
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/CoroutineManager.NestedEnumeratorBackground.cs:
--------------------------------------------------------------------------------
1 | #if !UNITY_WEBGL
2 | using System.Runtime.CompilerServices;
3 |
4 | using UnityEngine;
5 |
6 | namespace Enderlook.Unity.Coroutines
7 | {
8 | public sealed partial class CoroutineManager
9 | {
10 | private struct NestedEnumeratorBackground : IValueCoroutineEnumerator
11 | where TEnumerator1 : IValueCoroutineEnumerator
12 | where TEnumerator2 : IValueCoroutineEnumerator
13 | where TCallback : INextCallback
14 | {
15 | private readonly TypedManager parentManager;
16 | private TEnumerator1 parent;
17 | private TEnumerator2 child;
18 | private TCallback callback;
19 | private ThreadMode mode;
20 |
21 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
22 | public NestedEnumeratorBackground(TypedManager parentManager, TEnumerator1 parent, TEnumerator2 child, TCallback callback, ThreadMode mode)
23 | {
24 | this.parentManager = parentManager;
25 | this.parent = parent;
26 | this.child = child;
27 | this.callback = callback;
28 | this.mode = mode;
29 | }
30 |
31 | public ValueCoroutineState State {
32 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
33 | get => ValueCoroutineStateHelper.Merge(parent.State, child.State);
34 | }
35 |
36 | public ValueCoroutineState ConcurrentState {
37 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
38 | get {
39 | switch (parent.ConcurrentState)
40 | {
41 | case ValueCoroutineState.Continue:
42 | return child.ConcurrentState;
43 | case ValueCoroutineState.Suspended:
44 | switch (child.ConcurrentState)
45 | {
46 | case ValueCoroutineState.Finalized:
47 | return ValueCoroutineState.Finalized;
48 | default:
49 | return ValueCoroutineState.Suspended;
50 | }
51 | case ValueCoroutineState.Finalized:
52 | return ValueCoroutineState.Finalized;
53 | default:
54 | #if UNITY_EDITOR
55 | Debug.Assert(false, "Impossible state.");
56 | #endif
57 | goto case ValueCoroutineState.Continue;
58 | }
59 | }
60 | }
61 |
62 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
63 | public void Dispose() => child.Dispose();
64 |
65 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
66 | public ValueYieldInstruction Next()
67 | {
68 | switch (parent.State)
69 | {
70 | case ValueCoroutineState.Continue:
71 | ValueYieldInstruction instruction = child.Next();
72 | if (instruction.Mode == ValueYieldInstruction.Type.Finalized)
73 | parentManager.NextBackground(parent, callback, mode);
74 | return instruction;
75 | case ValueCoroutineState.Finalized:
76 | return Yield.Finalized;
77 | case ValueCoroutineState.Suspended:
78 | return Yield.Suspended;
79 | default:
80 | #if UNITY_EDITOR
81 | Debug.Assert(false, "Impossible state.");
82 | #endif
83 | goto case ValueCoroutineState.Continue;
84 | }
85 | }
86 |
87 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
88 | public ValueYieldInstruction ConcurrentNext(ThreadMode mode)
89 | {
90 | switch (parent.ConcurrentState)
91 | {
92 | case ValueCoroutineState.Continue:
93 | ValueYieldInstruction instruction = child.ConcurrentNext(mode);
94 | if (instruction.Mode == ValueYieldInstruction.Type.Finalized)
95 | parentManager.NextBackground(parent, callback, mode);
96 | return instruction;
97 | case ValueCoroutineState.Finalized:
98 | return Yield.Finalized;
99 | case ValueCoroutineState.Suspended:
100 | return Yield.Suspended;
101 | default:
102 | #if UNITY_EDITOR
103 | Debug.Assert(false, "Impossible state.");
104 | #endif
105 | goto case ValueCoroutineState.Continue;
106 | }
107 | }
108 | }
109 | }
110 | }
111 | #endif
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/CoroutineManager.NestedEnumeratorBackground.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c9f1818415deb8e49a92f1b5c2108ccf
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/CoroutineManager.On.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Collections.LowLevel;
2 | using Enderlook.Unity.Threading;
3 |
4 | using System;
5 |
6 | using UnityEngine;
7 |
8 | namespace Enderlook.Unity.Coroutines
9 | {
10 | public sealed partial class CoroutineManager
11 | {
12 | ///
13 | /// Returns an aproximate number of coroutines that are waiting for poll.
14 | /// Since this method is not synchronized, due multithreading scenarios it may not give exact results.
15 | ///
16 | public int PollCount
17 | {
18 | get
19 | {
20 | int total = 0;
21 | RawList managers = GetManagersList();
22 | for (int i = 0; i < managers.Count; i++)
23 | total += managers[i].PollCount;
24 | return total;
25 | }
26 | }
27 |
28 | ///
29 | /// Executes the update event of all coroutines.
30 | ///
31 | public void OnUpdate()
32 | {
33 | if (!UnityThread.IsMainThread)
34 | ThrowNonUnityThread();
35 |
36 | if (state != ValueCoroutineState.Continue)
37 | return;
38 |
39 | RawList managers = GetManagersList();
40 | for (int i = 0; i < managers.Count; i++)
41 | managers[i].OnUpdate();
42 | }
43 |
44 | ///
45 | /// Executes the late update event of all coroutines.
46 | ///
47 | public void OnLateUpdate()
48 | {
49 | if (!UnityThread.IsMainThread)
50 | ThrowNonUnityThread();
51 |
52 | if (state != ValueCoroutineState.Continue)
53 | return;
54 |
55 | RawList managers = GetManagersList();
56 | for (int i = 0; i < managers.Count; i++)
57 | managers[i].OnLateUpdate();
58 | }
59 |
60 | ///
61 | /// Executes the fixed update event of all coroutines.
62 | ///
63 | public void OnFixedUpdate()
64 | {
65 | if (!UnityThread.IsMainThread)
66 | ThrowNonUnityThread();
67 |
68 | if (state != ValueCoroutineState.Continue)
69 | return;
70 |
71 | RawList managers = GetManagersList();
72 | for (int i = 0; i < managers.Count; i++)
73 | managers[i].OnFixedUpdate();
74 | }
75 |
76 | ///
77 | /// Executes the end of frame event of all coroutines.
78 | ///
79 | public void OnEndOfFrame()
80 | {
81 | if (!UnityThread.IsMainThread)
82 | ThrowNonUnityThread();
83 |
84 | if (state != ValueCoroutineState.Continue)
85 | return;
86 |
87 | RawList managers = GetManagersList();
88 | for (int i = 0; i < managers.Count; i++)
89 | managers[i].OnEndOfFrame();
90 | }
91 |
92 | ///
93 | /// Executes the poll event of all coroutines.
94 | ///
95 | public void OnPoll()
96 | {
97 | if (!UnityThread.IsMainThread)
98 | ThrowNonUnityThread();
99 |
100 | if (state != ValueCoroutineState.Continue)
101 | return;
102 |
103 | int until = DateTime.Now.Millisecond + milisecondsExecutedPerFrameOnPoll;
104 | RawList managersList = GetManagersList();
105 | for (int i = 0; i < managersList.Count; i++)
106 | managersList[i].OnPoll(until, true);
107 |
108 | while (true)
109 | {
110 | // GetManagersList() is inside the loop because new managers may be added during the iterations.
111 | managersList = GetManagersList();
112 | if (managersList.Count == 0)
113 | break;
114 |
115 | for (int i = 0; i < managersList.Count; i++)
116 | {
117 | if (DateTime.Now.Millisecond > until)
118 | break;
119 | if (managersList[i].PollCount > 0)
120 | goto next;
121 | }
122 | break;
123 |
124 | next:;
125 | for (int i = 0; i < managersList.Count; i++)
126 | {
127 | if (DateTime.Now.Millisecond > until)
128 | break;
129 | managersList[i].OnPoll(until, false);
130 | }
131 | }
132 | }
133 |
134 | private RawList GetManagersList()
135 | {
136 | managerLock.ReadBegin();
137 | // Underlying arrays are not cleaned nor reaused during resize, nor coroutines implement auto-cleaning, so this is safe.
138 | RawList managers = managersList;
139 | managerLock.ReadEnd();
140 | return managers;
141 | }
142 | }
143 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/CoroutineManager.On.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a9e61312a8692f8469bf274ef84b9300
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/CoroutineManager.Starts.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8af4ea446359a964d890b9a4a24719ec
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/CoroutineManager.TypedManager.INextCallback.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 188503e386c0db2408fb1e8c06bb94ed
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/CoroutineManager.TypedManager.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 22b922126481d2a4d9ff9fc7a6410ddb
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/CoroutineManager.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9c1be6cf5da44f94b87b704840a966b6
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/GlobalCoroutinesManagerUnit.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using UnityEngine;
4 |
5 | namespace Enderlook.Unity.Coroutines
6 | {
7 | ///
8 | /// Represent the global settings of the .
9 | ///
10 | [CreateAssetMenu(fileName = "Global Coroutines Manager Configuration", menuName = "Enderlook/Coroutines/Global Coroutines Manager Unit")]
11 | internal sealed class GlobalCoroutinesManagerUnit : ScriptableObject
12 | {
13 | // Keep names in sync with GlobalCoroutinesManagerUnitEditor and UnityCoroutinesPoolInfo
14 |
15 | [SerializeField, Min(0), Tooltip("Amount of miliseconds spent in executing poll coroutines.")]
16 | private int milisecondsExecutedPerFrameOnPoll = CoroutineManager.MILISECONDS_EXECUTED_PER_FRAME_ON_POLL_DEFAULT_VALUE;
17 |
18 | [SerializeField, Range(0, 1), Tooltip("Percentage of total executions that must be executed on poll coroutines regardless of timeout.")]
19 | private float minimumPercentOfExecutionsPerFrameOnPoll = CoroutineManager.MINIMUM_PERCENT_OF_EXECUTIONS_PER_FRAME_ON_POLL_DEFAULT_VALUE;
20 |
21 | public static void Load()
22 | {
23 | GlobalCoroutinesManagerUnit[] managers = Resources.LoadAll("");
24 | if (managers.Length > 1)
25 | throw new InvalidOperationException($"Multiple instances of {nameof(GlobalCoroutinesManagerUnit)} were found in the Resources folder.");
26 | else if (managers.Length == 1)
27 | {
28 | GlobalCoroutinesManagerUnit manager = managers[0];
29 | CoroutineManager.Shared.MilisecondsExecutedPerFrameOnPoll = manager.milisecondsExecutedPerFrameOnPoll;
30 | CoroutineManager.Shared.MinimumPercentOfExecutionsPerFrameOnPoll = manager.minimumPercentOfExecutionsPerFrameOnPoll;
31 | }
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/GlobalCoroutinesManagerUnit.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 05ab0e930b8b44644bc58d04711ae9f1
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/ThreadMode.cs:
--------------------------------------------------------------------------------
1 | namespace Enderlook.Unity.Coroutines
2 | {
3 | internal enum ThreadMode : byte
4 | {
5 | Unknown = 0,
6 | Short = 1,
7 | Long = 2,
8 | }
9 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/CoroutineScheduler/ThreadMode.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 49a05f637d9f9ea469c87da244fdb297
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutine.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 833401032f7c5274bb9ee4f7464e5abf
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutine/IValueCoroutineEnumerator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Enderlook.Unity.Coroutines
4 | {
5 | ///
6 | /// Represent a value coroutine enumerator.
7 | ///
8 | internal interface IValueCoroutineEnumerator : IDisposable
9 | {
10 | ///
11 | /// Determines the state of the coroutine.
12 | /// This will only be executed from Unity Thread.
13 | ///
14 | ValueCoroutineState State { get; }
15 |
16 | #if !UNITY_WEBGL
17 | ///
18 | /// Determines the state of the coroutine.
19 | ///
20 | ValueCoroutineState ConcurrentState { get; }
21 | #endif
22 |
23 | ///
24 | /// Advances the coroutine by one.
25 | /// This will only be executed from Unity Thread.
26 | ///
27 | /// Instruction of how coroutione should continue its execution.
28 | /// While is this must return .
29 | /// If is this must return .
30 | ValueYieldInstruction Next();
31 |
32 | #if !UNITY_WEBGL
33 | ///
34 | /// Advances the coroutine by one.
35 | ///
36 | /// Type of thread where this function is being executed.
37 | /// Instruction of how coroutione should continue its execution.
38 | /// While is this must return .
39 | /// If is this must return .
40 | ValueYieldInstruction ConcurrentNext(ThreadMode mode);
41 | #endif
42 | }
43 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutine/IValueCoroutineEnumerator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 58fe9c4f26d51134887c34b4a6f93dc7
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutine/UnityCoroutineEnumerator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Runtime.CompilerServices;
5 | using System.Threading.Tasks;
6 |
7 | using Unity.Jobs;
8 |
9 | using UnityEngine;
10 |
11 | namespace Enderlook.Unity.Coroutines
12 | {
13 | internal struct UnityCoroutineEnumerator : IValueCoroutineEnumerator
14 | {
15 | private IEnumerator enumerator;
16 |
17 | public ValueCoroutineState State { get; private set; }
18 |
19 | #if !UNITY_WEBGL
20 | public ValueCoroutineState ConcurrentState => State;
21 | #endif
22 |
23 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
24 | public UnityCoroutineEnumerator(IEnumerator enumerator)
25 | {
26 | this.enumerator = enumerator;
27 | State = ValueCoroutineState.Continue;
28 | }
29 |
30 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
31 | public void Dispose()
32 | {
33 | // Not required but may be useful.
34 | if (enumerator is IDisposable disposable)
35 | disposable.Dispose();
36 | }
37 |
38 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
39 | public ValueYieldInstruction Next()
40 | {
41 | if (enumerator.MoveNext())
42 | {
43 | switch (enumerator.Current)
44 | {
45 | case ValueYieldInstruction instruction:
46 | instruction.DebugAssertIsAllowedInEnumerators();
47 | return instruction;
48 | case null:
49 | return Yield.ToUpdate;
50 | case WaitForUpdate v:
51 | return v;
52 | case WaitForFixedUpdate v:
53 | return v;
54 | case WaitForSeconds v:
55 | return v;
56 | case WaitForSecondsRealtime v:
57 | return v;
58 | case WaitForSecondsRealtimePooled v:
59 | return v;
60 | case WaitForEndOfFrame v:
61 | return v;
62 | case CustomYieldInstruction v:
63 | return v;
64 | case ValueTask v:
65 | return v;
66 | case Task v:
67 | return v;
68 | case JobHandle v:
69 | return v;
70 | case ValueCoroutine v:
71 | return v;
72 | case Coroutine v:
73 | return v;
74 | case YieldInstruction v:
75 | return v;
76 | case IEnumerator v:
77 | return Yield.From(v);
78 | case IEnumerator v:
79 | return Yield.From(v);
80 | case IValueCoroutineEnumerator v:
81 | return Yield.From(v);
82 | default:
83 | #if DEBUG
84 | Debug.LogError($"Unexpected yielded type for value coroutine that implements {nameof(IEnumerator)}. This will result in undefined behaviour. This message will not shown on release.");
85 | #endif
86 | return Yield.ToUpdate;
87 | }
88 | }
89 | else
90 | {
91 | State = ValueCoroutineState.Finalized;
92 | return Yield.Finalized;
93 | }
94 | }
95 |
96 | #if !UNITY_WEBGL
97 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
98 | public ValueYieldInstruction ConcurrentNext(ThreadMode mode) => Next();
99 | #endif
100 | }
101 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutine/UnityCoroutineEnumerator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d62e3c46641f8e64eb1ea5b8adc8280e
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutine/ValueCoroutineEnumerator.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Runtime.CompilerServices;
3 |
4 | namespace Enderlook.Unity.Coroutines
5 | {
6 | internal struct ValueCoroutineEnumerator : IValueCoroutineEnumerator
7 | where T : IEnumerator
8 | {
9 | private T enumerator;
10 |
11 | public ValueCoroutineState State { get; private set; }
12 |
13 | #if !UNITY_WEBGL
14 | public ValueCoroutineState ConcurrentState => State;
15 | #endif
16 |
17 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
18 | public ValueCoroutineEnumerator(T enumerator)
19 | {
20 | this.enumerator = enumerator;
21 | State = ValueCoroutineState.Continue;
22 | }
23 |
24 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
25 | public void Dispose() => enumerator.Dispose();
26 |
27 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
28 | public ValueYieldInstruction Next()
29 | {
30 | if (enumerator.MoveNext())
31 | {
32 | ValueYieldInstruction instruction = enumerator.Current;
33 | instruction.DebugAssertIsAllowedInEnumerators();
34 | return instruction;
35 | }
36 | State = ValueCoroutineState.Finalized;
37 | return Yield.Finalized;
38 | }
39 |
40 | #if !UNITY_WEBGL
41 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
42 | public ValueYieldInstruction ConcurrentNext(ThreadMode mode) => Next();
43 | #endif
44 | }
45 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutine/ValueCoroutineEnumerator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ee97101c0c035354f9a7c8c55b4b0235
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutine/ValueCoroutineEnumeratorWithState.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Runtime.CompilerServices;
3 |
4 | namespace Enderlook.Unity.Coroutines
5 | {
6 | internal struct ValueCoroutineEnumeratorWithState : IValueCoroutineEnumerator
7 | where T : IEnumerator
8 | where U : IValueCoroutineState
9 | {
10 | private T enumerator;
11 | private U token;
12 | private ValueCoroutineState state;
13 |
14 | public ValueCoroutineState State {
15 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
16 | get => ValueCoroutineStateHelper.Merge(token.State, state);
17 | }
18 |
19 | #if !UNITY_WEBGL
20 | public ValueCoroutineState ConcurrentState {
21 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
22 | get => ValueCoroutineStateHelper.Merge(token.ConcurrentState, state);
23 | }
24 | #endif
25 |
26 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
27 | public ValueCoroutineEnumeratorWithState(T enumerator, U token)
28 | {
29 | this.enumerator = enumerator;
30 | this.token = token;
31 | state = ValueCoroutineState.Continue;
32 | }
33 |
34 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
35 | public void Dispose() => enumerator.Dispose();
36 |
37 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
38 | public ValueYieldInstruction Next()
39 | {
40 | switch (token.State)
41 | {
42 | case ValueCoroutineState.Finalized:
43 | return Yield.Finalized;
44 | case ValueCoroutineState.Suspended:
45 | return Yield.Suspended;
46 | }
47 |
48 | if (enumerator.MoveNext())
49 | {
50 | ValueYieldInstruction instruction = enumerator.Current;
51 | instruction.DebugAssertIsAllowedInEnumerators();
52 | return instruction;
53 | }
54 |
55 | state = ValueCoroutineState.Finalized;
56 | return Yield.Finalized;
57 | }
58 |
59 | #if !UNITY_WEBGL
60 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
61 | public ValueYieldInstruction ConcurrentNext(ThreadMode mode)
62 | {
63 | switch (token.ConcurrentState)
64 | {
65 | case ValueCoroutineState.Finalized:
66 | return Yield.Finalized;
67 | case ValueCoroutineState.Suspended:
68 | return Yield.Suspended;
69 | }
70 |
71 | if (enumerator.MoveNext())
72 | {
73 | ValueYieldInstruction instruction = enumerator.Current;
74 | instruction.DebugAssertIsAllowedInEnumerators();
75 | return instruction;
76 | }
77 |
78 | this.state = ValueCoroutineState.Finalized;
79 | return Yield.Finalized;
80 | }
81 | #endif
82 | }
83 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutine/ValueCoroutineEnumeratorWithState.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2f89596d7e4e549478dd7b7ec8ea99b2
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4da9009d5511f4b4e8e8585a3c9b9c60
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/CancellationTokenFinalizer.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 | using System.Threading;
3 |
4 | namespace Enderlook.Unity.Coroutines
5 | {
6 | internal struct CancellationTokenFinalizer : IValueCoroutineState
7 | {
8 | private readonly CancellationToken token;
9 |
10 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
11 | public CancellationTokenFinalizer(CancellationToken token)
12 | => this.token = token;
13 |
14 | public ValueCoroutineState State {
15 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
16 | get => token.IsCancellationRequested ? ValueCoroutineState.Finalized : ValueCoroutineState.Continue;
17 | }
18 |
19 | public ValueCoroutineState ConcurrentState {
20 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
21 | get => State;
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/CancellationTokenFinalizer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8b80392660170a94590fa992e7704c95
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/GameObjectFinalizeWhenNullAndSuspendWhenIsNotActive.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Unity.Threading;
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | using UnityEngine;
7 |
8 | namespace Enderlook.Unity.Coroutines
9 | {
10 | internal struct GameObjectFinalizeWhenNullAndSuspendWhenIsNotActive : IValueCoroutineState
11 | {
12 | private static readonly Func callback = e => e.activeInHierarchy;
13 |
14 | private readonly GameObject gameObject;
15 |
16 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
17 | public GameObjectFinalizeWhenNullAndSuspendWhenIsNotActive(GameObject gameObject)
18 | => this.gameObject = gameObject;
19 |
20 | public ValueCoroutineState State {
21 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
22 | get {
23 | if (gameObject == null)
24 | return ValueCoroutineState.Finalized;
25 | if (!gameObject.activeInHierarchy)
26 | return ValueCoroutineState.Suspended;
27 | return ValueCoroutineState.Continue;
28 | }
29 | }
30 |
31 | public ValueCoroutineState ConcurrentState {
32 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
33 | get {
34 | if (gameObject == null)
35 | return ValueCoroutineState.Finalized;
36 | if (!UnityThread.RunNow(callback, gameObject))
37 | return ValueCoroutineState.Suspended;
38 | return ValueCoroutineState.Continue;
39 | }
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/GameObjectFinalizeWhenNullAndSuspendWhenIsNotActive.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 858e4f2db2c44cd41a867b7440719eaa
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/IValueCoroutineState.cs:
--------------------------------------------------------------------------------
1 | namespace Enderlook.Unity.Coroutines
2 | {
3 | ///
4 | /// Determines the state of a coroutine.
5 | ///
6 | internal interface IValueCoroutineState
7 | {
8 | ///
9 | /// State of the coroutine.
10 | /// This method must be executed from the Unity thread.
11 | ///
12 | ValueCoroutineState State { get; }
13 |
14 | ///
15 | /// State of the coroutine.
16 | ///
17 | ValueCoroutineState ConcurrentState { get; }
18 | }
19 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/IValueCoroutineState.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b895695859869c74da5d5902cddaa747
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/MonoBehaviourFinalizeWhenNullAndSuspendWhenGameObjectIsDisabled.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Unity.Threading;
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | using UnityEngine;
7 |
8 | namespace Enderlook.Unity.Coroutines
9 | {
10 | internal struct MonoBehaviourFinalizeWhenNullAndSuspendWhenGameObjectIsDisabled : IValueCoroutineState
11 | {
12 | private static readonly Func callback = e => e.gameObject.activeInHierarchy;
13 |
14 | private readonly MonoBehaviour monoBehaviour;
15 |
16 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
17 | public MonoBehaviourFinalizeWhenNullAndSuspendWhenGameObjectIsDisabled(MonoBehaviour monoBehaviour)
18 | => this.monoBehaviour = monoBehaviour;
19 |
20 | public ValueCoroutineState State {
21 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
22 | get {
23 | if (monoBehaviour == null)
24 | return ValueCoroutineState.Finalized;
25 | if (!monoBehaviour.gameObject.activeInHierarchy)
26 | return ValueCoroutineState.Suspended;
27 | return ValueCoroutineState.Continue;
28 | }
29 | }
30 | public ValueCoroutineState ConcurrentState {
31 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
32 | get {
33 | if (monoBehaviour == null)
34 | return ValueCoroutineState.Finalized;
35 | if (!UnityThread.RunNow(callback, monoBehaviour))
36 | return ValueCoroutineState.Suspended;
37 | return ValueCoroutineState.Continue;
38 | }
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/MonoBehaviourFinalizeWhenNullAndSuspendWhenGameObjectIsDisabled.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9ca5685748e4e8e49995c4f99f9c42a7
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/MonoBehaviourFinalizeWhenNullAndSuspendWhenIsNotActiveNorEnabled.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Unity.Threading;
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | using UnityEngine;
7 |
8 | namespace Enderlook.Unity.Coroutines
9 | {
10 | internal struct MonoBehaviourFinalizeWhenNullAndSuspendWhenIsNotActiveNorEnabled : IValueCoroutineState
11 | {
12 | private static readonly Func callback = e => e.isActiveAndEnabled;
13 |
14 | private readonly MonoBehaviour monoBehaviour;
15 |
16 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
17 | public MonoBehaviourFinalizeWhenNullAndSuspendWhenIsNotActiveNorEnabled(MonoBehaviour monoBehaviour)
18 | => this.monoBehaviour = monoBehaviour;
19 |
20 | public ValueCoroutineState State {
21 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
22 | get {
23 | if (monoBehaviour == null)
24 | return ValueCoroutineState.Finalized;
25 | if (!monoBehaviour.isActiveAndEnabled)
26 | return ValueCoroutineState.Suspended;
27 | return ValueCoroutineState.Continue;
28 | }
29 | }
30 |
31 | public ValueCoroutineState ConcurrentState {
32 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
33 | get {
34 | if (monoBehaviour == null)
35 | return ValueCoroutineState.Finalized;
36 | if (!UnityThread.RunNow(callback, monoBehaviour))
37 | return ValueCoroutineState.Suspended;
38 | return ValueCoroutineState.Continue;
39 | }
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/MonoBehaviourFinalizeWhenNullAndSuspendWhenIsNotActiveNorEnabled.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0780a24b0adc9cf47a97c978f7cd74df
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/UnityObjectFinalizeWhenNull.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | using UnityEngine;
4 |
5 | namespace Enderlook.Unity.Coroutines
6 | {
7 | internal struct UnityObjectFinalizeWhenNull : IValueCoroutineState
8 | {
9 | private readonly Object @object;
10 |
11 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
12 | public UnityObjectFinalizeWhenNull(Object @object)
13 | => this.@object = @object;
14 |
15 | public ValueCoroutineState State {
16 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
17 | get => @object == null ? ValueCoroutineState.Finalized : ValueCoroutineState.Continue;
18 | }
19 | public ValueCoroutineState ConcurrentState {
20 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
21 | get => State;
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/UnityObjectFinalizeWhenNull.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 83438f82ed117a04681a90b9648dfb38
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/ValueCoroutineState.cs:
--------------------------------------------------------------------------------
1 | namespace Enderlook.Unity.Coroutines
2 | {
3 | ///
4 | /// Determines the state of the coroutine.
5 | ///
6 | internal enum ValueCoroutineState : byte
7 | {
8 | ///
9 | /// The coroutine can continue.
10 | ///
11 | Continue = 0,
12 |
13 | ///
14 | /// The coroutine has been finalized or cancelled.
15 | ///
16 | Finalized = 1,
17 |
18 | ///
19 | /// The coroutine has is suspended.
20 | ///
21 | Suspended = 2,
22 | }
23 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/ValueCoroutineState.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c52903a5b33a83448be08043164bc685
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/ValueCoroutineStateBoxed.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | namespace Enderlook.Unity.Coroutines
4 | {
5 | internal class ValueCoroutineStateBoxed : IValueCoroutineState
6 | {
7 | public ValueCoroutineState State { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; set; }
8 |
9 | public ValueCoroutineState ConcurrentState {
10 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
11 | get => State;
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/ValueCoroutineStateBoxed.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2f20080f0c69e0847af53c356903d9f6
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/ValueCoroutineStateHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | using UnityEngine;
4 |
5 | namespace Enderlook.Unity.Coroutines
6 | {
7 | internal static class ValueCoroutineStateHelper
8 | {
9 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
10 | public static ValueCoroutineState Merge(ValueCoroutineState a, ValueCoroutineState b)
11 | {
12 | switch (a | b)
13 | {
14 | case ValueCoroutineState.Finalized | ValueCoroutineState.Continue:
15 | case ValueCoroutineState.Finalized | ValueCoroutineState.Suspended:
16 | //case ValueCoroutineState.Finalized | ValueCoroutineState.Finalized:
17 | return ValueCoroutineState.Finalized;
18 | case ValueCoroutineState.Suspended | ValueCoroutineState.Continue:
19 | //case ValueCoroutineState.Suspended | ValueCoroutineState.Suspended:
20 | return ValueCoroutineState.Suspended;
21 | case ValueCoroutineState.Continue | ValueCoroutineState.Continue:
22 | return ValueCoroutineState.Continue;
23 | }
24 | Debug.Assert(false, "Impossible state.");
25 | return default;
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/IValueCoroutineState/ValueCoroutineStateHelper.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cc387809ee5d0eb4eb375f89d7092db1
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/ValueCoroutine.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d73516ec418a3e04cae1b5808fbc7a02
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/ValueCoroutine/ValueCoroutine.Enumerator.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | namespace Enderlook.Unity.Coroutines
4 | {
5 | public readonly partial struct ValueCoroutine
6 | {
7 | private struct Coroutine : IValueCoroutineEnumerator
8 | where T : IValueCoroutineEnumerator
9 | {
10 | private readonly Handle handler;
11 | private T coroutine;
12 |
13 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
14 | public Coroutine(Handle handler, T coroutine)
15 | {
16 | this.handler = handler;
17 | this.coroutine = coroutine;
18 | }
19 |
20 | public ValueCoroutineState State {
21 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
22 | get => coroutine.State;
23 | }
24 |
25 | #if !UNITY_WEBGL
26 | public ValueCoroutineState ConcurrentState {
27 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
28 | get => coroutine.ConcurrentState;
29 | }
30 | #endif
31 |
32 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
33 | public void Dispose() => coroutine.Dispose();
34 |
35 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
36 | public ValueYieldInstruction Next()
37 | {
38 | ValueYieldInstruction instruction = coroutine.Next();
39 | if (instruction.Mode == ValueYieldInstruction.Type.Finalized)
40 | handler.Complete();
41 | return instruction;
42 | }
43 |
44 | #if !UNITY_WEBGL
45 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
46 | public ValueYieldInstruction ConcurrentNext(ThreadMode mode)
47 | {
48 | ValueYieldInstruction instruction = coroutine.ConcurrentNext(mode);
49 | if (instruction.Mode == ValueYieldInstruction.Type.Finalized)
50 | handler.Complete();
51 | return instruction;
52 | }
53 | #endif
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/ValueCoroutine/ValueCoroutine.Enumerator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 97cac4dc4458c7740b531b704e7c941e
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/ValueCoroutine/ValueCoroutine.Handle.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Pools;
2 | using Enderlook.Unity.Threading;
3 |
4 | using System;
5 | using System.Threading;
6 |
7 | using UnityEngine;
8 |
9 | namespace Enderlook.Unity.Coroutines
10 | {
11 | public readonly partial struct ValueCoroutine
12 | {
13 | internal class Handle
14 | {
15 | private Action continuation;
16 | private int isAdding;
17 | private bool isCompleted;
18 |
19 | public uint Generation { get; private set; }
20 |
21 | public void Complete()
22 | {
23 | #if UNITY_EDITOR
24 | Debug.Assert(!isCompleted);
25 | #endif
26 | isCompleted = true;
27 |
28 | while (isAdding == 1) ;
29 |
30 | Action action = continuation;
31 | if (!(action is null))
32 | {
33 | // Complete can be called outside main thread, so we must to ensure we are in the appropiate thread.
34 | if (UnityThread.IsMainThread)
35 | action();
36 | else
37 | UnityThread.RunLater(action);
38 | }
39 |
40 | Generation++;
41 | ObjectPool.Shared.Return(this);
42 | }
43 |
44 | public bool IsCompleted(uint generation)
45 | {
46 | bool isCompleted = this.isCompleted;
47 | if (Generation != generation)
48 | return true;
49 | return isCompleted;
50 | }
51 |
52 | public void OnCompleted(Action continuation, uint generation)
53 | {
54 | if (Generation != generation)
55 | {
56 | Run();
57 | return;
58 | }
59 |
60 | while (Interlocked.Exchange(ref isAdding, 1) == 0) ;
61 |
62 | if (Generation != generation)
63 | {
64 | Run();
65 | return;
66 | }
67 |
68 | if (isCompleted)
69 | {
70 | isAdding = 0;
71 | Run();
72 | return;
73 | }
74 |
75 | try
76 | {
77 | this.continuation += continuation;
78 | }
79 | finally
80 | {
81 | isAdding = 0;
82 | }
83 |
84 | void Run()
85 | {
86 | // Complete can be called outside main thread, so we must to ensure we are in the appropiate thread.
87 | if (UnityThread.IsMainThread)
88 | continuation();
89 | else
90 | UnityThread.RunLater(continuation);
91 | }
92 | }
93 | }
94 | }
95 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/ValueCoroutine/ValueCoroutine.Handle.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3374e238a9e0ab44f809b54f77a5eafd
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/ValueCoroutine/ValueCoroutine.Starts.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Runtime.CompilerServices;
3 | using System.Threading;
4 |
5 | using UnityEngine;
6 |
7 | namespace Enderlook.Unity.Coroutines
8 | {
9 | public partial struct ValueCoroutine
10 | {
11 | ///
12 | /// Amount of miliseconds spent in executing global poll coroutines per frame.
13 | ///
14 | public static int MilisecondsExecutedPerFrameOnPoll {
15 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
16 | get => CoroutineManager.Shared.MilisecondsExecutedPerFrameOnPoll;
17 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
18 | set => CoroutineManager.Shared.MilisecondsExecutedPerFrameOnPoll = value;
19 | }
20 |
21 | ///
22 | /// Percentage of total execution that must be executed on per frame regardless of for global poll coroutines.
23 | ///
24 | public static float MinimumPercentOfExecutionsPerFrameOnPoll {
25 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
26 | get => CoroutineManager.Shared.MinimumPercentOfExecutionsPerFrameOnPoll;
27 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
28 | set => CoroutineManager.Shared.MinimumPercentOfExecutionsPerFrameOnPoll = value;
29 | }
30 |
31 | ///
32 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
33 | public static void Start(T routine)
34 | where T : IEnumerator
35 | => CoroutineManager.Shared.Start(routine);
36 |
37 | ///
38 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
39 | public static ValueCoroutine StartWithHandle(T routine)
40 | where T : IEnumerator
41 | => CoroutineManager.Shared.StartWithHandle(routine);
42 |
43 | ///
44 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
45 | public static void Start(T routine, CancellationToken token)
46 | where T : IEnumerator
47 | => CoroutineManager.Shared.Start(routine, token);
48 |
49 | ///
50 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
51 | public static ValueCoroutine StartWithHandle(T routine, CancellationToken token)
52 | where T : IEnumerator
53 | => CoroutineManager.Shared.StartWithHandle(routine, token);
54 |
55 | ///
56 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
57 | public static void Start(T routine, Object source)
58 | where T : IEnumerator
59 | => CoroutineManager.Shared.Start(routine, source);
60 |
61 | ///
62 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
63 | public static ValueCoroutine StartWithHandle(T routine, Object source)
64 | where T : IEnumerator
65 | => CoroutineManager.Shared.StartWithHandle(routine, source);
66 |
67 | ///
68 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
69 | public static void Start(T routine, GameObject source)
70 | where T : IEnumerator
71 | => CoroutineManager.Shared.Start(routine, source);
72 |
73 | ///
74 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
75 | public static ValueCoroutine StartWithHandle(T routine, GameObject source)
76 | where T : IEnumerator
77 | => CoroutineManager.Shared.StartWithHandle(routine, source);
78 |
79 | ///
80 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
81 | public static void Start(T routine, MonoBehaviour source, bool suspendWhenSourceIsDisabled = false)
82 | where T : IEnumerator
83 | => CoroutineManager.Shared.Start(routine, source, suspendWhenSourceIsDisabled);
84 |
85 | ///
86 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
87 | public static ValueCoroutine StartWithHandle(T routine, MonoBehaviour source, bool suspendWhenSourceIsDisabled = false)
88 | where T : IEnumerator
89 | => CoroutineManager.Shared.StartWithHandle(routine, source, suspendWhenSourceIsDisabled);
90 | }
91 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/ValueCoroutine/ValueCoroutine.Starts.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5e25f5d8103c23c4ba67663ed81e8280
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/ValueCoroutine/ValueCoroutine.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Pools;
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace Enderlook.Unity.Coroutines
7 | {
8 | ///
9 | /// Represent the handler of a value coroutine.
10 | ///
11 | public readonly partial struct ValueCoroutine : INotifyCompletion
12 | {
13 | internal readonly Handle handle;
14 | // Since the handle is pooled, we use generation to check if it's already used.
15 | internal readonly uint generation;
16 |
17 | private ValueCoroutine(Handle handle)
18 | {
19 | this.handle = handle;
20 | generation = handle.Generation;
21 | }
22 |
23 | internal ValueCoroutine(Handle handle, uint generation)
24 | {
25 | this.handle = handle;
26 | this.generation = generation;
27 | }
28 |
29 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
30 | internal static ValueCoroutine StartEnumerator(CoroutineManager manager, T routine)
31 | where T : IValueCoroutineEnumerator
32 | {
33 | Handle handler = ObjectPool.Shared.Rent();
34 | manager.StartEnumerator(new Coroutine(handler, routine));
35 | return new ValueCoroutine(handler);
36 | }
37 |
38 | ///
39 | /// Whenever the value coroutine has completed or not.
40 | ///
41 | public bool IsCompleted => handle.IsCompleted(generation);
42 |
43 | ///
44 | /// Return self.
45 | ///
46 | /// Self.
47 | public ValueCoroutine GetAwaiter() => this;
48 |
49 | ///
50 | /// Determines the action to run after the coroutine has completed or was stopped.
51 | ///
52 | /// Action to run.
53 | public void OnCompleted(Action continuation) => handle.OnCompleted(continuation, generation);
54 | }
55 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/ValueCoroutine/ValueCoroutine.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 11521ba9a95a6e649a8ed5ab371d1494
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/ValueYieldInstruction.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0854f971e365bf64ab5b1acd96281a47
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/Runtime/Value Coroutines/Yield.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a640448a463e73740bb2b54424c32591
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.enderlook.unity.coroutines",
3 | "version": "0.3.5",
4 | "displayName": "Enderlook Unity Coroutines",
5 | "description": "Provides utility methods for working with Unity coroutines.",
6 | "unity": "2019.2",
7 | "keywords": [
8 | "utility",
9 | "threading",
10 | "coroutines"
11 | ],
12 | "dependencies": {
13 | "com.enderlook.threading": "https://github.com/Enderlook/Unity-Net-Packages?path=Packages/com.enderlook.threading#com.enderlook.threading/v0.2.0",
14 | "com.enderlook.unity.threading": "https://github.com/Enderlook/Unity-Threading.git?/path=Packages/com.enderlook.unity.threading#com.enderlook.unity.threading/v0.7.7",
15 | "com.enderlook.unity.toolset.utils": "https://github.com/Enderlook/Unity-Toolset.git?path=Packages/com.enderlook.unity.toolset.utils#com.enderlook.unity.toolset.utils/v0.",
16 | "com.system.threading.tasks.extensions": "https://github.com/Enderlook/Unity-Net-Packages?path=Packages/com.system.threading.tasks.extensions#com.system.threading.tasks.extensions/v4.5.4"
17 | },
18 | "author": {
19 | "name": "Enderlook",
20 | "url": "https://github.com/Enderlook"
21 | }
22 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/package.json.bak:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.enderlook.unity.coroutines",
3 | "version": "0.3.4",
4 | "displayName": "Enderlook Unity Coroutines",
5 | "description": "Provides utility methods for working with Unity coroutines.",
6 | "unity": "2019.2",
7 | "keywords": [
8 | "utility",
9 | "threading",
10 | "coroutines"
11 | ],
12 | "dependencies": {
13 | "com.enderlook.threading": "https://github.com/Enderlook/Unity-Net-Packages?path=Packages/com.enderlook.threading#com.enderlook.threading/v0.2.0",
14 | "com.enderlook.unity.threading": "https://github.com/Enderlook/Unity-Threading.git?/path=Packages/com.enderlook.unity.threading#com.enderlook.unity.threading/v0.7.4",
15 | "com.enderlook.unity.toolset.utils": "https://github.com/Enderlook/Unity-Toolset.git?path=Packages/com.enderlook.unity.toolset.utils#com.enderlook.unity.toolset.utils/v0.3.1",
16 | "com.system.threading.tasks.extensions": "https://github.com/Enderlook/Unity-Net-Packages?path=Packages/com.system.threading.tasks.extensions#com.system.threading.tasks.extensions/v4.5.4"
17 | },
18 | "author": {
19 | "name": "Enderlook",
20 | "url": "https://github.com/Enderlook"
21 | }
22 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/package.json.bak.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2374ecf881f3e494cb74c60313515a4c
3 | DefaultImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.coroutines/package.json.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9e4883f479732b246984cd5bc82d0452
3 | PackageManifestImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c5ce67f00811d18458859cc7569ab7ca
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Editor/Enderlook.Unity.Jobs-Editor.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Enderlook.Unity.Jobs-Editor",
3 | "references": [
4 | "GUID:0213f6f83d9102e47a7722b566934def",
5 | "GUID:70bb7604d926506479be15f5272e3957"
6 | ],
7 | "includePlatforms": [
8 | "Editor"
9 | ],
10 | "excludePlatforms": [],
11 | "allowUnsafeCode": false,
12 | "overrideReferences": false,
13 | "precompiledReferences": [],
14 | "autoReferenced": true,
15 | "defineConstraints": [],
16 | "versionDefines": []
17 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Editor/Enderlook.Unity.Jobs-Editor.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5fc6a37ea738cae4babcf2ea61d5d3c2
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Editor/JobsInfo.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Unity.Toolset.Utils;
2 |
3 | using UnityEditor;
4 |
5 | using UnityEngine;
6 |
7 | namespace Enderlook.Unity.Jobs
8 | {
9 | internal sealed class JobsInfo : EditorWindow
10 | {
11 | private static readonly GUIContent TITLE_CONTENT = new GUIContent("Jobs Information", "Show jobs information.");
12 |
13 | private static readonly GUIContent JOB_MANAGER_HEADER_CONTENT = new GUIContent("Threading.JobManager Workload", "Show amount of work related to Unity jobs must be done.");
14 | private static readonly GUIContent JOB_MANAGER_HEADER_CONTENT_METHOD_TITLE = new GUIContent("Method", "Name of the method which the related workload.");
15 | private static readonly GUIContent JOB_MANAGER_HEADER_CONTENT_COUNT_TITLE = new GUIContent("Waiting", "Amount of workload related to that method that is being watched to complete.");
16 |
17 | private GUILayoutOption[] jobManagerLayoutOptionsMethod;
18 | private GUILayoutOption[] jobManagerLayoutOptionsCount;
19 | private GUILayoutOption[] jobManagerLayoutOptionScroll;
20 |
21 | private (int, string) jobHandleWatchCompletition = (0, "0");
22 | private (int, string) jobHandleOnComplete = (0, "0");
23 | private Vector2 jobHandleScrollPosition;
24 |
25 | [MenuItem("Enderlook/Jobs Information")]
26 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Code Quality", "IDE0051:Remove unused private members", Justification = "Used by Unity.")]
27 | private static void ShowWindow()
28 | {
29 | JobsInfo window = CreateWindow();
30 |
31 | Rect position = window.position;
32 | position.width = (EditorGUIUtility.fieldWidth + EditorGUIUtility.labelWidth) * 2;
33 | position.height = EditorGUIUtility.singleLineHeight * 6f;
34 | window.position = position;
35 | }
36 |
37 | public void OnGUI()
38 | {
39 | titleContent = TITLE_CONTENT;
40 |
41 | CreateLayoutOptions();
42 | DrawJobManager();
43 | }
44 |
45 | private void CreateLayoutOptions()
46 | {
47 | if (jobManagerLayoutOptionsMethod is null)
48 | {
49 | const int min = 100;
50 | const int ratio = 5;
51 | jobManagerLayoutOptionsMethod = new GUILayoutOption[] { GUILayout.MinWidth(min - (min / ratio)), GUILayout.MaxWidth(position.width - (position.width / ratio)) };
52 | jobManagerLayoutOptionsCount = new GUILayoutOption[] { GUILayout.MinWidth(min / ratio), GUILayout.MaxWidth(position.width / ratio) };
53 | jobManagerLayoutOptionScroll = new GUILayoutOption[] { GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight * 2.5f) };
54 | }
55 | }
56 |
57 | private void DrawJobManager()
58 | {
59 | EditorGUIHelper.Header(JOB_MANAGER_HEADER_CONTENT);
60 |
61 | EditorGUILayout.BeginVertical(GUI.skin.box);
62 | {
63 | EditorGUILayout.BeginHorizontal();
64 | {
65 | EditorGUILayout.LabelField(JOB_MANAGER_HEADER_CONTENT_METHOD_TITLE, EditorStyles.boldLabel, jobManagerLayoutOptionsMethod);
66 | EditorGUILayout.LabelField(JOB_MANAGER_HEADER_CONTENT_COUNT_TITLE, EditorStyles.boldLabel, jobManagerLayoutOptionsCount);
67 | }
68 | EditorGUILayout.EndHorizontal();
69 |
70 | EditorGUIHelper.DrawHorizontalLine();
71 |
72 | jobHandleScrollPosition = EditorGUILayout.BeginScrollView(jobHandleScrollPosition, jobManagerLayoutOptionScroll);
73 | {
74 | EditorGUILayout.BeginHorizontal();
75 | {
76 | EditorGUILayout.LabelField("JobManager.WatchCompletition(JobHandle)", jobManagerLayoutOptionsMethod);
77 | if (jobHandleWatchCompletition.Item1 != JobManager.JobHandleCompleterCount)
78 | {
79 | jobHandleWatchCompletition.Item1 = JobManager.JobHandleCompleterCount;
80 | jobHandleWatchCompletition.Item2 = jobHandleWatchCompletition.Item1.ToString();
81 | }
82 | EditorGUILayout.LabelField(jobHandleWatchCompletition.Item2, jobManagerLayoutOptionsCount);
83 | }
84 | EditorGUILayout.EndHorizontal();
85 |
86 | EditorGUILayout.BeginHorizontal();
87 | {
88 | EditorGUILayout.LabelField("JobManager.OnComplete(JobHandle, Action, bool)", jobManagerLayoutOptionsMethod);
89 | if (jobHandleOnComplete.Item1 != JobManager.JobTasksManagerCount)
90 | {
91 | jobHandleOnComplete.Item1 = JobManager.JobTasksManagerCount;
92 | jobHandleOnComplete.Item2 = jobHandleOnComplete.Item1.ToString();
93 | }
94 | EditorGUILayout.LabelField(jobHandleOnComplete.Item2, jobManagerLayoutOptionsCount);
95 | }
96 | EditorGUILayout.EndHorizontal();
97 | }
98 | EditorGUILayout.EndScrollView();
99 | }
100 | EditorGUILayout.EndVertical();
101 | }
102 | }
103 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Editor/JobsInfo.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fb4eadc28e83dc44b9eafce54b628caa
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ac014afa6a1b9514ca8949f564119eb2
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Enderlook.Unity.Jobs.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Enderlook.Unity.Jobs",
3 | "references": [
4 | "GUID:12965892c664bf44cbd63f6568ef40da"
5 | ],
6 | "includePlatforms": [],
7 | "excludePlatforms": [],
8 | "allowUnsafeCode": false,
9 | "overrideReferences": false,
10 | "precompiledReferences": [],
11 | "autoReferenced": true,
12 | "defineConstraints": [],
13 | "versionDefines": []
14 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Enderlook.Unity.Jobs.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0213f6f83d9102e47a7722b566934def
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/GlobalDictionary`1.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Concurrent;
2 | using System.Collections.Generic;
3 | using System.Runtime.CompilerServices;
4 | using System.Threading;
5 |
6 | using UnityEngine;
7 |
8 | namespace Enderlook.Unity.Jobs
9 | {
10 | internal static class GlobalDictionary
11 | {
12 | private static readonly ConcurrentDictionary dictionary = new ConcurrentDictionary();
13 |
14 | private static long counter;
15 |
16 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
17 | public static long Store(T value)
18 | {
19 | long v = Interlocked.Increment(ref counter);
20 | if (!dictionary.TryAdd(v, value))
21 | Debug.LogError("Impossible state.");
22 | return v;
23 | }
24 |
25 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
26 | public static T Drain(long key)
27 | {
28 | if (!dictionary.TryRemove(key, out T value))
29 | ThrowRequestedMoreThanOnce();
30 | return value;
31 | }
32 |
33 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
34 | public static void Remove(long key)
35 | {
36 | if (dictionary.TryRemove(key, out T _))
37 | ThrowRequestedMoreThanOnce();
38 | }
39 |
40 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
41 | public static T Peek(long key)
42 | {
43 | if (!dictionary.TryGetValue(key, out T value))
44 | ThrowAlreadyDrain();
45 | return value;
46 |
47 | void ThrowAlreadyDrain() => throw new KeyNotFoundException("A key was already drained");
48 | }
49 |
50 | private static void ThrowRequestedMoreThanOnce() => throw new KeyNotFoundException("A key can't be requested more than once.");
51 | }
52 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/GlobalDictionary`1.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4c2b710f48f95b64ba7046886e0e659f
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/InternalsVisibleTo.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | [assembly: InternalsVisibleTo("Enderlook.Unity.Jobs-Editor")]
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/InternalsVisibleTo.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7b76d8ed618486944a0729bc1f06ed9f
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/JobHandleAwaiter.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 260a503956c5ca74694be954a29c38b1
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/JobHandleAwaiter/JobHandleAwaiter.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Unity.Threading;
2 |
3 | using System;
4 | using System.Collections;
5 | using System.Runtime.CompilerServices;
6 |
7 | using Unity.Jobs;
8 |
9 | using UnityEngine;
10 |
11 | namespace Enderlook.Unity.Jobs
12 | {
13 | ///
14 | /// An awaiter for
15 | ///
16 | public struct JobHandleAwaiter : INotifyCompletion
17 | {
18 | // https://gist.github.com/distantcam/64cf44d84441e5c45e197f7d90c6df3e
19 |
20 | private static readonly Func isCompleted = e => e.IsCompleted;
21 |
22 | internal readonly JobHandle jobHandle;
23 |
24 | ///
25 | /// Creates an awaiter for the given .
26 | ///
27 | /// Job handle to await for.
28 | public JobHandleAwaiter(JobHandle jobHandle)
29 | {
30 | jobHandle.WatchCompletion();
31 | this.jobHandle = jobHandle;
32 | }
33 |
34 | ///
35 | /// Return self.
36 | ///
37 | /// Self.
38 | public JobHandleAwaiter GetAwaiter() => this;
39 |
40 | ///
41 | /// Whenever the job handle has completed or not.
42 | ///
43 | public bool IsCompleted
44 | {
45 | get {
46 | if (UnityThread.IsMainThread)
47 | return jobHandle.IsCompleted;
48 | Debug.Log("This method requires to be executed in the Unity thread but wasn't.\n" +
49 | "As a fallback, it will forward the call to the Unity thread.\n" +
50 | "However, this may produce deadlocks very easily.");
51 | return UnityThread.RunNow(isCompleted, jobHandle);
52 | }
53 | }
54 |
55 | ///
56 | /// Determines the action to run after the job handle has completed.
57 | ///
58 | /// Action to run.
59 | public void OnCompleted(Action continuation) => jobHandle.OnComplete(continuation);
60 |
61 | ///
62 | /// Does nothing.
63 | ///
64 | public void GetResult()
65 | {
66 | // We could execute `jobHandle.Complete()` here in order to force finalization of the call.
67 | // However, that would require to block if this call is not in the Unity thread.
68 | // Also, we are already using JobManager.WatchCompletion(JobHandle) method so it's not necessary.
69 | // Just noting in case we may want in the future.
70 | }
71 |
72 | ///
73 | /// Convert a this awaiter into an enumerator.
74 | ///
75 | /// Enumerator which wraps the awaiter.
76 | public IEnumerator AsCoroutine()
77 | {
78 | while (!jobHandle.IsCompleted)
79 | yield return null;
80 |
81 | jobHandle.Complete();
82 | }
83 | }
84 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/JobHandleAwaiter/JobHandleAwaiter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6e2a0fa54bb959b4ea042087dc749932
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/JobHandleAwaiter/JobHandleAwaiterExtension.cs:
--------------------------------------------------------------------------------
1 | using Unity.Jobs;
2 |
3 | namespace Enderlook.Unity.Jobs
4 | {
5 | ///
6 | /// Allows to get an awaiter from .
7 | ///
8 | public static class JobHandleAwaiterExtension
9 | {
10 | ///
11 | /// Wrap a job handle as a task.
12 | ///
13 | /// Job handle to wrap.
14 | /// Task wrapper of the job handle.
15 | public static JobHandleAwaiter GetAwaiter(this JobHandle jobHandle) => new JobHandleAwaiter(jobHandle);
16 | }
17 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/JobHandleAwaiter/JobHandleAwaiterExtension.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 75b1a4872d2ad9e46af984da2bb70026
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/JobManager.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 185b9a8fb3077e141a11423d8769aa54
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/JobManager/JobManager.JobHandleCompleter.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Collections.LowLevel;
2 | using Enderlook.Unity.Threading;
3 |
4 | using Unity.Jobs;
5 |
6 | namespace Enderlook.Unity.Jobs
7 | {
8 | public static partial class JobManager
9 | {
10 | private static class JobHandleCompleter
11 | {
12 | private static RawList jobHandles = RawList.Create();
13 |
14 | #if UNITY_EDITOR
15 | ///
16 | /// Unity Editor Only.
17 | ///
18 | internal static int Count => jobHandles.Count;
19 | #endif
20 |
21 | public static void Add(JobHandle jobHandle)
22 | {
23 | if (UnityThread.IsMainThread && jobHandle.IsCompleted)
24 | jobHandle.Complete();
25 | else
26 | jobHandles.Add(jobHandle);
27 | }
28 |
29 | public static void Update()
30 | {
31 | int j = 0;
32 | for (int i = 0; i < jobHandles.Count; i++)
33 | {
34 | JobHandle jobHandle = jobHandles[i];
35 | if (jobHandle.IsCompleted)
36 | {
37 | jobHandle.Complete();
38 | continue;
39 | }
40 | jobHandles[j++] = jobHandle;
41 | }
42 | jobHandles = RawList.From(jobHandles.UnderlyingArray, j);
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/JobManager/JobManager.JobHandleCompleter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 540423948f9a42e4abb8d3ded8f30282
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/JobManager/JobManager.JobTask.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Unity.Jobs;
4 |
5 | namespace Enderlook.Unity.Jobs
6 | {
7 | public static partial class JobManager
8 | {
9 | private struct JobTask
10 | {
11 | public JobHandle JobHandle { get; set; }
12 |
13 | public Action OnJobComplete { get; set; }
14 |
15 | public bool IsCompleted => JobHandle.IsCompleted;
16 |
17 | public void Complete()
18 | {
19 | JobHandle.Complete();
20 | OnJobComplete();
21 | }
22 |
23 | public JobTask(JobHandle jobHandle, Action onJobComplete)
24 | {
25 | JobHandle = jobHandle;
26 | OnJobComplete = onJobComplete;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/JobManager/JobManager.JobTask.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b6e6a81dc10a5d1478da93469c0cc26d
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/JobManager/JobManager.JobTasksManager.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Collections.LowLevel;
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | using Unity.Jobs;
7 |
8 | namespace Enderlook.Unity.Jobs
9 | {
10 | public static partial class JobManager
11 | {
12 | private static class JobTasksManager
13 | {
14 | private static RawList jobTasks = RawList.Create();
15 |
16 | #if UNITY_EDITOR
17 | ///
18 | /// Unity Editor Only.
19 | ///
20 | internal static int Count => jobTasks.Count;
21 | #endif
22 |
23 | public static void Add(JobHandle jobHandle, Action onJobComplete, bool canCompleteImmediately = true)
24 | {
25 | if (onJobComplete is null)
26 | ThrowArgumentNullException();
27 |
28 | JobTask jobTask = new JobTask(jobHandle, onJobComplete);
29 |
30 | if (jobTask.IsCompleted && canCompleteImmediately)
31 | {
32 | jobTask.Complete();
33 | return;
34 | }
35 |
36 | jobTasks.Add(jobTask);
37 | }
38 |
39 | [MethodImpl(MethodImplOptions.NoInlining)]
40 | private static void ThrowArgumentNullException() => throw new ArgumentNullException("onJobComplete");
41 |
42 | public static void Update()
43 | {
44 | int j = 0;
45 | for (int i = 0; i < jobTasks.Count; i++)
46 | {
47 | JobTask jobTask = jobTasks[i];
48 | if (jobTask.IsCompleted)
49 | {
50 | jobTask.Complete();
51 | continue;
52 | }
53 | jobTasks[j++] = jobTask;
54 | }
55 | jobTasks = RawList.From(jobTasks.UnderlyingArray, j);
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/JobManager/JobManager.JobTasksManager.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b91130bea4ad6b64a8aaacfd7e782768
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/JobManager/JobManager.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Collections.LowLevel;
2 | using Enderlook.Unity.Threading;
3 |
4 | using System;
5 |
6 | using Unity.Jobs;
7 |
8 | using UnityEditor;
9 |
10 | namespace Enderlook.Unity.Jobs
11 | {
12 | public static partial class JobManager
13 | {
14 | internal static RawList updaters = RawList.Create();
15 |
16 | static JobManager() => Manager.OnUpdate += Update;
17 |
18 | internal static void Update()
19 | {
20 | JobHandleCompleter.Update();
21 | JobTasksManager.Update();
22 | foreach (Action action in updaters)
23 | action();
24 | }
25 |
26 | ///
27 | /// Enqueues an action to be execute when the job handle completes.
28 | /// Note that this action will not be executed immediately after .Complete(), but may execute on the current or next frame.
29 | ///
30 | /// Job handle to schedule action.
31 | /// Action to execute when job handle completes.
32 | /// If the job handle is already completed, this value determines if the action should run immediately or later (which may be in this or in the next frame).
33 | public static void OnComplete(this JobHandle jobHandle, Action onJobComplete, bool canCompleteImmediately = true)
34 | => JobTasksManager.Add(jobHandle, onJobComplete, canCompleteImmediately);
35 |
36 | ///
37 | /// Automatically watches the completion of this job handle.
38 | /// Useful for fire and forget.
39 | ///
40 | /// Job handle to watch completion.
41 | /// .
42 | public static JobHandle WatchCompletion(this JobHandle jobHandle)
43 | {
44 | JobHandleCompleter.Add(jobHandle);
45 | return jobHandle;
46 | }
47 |
48 | #if UNITY_EDITOR
49 | [InitializeOnLoadMethod]
50 | private static void Initialize() => EditorApplication.update += Update;
51 |
52 | ///
53 | /// Unity Editor Only.
54 | ///
55 | internal static int JobHandleCompleterCount => JobHandleCompleter.Count;
56 |
57 | ///
58 | /// Unity Editor Only.
59 | ///
60 | internal static int JobTasksManagerCount => JobTasksManager.Count;
61 | #endif
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/JobManager/JobManager.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ccdc2b70865e4b34dab6ab1dba7f7137
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 231be9634ec165f4eb1d843d2643cef9
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed/IManagedJob.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 88421a87f66f154448f4b25771aebfe1
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed/IManagedJob/IManagedJob.cs:
--------------------------------------------------------------------------------
1 | using Unity.Jobs;
2 |
3 | namespace Enderlook.Unity.Jobs
4 | {
5 | ///
6 | /// Represent an that contains managed data.
7 | ///
8 | public interface IManagedJob
9 | {
10 | ///
11 | /// Action to execute.
12 | ///
13 | void Execute();
14 | }
15 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed/IManagedJob/IManagedJob.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ad35c5bb5a544f74b9a2c93ab67af3b2
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed/IManagedJob/IManagedJobExtensions.Delegates.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b4410841272058d4290fd566f424e38a
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed/IManagedJob/IManagedJobExtensions.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Pools;
2 |
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | using Unity.Jobs;
7 |
8 | using UnityEngine;
9 |
10 | namespace Enderlook.Unity.Jobs
11 | {
12 | ///
13 | /// Helper methods for .
14 | ///
15 | public static partial class IManagedJobExtensions
16 | {
17 | ///
18 | public static JobHandle Schedule(this T job, JobHandle dependsOn = default)
19 | where T : IManagedJob
20 | {
21 | if (typeof(T).IsValueType)
22 | {
23 | StrongBox box = ObjectPool>.Shared.Rent();
24 | #if UNITY_WEBGL
25 | box.Value = job;
26 | return new JobWithKey(GlobalDictionary>.Store(box)).Schedule(dependsOn);
27 | #else
28 | box.Value = job;
29 | return new JobWithHandle(GCHandle.Alloc(box, GCHandleType.Pinned)).Schedule(dependsOn);
30 | #endif
31 | }
32 | else
33 | {
34 | #if UNITY_WEBGL
35 | return new JobWithKey(GlobalDictionary.Store(job)).Schedule(dependsOn);
36 | #else
37 | return new JobWithHandle(GCHandle.Alloc(job, GCHandleType.Pinned)).Schedule(dependsOn);
38 | #endif
39 | }
40 | }
41 |
42 | ///
43 | /// Wrap a job into a managed job.
44 | ///
45 | /// Type of job to wrap.
46 | /// Job to wrap.
47 | /// Wrapped job.
48 | public static ManagedJob AsManaged(this T job) where T : IJob
49 | => new ManagedJob(job);
50 |
51 | ///
52 | public static void Run(this T job)
53 | where T : IManagedJob
54 | {
55 | if (typeof(T).IsValueType)
56 | {
57 | #if UNITY_WEBGL
58 | StrongBox box = ObjectPool>.Shared.Rent();
59 | box.Value = job;
60 | new JobWithKey(GlobalDictionary>.Store(box)).Run();
61 | #else
62 | StrongBox box = ObjectPool>.Shared.Rent();
63 | box.Value = job;
64 | new JobWithHandle(GCHandle.Alloc(box, GCHandleType.Pinned)).Run();
65 | #endif
66 | }
67 | else
68 | {
69 | #if UNITY_WEBGL
70 | new JobWithKey(GlobalDictionary.Store(job)).Run();
71 | #else
72 | new JobWithHandle(GCHandle.Alloc(job, GCHandleType.Pinned)).Run();
73 | #endif
74 | }
75 | }
76 |
77 | #if !UNITY_WEBGL
78 | private readonly struct JobWithHandle : IJob
79 | {
80 | private readonly GCHandle handle;
81 |
82 | public JobWithHandle(GCHandle handle) => this.handle = handle;
83 |
84 | public void Execute()
85 | {
86 | object target = handle.Target;
87 | Debug.Assert(target is IManagedJob);
88 | IManagedJob job = Unsafe.As(target);
89 | handle.Free();
90 | job.Execute();
91 | }
92 | }
93 |
94 | private readonly struct JobWithHandle : IJob where T : IManagedJob
95 | {
96 | private readonly GCHandle handle;
97 |
98 | public JobWithHandle(GCHandle handle) => this.handle = handle;
99 |
100 | public void Execute()
101 | {
102 | object target = handle.Target;
103 | Debug.Assert(target is StrongBox);
104 | StrongBox box = Unsafe.As>(target);
105 | handle.Free();
106 | T job = box.Value;
107 | ObjectPool>.Shared.Return(box);
108 | job.Execute();
109 | }
110 | }
111 | #else
112 | private readonly struct JobWithKey : IJob
113 | {
114 | private readonly long key;
115 |
116 | public JobWithKey(long key) => this.key = key;
117 |
118 | public void Execute() => GlobalDictionary.Drain(key).Execute();
119 | }
120 |
121 | private readonly struct JobWithKey : IJob where T : IManagedJob
122 | {
123 | private readonly long key;
124 |
125 | public JobWithKey(long key) => this.key = key;
126 |
127 | public void Execute()
128 | {
129 | StrongBox box = GlobalDictionary>.Drain(key);
130 | T job = box.Value;
131 | ObjectPool>.Shared.Return(box);
132 | job.Execute();
133 | }
134 | }
135 | #endif
136 | }
137 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed/IManagedJob/IManagedJobExtensions.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b1b934bbeabf65c488f395c74d5f6905
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed/IManagedJob/ManagedJob.cs:
--------------------------------------------------------------------------------
1 | using Unity.Jobs;
2 |
3 | namespace Enderlook.Unity.Jobs
4 | {
5 | ///
6 | /// Wrap a job into a managed job.
7 | ///
8 | /// Type of job to wrap.
9 | public readonly struct ManagedJob : IManagedJob where T : IJob
10 | {
11 | private readonly T job;
12 |
13 | internal ManagedJob(T job) => this.job = job;
14 |
15 | ///
16 | void IManagedJob.Execute() => job.Execute();
17 | }
18 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed/IManagedJob/ManagedJob.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3b9df9ea8971b514d87e6c7fa751809b
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed/IManagedJobParallelFor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f41a80889ec9e5c4eb2055bacbd643b2
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed/IManagedJobParallelFor/IManagedJobParallelFor.cs:
--------------------------------------------------------------------------------
1 | using Unity.Jobs;
2 |
3 | namespace Enderlook.Unity.Jobs
4 | {
5 | ///
6 | /// Represent an that contains managed data.
7 | ///
8 | public interface IManagedJobParallelFor
9 | {
10 | ///
11 | /// Action to execute.
12 | ///
13 | /// Index of element to execute
14 | void Execute(int index);
15 | }
16 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed/IManagedJobParallelFor/IManagedJobParallelFor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 93fd7ccd4a2ea4d41a85350b4a2eb819
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed/IManagedJobParallelFor/IManagedJobParallelForExtensions.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3339797b41e826f4f9833061846da964
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed/IManagedJobParallelFor/ManagedJobParallelFor.cs:
--------------------------------------------------------------------------------
1 | using Unity.Jobs;
2 |
3 | namespace Enderlook.Unity.Jobs
4 | {
5 | ///
6 | /// Wrap a job into a managed job.
7 | ///
8 | /// Type of job to wrap.
9 | public readonly struct ManagedJobParallelFor : IManagedJobParallelFor where T : IJobParallelFor
10 | {
11 | private readonly T job;
12 |
13 | internal ManagedJobParallelFor(T job) => this.job = job;
14 |
15 | ///
16 | void IManagedJobParallelFor.Execute(int index) => job.Execute(index);
17 | }
18 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/Runtime/Managed/IManagedJobParallelFor/ManagedJobParallelFor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f3904c0992269c8428f4c8778989595a
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.enderlook.unity.jobs",
3 | "version": "0.1.5",
4 | "displayName": "Enderlook Unity Jobs",
5 | "description": "Provides utility methods for working with Unity Jobs.",
6 | "unity": "2019.2",
7 | "keywords": [
8 | "utility",
9 | "threading",
10 | "jobs"
11 | ],
12 | "dependencies": {
13 | "com.enderlook.collections.low_level": "https://github.com/Enderlook/Unity-Net-Packages.git?path=Packages/com.enderlook.collections.low_level#com.enderlook.collections.low_level/v0.8.0",
14 | "com.enderlook.unity.threading": "https://github.com/Enderlook/Unity-Threading.git?/path=Packages/com.enderlook.unity.threading#com.enderlook.unity.threading/v0.7.7",
15 | "com.enderlook.unity.toolset.utils": "https://github.com/Enderlook/Unity-Toolset.git?path=Packages/com.enderlook.unity.toolset.utils#com.enderlook.unity.toolset.utils/v0.7.0"
16 | },
17 | "author": {
18 | "name": "Enderlook",
19 | "url": "https://github.com/Enderlook"
20 | }
21 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.jobs/package.json.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3d0d89b76eeb48846817fb330a3b2f1e
3 | PackageManifestImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a5792da64c7b0cb48af904de3abacd5a
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime/Enderlook.Unity.Threading.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Enderlook.Unity.Threading",
3 | "references": [],
4 | "includePlatforms": [],
5 | "excludePlatforms": [],
6 | "allowUnsafeCode": false,
7 | "overrideReferences": false,
8 | "precompiledReferences": [],
9 | "autoReferenced": true,
10 | "defineConstraints": [],
11 | "versionDefines": []
12 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime/Enderlook.Unity.Threading.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 12965892c664bf44cbd63f6568ef40da
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime/InternalsVisibleTo.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | [assembly: InternalsVisibleTo("Enderlook.Unity.Coroutines")]
4 | [assembly: InternalsVisibleTo("Enderlook.Unity.Coroutines-Editor")]
5 | [assembly: InternalsVisibleTo("Enderlook.Unity.Events")]
6 | [assembly: InternalsVisibleTo("Enderlook.Unity.Events-Editor")]
7 | [assembly: InternalsVisibleTo("Enderlook.Unity.Jobs")]
8 | [assembly: InternalsVisibleTo("Enderlook.Unity.Jobs-Editor")]
9 | [assembly: InternalsVisibleTo("Enderlook.Unity.Async")]
10 | [assembly: InternalsVisibleTo("Enderlook.Unity.AsyncEditor")]
11 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime/InternalsVisibleTo.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 42c4cb7593bde38479f1a67f5c8c5e42
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime/Unity Thread.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9f2f9ca195920dd4b8b66c506486580d
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime/Unity Thread/UnitySynchronizationContextUtility.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using System.Threading.Tasks;
4 |
5 | using UnityEditor;
6 |
7 | using UnityEngine;
8 |
9 | namespace Enderlook.Unity.Threading
10 | {
11 | ///
12 | /// A helper class to gather the thread id and synchronization context of Unity main thread.
13 | ///
14 | internal static class UnitySynchronizationContextUtility
15 | {
16 | ///
17 | /// Synchronization context used by Unity.
18 | ///
19 | public static SynchronizationContext UnitySynchronizationContext
20 | {
21 | get
22 | {
23 | if (!wasInitialized)
24 | throw new InvalidOperationException("Can't get Unity Synchronization Context before Unity initializes the syncronization.");
25 | return unitySynchronizationContext;
26 | }
27 | private set => unitySynchronizationContext = value;
28 | }
29 |
30 | ///
31 | /// Thread Id used by Unity main thread.
32 | ///
33 | public static int UnityThreadId
34 | {
35 | get
36 | {
37 | if (!wasInitialized)
38 | throw new InvalidOperationException("Can't get Unity Synchronization Context before Unity initializes the syncronization.");
39 | return unityThreadId;
40 | }
41 | private set => unityThreadId = value;
42 | }
43 |
44 | ///
45 | /// Task Scheduler used by Unity.
46 | ///
47 | public static TaskScheduler UnityTaskScheduler
48 | {
49 | get
50 | {
51 | if (!wasInitialized)
52 | throw new InvalidOperationException("Can't get Unity Synchronization Context before Unity initializes the syncronization.");
53 | return unityTaskScheduler;
54 | }
55 | private set => unityTaskScheduler = value;
56 | }
57 |
58 | // https://github.com/svermeulen/Unity3dAsyncAwaitUtil/blob/master/UnityProject/Assets/Plugins/AsyncAwaitUtil/Source/Internal/SyncContextUtil.cs
59 |
60 | private static bool wasInitialized;
61 | private static SynchronizationContext unitySynchronizationContext;
62 | private static int unityThreadId;
63 | private static TaskScheduler unityTaskScheduler;
64 |
65 | #if UNITY_EDITOR
66 | [InitializeOnLoadMethod]
67 | #endif
68 | [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
69 | private static void Initialize()
70 | {
71 | if (wasInitialized)
72 | return;
73 | wasInitialized = true;
74 | UnitySynchronizationContext = SynchronizationContext.Current;
75 | UnityThreadId = Thread.CurrentThread.ManagedThreadId;
76 | UnityTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
77 | }
78 | }
79 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime/Unity Thread/UnitySynchronizationContextUtility.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a08093210292c6b488c52ced5fce005f
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime/Unity Thread/UnityThread.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f64b586d374dc734faececb09837aa5a
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime/Utility.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 622ac10f1c9b40a44b0d8a1e2eda58f6
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime/Utility/Manager.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ee8e8a78eea9be9459cd775f9e045bca
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime/Utility/Tuple2.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Pools;
2 |
3 | namespace Enderlook.Unity.Threading
4 | {
5 | internal sealed class Tuple2
6 | {
7 | public T1 Item1;
8 | public T2 Item2;
9 |
10 | public static Tuple2 Rent(T1 item1, T2 item2)
11 | {
12 | Tuple2 tuple = ObjectPool>.Shared.Rent();
13 | tuple.Item1 = item1;
14 | tuple.Item2 = item2;
15 | return tuple;
16 | }
17 |
18 | public static Tuple2 Rent(T1 item1)
19 | {
20 | Tuple2 tuple = ObjectPool>.Shared.Rent();
21 | tuple.Item1 = item1;
22 | return tuple;
23 | }
24 |
25 | public void Return()
26 | {
27 | Item1 = default; // TODO: In .Net Standard 2.1 use RuntimeHelpers.IsReferenceOrContainsReferences.
28 | Item2 = default; // TODO: In .Net Standard 2.1 use RuntimeHelpers.IsReferenceOrContainsReferences.
29 | ObjectPool>.Shared.Return(this);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime/Utility/Tuple2.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 560ccbc1de8f829459317c548036a0c3
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime/Utility/Tuple3.cs:
--------------------------------------------------------------------------------
1 | using Enderlook.Pools;
2 |
3 | namespace Enderlook.Unity.Threading
4 | {
5 | internal sealed class Tuple3
6 | {
7 | public T1 Item1;
8 | public T2 Item2;
9 | public T3 Item3;
10 |
11 | public static Tuple3 Rent(T1 item1, T2 item2, T3 item3)
12 | {
13 | Tuple3 tuple = ObjectPool>.Shared.Rent();
14 | tuple.Item1 = item1;
15 | tuple.Item2 = item2;
16 | tuple.Item3 = item3;
17 | return tuple;
18 | }
19 |
20 | public static Tuple3 Rent(T1 item1, T2 item2)
21 | {
22 | Tuple3 tuple = ObjectPool>.Shared.Rent();
23 | tuple.Item1 = item1;
24 | tuple.Item2 = item2;
25 | return tuple;
26 | }
27 |
28 | public void Return()
29 | {
30 | Item1 = default; // TODO: In .Net Standard 2.1 use RuntimeHelpers.IsReferenceOrContainsReferences.
31 | Item2 = default; // TODO: In .Net Standard 2.1 use RuntimeHelpers.IsReferenceOrContainsReferences.
32 | Item3 = default; // TODO: In .Net Standard 2.1 use RuntimeHelpers.IsReferenceOrContainsReferences.
33 | ObjectPool>.Shared.Return(this);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/Runtime/Utility/Tuple3.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 45a111f3f123e3b47823d57d19bfeb97
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.enderlook.unity.threading",
3 | "version": "0.7.7",
4 | "displayName": "Enderlook Unity Threading",
5 | "description": "Provides utility methods for working with multithreading and tasks.",
6 | "unity": "2019.2",
7 | "keywords": [
8 | "utility",
9 | "threading",
10 | "tasks"
11 | ],
12 | "dependencies": {
13 | "com.enderlook.collections.low_level": "https://github.com/Enderlook/Unity-Net-Packages.git?path=Packages/com.enderlook.collections.low_level#com.enderlook.collections.low_level/v0.8.0",
14 | "com.enderlook.pools": "https://github.com/Enderlook/Unity-Net-Packages.git?path=Packages/com.enderlook.pools#com.enderlook.pools/v0.2.3",
15 | "com.system.runtime.compiler_services.unsafe": "https://github.com/Enderlook/Unity-Net-Packages.git?path=Packages/com.runtime.compiler_services.unsafe#com.runtime.compiler_services.unsafe/v4.5.3"
16 | },
17 | "author": {
18 | "name": "Enderlook",
19 | "url": "https://github.com/Enderlook"
20 | }
21 | }
--------------------------------------------------------------------------------
/Packages/com.enderlook.unity.threading/package.json.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0ad18901cfc657d4f84e5ddd9bc9cf19
3 | PackageManifestImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Packages/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "com.coffee.git-dependency-resolver": "https://github.com/mob-sakai/GitDependencyResolverForUnity.git#2.0.0",
4 | "com.unity.collab-proxy": "1.15.4",
5 | "com.unity.ext.nunit": "1.0.6",
6 | "com.unity.ide.rider": "2.0.7",
7 | "com.unity.ide.visualstudio": "2.0.12",
8 | "com.unity.ide.vscode": "1.2.4",
9 | "com.unity.test-framework": "1.1.29",
10 | "com.unity.textmeshpro": "3.0.6",
11 | "com.unity.timeline": "1.4.8",
12 | "com.unity.ugui": "1.0.0",
13 | "com.unity.modules.ai": "1.0.0",
14 | "com.unity.modules.androidjni": "1.0.0",
15 | "com.unity.modules.animation": "1.0.0",
16 | "com.unity.modules.assetbundle": "1.0.0",
17 | "com.unity.modules.audio": "1.0.0",
18 | "com.unity.modules.cloth": "1.0.0",
19 | "com.unity.modules.director": "1.0.0",
20 | "com.unity.modules.imageconversion": "1.0.0",
21 | "com.unity.modules.imgui": "1.0.0",
22 | "com.unity.modules.jsonserialize": "1.0.0",
23 | "com.unity.modules.particlesystem": "1.0.0",
24 | "com.unity.modules.physics": "1.0.0",
25 | "com.unity.modules.physics2d": "1.0.0",
26 | "com.unity.modules.screencapture": "1.0.0",
27 | "com.unity.modules.terrain": "1.0.0",
28 | "com.unity.modules.terrainphysics": "1.0.0",
29 | "com.unity.modules.tilemap": "1.0.0",
30 | "com.unity.modules.ui": "1.0.0",
31 | "com.unity.modules.uielements": "1.0.0",
32 | "com.unity.modules.umbra": "1.0.0",
33 | "com.unity.modules.unityanalytics": "1.0.0",
34 | "com.unity.modules.unitywebrequest": "1.0.0",
35 | "com.unity.modules.unitywebrequestassetbundle": "1.0.0",
36 | "com.unity.modules.unitywebrequestaudio": "1.0.0",
37 | "com.unity.modules.unitywebrequesttexture": "1.0.0",
38 | "com.unity.modules.unitywebrequestwww": "1.0.0",
39 | "com.unity.modules.vehicles": "1.0.0",
40 | "com.unity.modules.video": "1.0.0",
41 | "com.unity.modules.vr": "1.0.0",
42 | "com.unity.modules.wind": "1.0.0",
43 | "com.unity.modules.xr": "1.0.0"
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Packages/packages-lock.git.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": [
3 | {
4 | "name": "com.system.threading.tasks.extensions",
5 | "hash": "57b64eece04ab26d1704661895393891263cedc8",
6 | "url": "https://github.com/Enderlook/Unity-Net-Packages?path=Packages/com.system.threading.tasks.extensions#com.system.threading.tasks.extensions/v4.5.4"
7 | },
8 | {
9 | "name": "com.enderlook.threading",
10 | "hash": "3873b822b18c29fe2a57a0cad498b6be87566075",
11 | "url": "https://github.com/Enderlook/Unity-Net-Packages?path=Packages/com.enderlook.threading#com.enderlook.threading/v0.2.0"
12 | },
13 | {
14 | "name": "com.enderlook.collections.low_level",
15 | "hash": "82d16686f901d2945ded6b9c49bfa5eb5d6e8bc5",
16 | "url": "https://github.com/Enderlook/Unity-Net-Packages.git?path=Packages/com.enderlook.collections.low_level#com.enderlook.collections.low_level/v0.6.0"
17 | },
18 | {
19 | "name": "com.enderlook.pools",
20 | "hash": "9a857f290f6f623a7b5ad9e1ea50fb9b323337ea",
21 | "url": "https://github.com/Enderlook/Unity-Net-Packages.git?path=Packages/com.enderlook.pools#com.enderlook.pools/v0.2.1"
22 | },
23 | {
24 | "name": "com.system.memory",
25 | "hash": "b0ec3817f35dedf57c54f6aaafa2485c31e69b35",
26 | "url": "https://github.com/Enderlook/Unity-Net-Packages.git?path=Packages/com.system.memory#com.system.memory/v4.5.4"
27 | },
28 | {
29 | "name": "com.system.runtime.compiler_services.unsafe",
30 | "hash": "4e1388856d84de15006350d375973450c3eb04dd",
31 | "url": "https://github.com/Enderlook/Unity-Net-Packages.git?path=Packages/com.system.runtime.compiler_services.unsafe#com.system.runtime.compiler_services.unsafe/v4.5.3"
32 | },
33 | {
34 | "name": "com.system.buffers",
35 | "hash": "842c2cae1b41589606841297c3cc49d09fc73648",
36 | "url": "https://github.com/Enderlook/Unity-Net-Packages.git?path=Packages/com.system.buffers#com.system.buffers/v4.5.1"
37 | },
38 | {
39 | "name": "com.enderlook.unity.toolset.utils",
40 | "hash": "480aaf4cbc04d3e13832d9f6f6b35b0e62144743",
41 | "url": "https://github.com/Enderlook/Unity-Toolset.git?path=Packages/com.enderlook.unity.toolset.utils#com.enderlook.unity.toolset.utils/v0.6.0"
42 | }
43 | ]
44 | }
--------------------------------------------------------------------------------
/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!11 &1
4 | AudioManager:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | m_Volume: 1
8 | Rolloff Scale: 1
9 | Doppler Factor: 1
10 | Default Speaker Mode: 2
11 | m_SampleRate: 0
12 | m_DSPBufferSize: 1024
13 | m_VirtualVoiceCount: 512
14 | m_RealVoiceCount: 32
15 | m_SpatializerPlugin:
16 | m_AmbisonicDecoderPlugin:
17 | m_DisableAudio: 0
18 | m_VirtualizeEffects: 1
19 | m_RequestedDSPBufferSize: 1024
20 |
--------------------------------------------------------------------------------
/ProjectSettings/ClusterInputManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!236 &1
4 | ClusterInputManager:
5 | m_ObjectHideFlags: 0
6 | m_Inputs: []
7 |
--------------------------------------------------------------------------------
/ProjectSettings/DynamicsManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!55 &1
4 | PhysicsManager:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 11
7 | m_Gravity: {x: 0, y: -9.81, z: 0}
8 | m_DefaultMaterial: {fileID: 0}
9 | m_BounceThreshold: 2
10 | m_SleepThreshold: 0.005
11 | m_DefaultContactOffset: 0.01
12 | m_DefaultSolverIterations: 6
13 | m_DefaultSolverVelocityIterations: 1
14 | m_QueriesHitBackfaces: 0
15 | m_QueriesHitTriggers: 1
16 | m_EnableAdaptiveForce: 0
17 | m_ClothInterCollisionDistance: 0
18 | m_ClothInterCollisionStiffness: 0
19 | m_ContactsGeneration: 1
20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
21 | m_AutoSimulation: 1
22 | m_AutoSyncTransforms: 0
23 | m_ReuseCollisionCallbacks: 1
24 | m_ClothInterCollisionSettingsToggle: 0
25 | m_ContactPairsMode: 0
26 | m_BroadphaseType: 0
27 | m_WorldBounds:
28 | m_Center: {x: 0, y: 0, z: 0}
29 | m_Extent: {x: 250, y: 250, z: 250}
30 | m_WorldSubdivisions: 8
31 | m_FrictionType: 0
32 | m_EnableEnhancedDeterminism: 0
33 | m_EnableUnifiedHeightmaps: 1
34 | m_DefaultMaxAngluarSpeed: 7
35 |
--------------------------------------------------------------------------------
/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!1045 &1
4 | EditorBuildSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | m_Scenes: []
8 | m_configObjects: {}
9 |
--------------------------------------------------------------------------------
/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!159 &1
4 | EditorSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 8
7 | m_ExternalVersionControlSupport: Hidden Meta Files
8 | m_SerializationMode: 2
9 | m_LineEndingsForNewScripts: 2
10 | m_DefaultBehaviorMode: 0
11 | m_PrefabRegularEnvironment: {fileID: 0}
12 | m_PrefabUIEnvironment: {fileID: 0}
13 | m_SpritePackerMode: 0
14 | m_SpritePackerPaddingPower: 1
15 | m_EtcTextureCompressorBehavior: 1
16 | m_EtcTextureFastCompressor: 1
17 | m_EtcTextureNormalCompressor: 2
18 | m_EtcTextureBestCompressor: 4
19 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;rsp;asmref
20 | m_ProjectGenerationRootNamespace:
21 | m_CollabEditorSettings:
22 | inProgressEnabled: 1
23 | m_EnableTextureStreamingInEditMode: 1
24 | m_EnableTextureStreamingInPlayMode: 1
25 | m_AsyncShaderCompilation: 1
26 | m_ShowLightmapResolutionOverlay: 1
27 |
--------------------------------------------------------------------------------
/ProjectSettings/GraphicsSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!30 &1
4 | GraphicsSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 12
7 | m_Deferred:
8 | m_Mode: 1
9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0}
10 | m_DeferredReflections:
11 | m_Mode: 1
12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0}
13 | m_ScreenSpaceShadows:
14 | m_Mode: 1
15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0}
16 | m_LegacyDeferred:
17 | m_Mode: 1
18 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0}
19 | m_DepthNormals:
20 | m_Mode: 1
21 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0}
22 | m_MotionVectors:
23 | m_Mode: 1
24 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0}
25 | m_LightHalo:
26 | m_Mode: 1
27 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0}
28 | m_LensFlare:
29 | m_Mode: 1
30 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0}
31 | m_AlwaysIncludedShaders:
32 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0}
33 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0}
34 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0}
35 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0}
36 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
37 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
38 | m_PreloadedShaders: []
39 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
40 | type: 0}
41 | m_CustomRenderPipeline: {fileID: 0}
42 | m_TransparencySortMode: 0
43 | m_TransparencySortAxis: {x: 0, y: 0, z: 1}
44 | m_DefaultRenderingPath: 1
45 | m_DefaultMobileRenderingPath: 1
46 | m_TierSettings: []
47 | m_LightmapStripping: 0
48 | m_FogStripping: 0
49 | m_InstancingStripping: 0
50 | m_LightmapKeepPlain: 1
51 | m_LightmapKeepDirCombined: 1
52 | m_LightmapKeepDynamicPlain: 1
53 | m_LightmapKeepDynamicDirCombined: 1
54 | m_LightmapKeepShadowMask: 1
55 | m_LightmapKeepSubtractive: 1
56 | m_FogKeepLinear: 1
57 | m_FogKeepExp: 1
58 | m_FogKeepExp2: 1
59 | m_AlbedoSwatchInfos: []
60 | m_LightsUseLinearIntensity: 0
61 | m_LightsUseColorTemperature: 0
62 |
--------------------------------------------------------------------------------
/ProjectSettings/NavMeshAreas.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!126 &1
4 | NavMeshProjectSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | areas:
8 | - name: Walkable
9 | cost: 1
10 | - name: Not Walkable
11 | cost: 1
12 | - name: Jump
13 | cost: 2
14 | - name:
15 | cost: 1
16 | - name:
17 | cost: 1
18 | - name:
19 | cost: 1
20 | - name:
21 | cost: 1
22 | - name:
23 | cost: 1
24 | - name:
25 | cost: 1
26 | - name:
27 | cost: 1
28 | - name:
29 | cost: 1
30 | - name:
31 | cost: 1
32 | - name:
33 | cost: 1
34 | - name:
35 | cost: 1
36 | - name:
37 | cost: 1
38 | - name:
39 | cost: 1
40 | - name:
41 | cost: 1
42 | - name:
43 | cost: 1
44 | - name:
45 | cost: 1
46 | - name:
47 | cost: 1
48 | - name:
49 | cost: 1
50 | - name:
51 | cost: 1
52 | - name:
53 | cost: 1
54 | - name:
55 | cost: 1
56 | - name:
57 | cost: 1
58 | - name:
59 | cost: 1
60 | - name:
61 | cost: 1
62 | - name:
63 | cost: 1
64 | - name:
65 | cost: 1
66 | - name:
67 | cost: 1
68 | - name:
69 | cost: 1
70 | - name:
71 | cost: 1
72 | m_LastAgentTypeID: -887442657
73 | m_Settings:
74 | - serializedVersion: 2
75 | agentTypeID: 0
76 | agentRadius: 0.5
77 | agentHeight: 2
78 | agentSlope: 45
79 | agentClimb: 0.75
80 | ledgeDropHeight: 0
81 | maxJumpAcrossDistance: 0
82 | minRegionArea: 2
83 | manualCellSize: 0
84 | cellSize: 0.16666667
85 | manualTileSize: 0
86 | tileSize: 256
87 | accuratePlacement: 0
88 | debug:
89 | m_Flags: 0
90 | m_SettingNames:
91 | - Humanoid
92 |
--------------------------------------------------------------------------------
/ProjectSettings/Physics2DSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!19 &1
4 | Physics2DSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 4
7 | m_Gravity: {x: 0, y: -9.81}
8 | m_DefaultMaterial: {fileID: 0}
9 | m_VelocityIterations: 8
10 | m_PositionIterations: 3
11 | m_VelocityThreshold: 1
12 | m_MaxLinearCorrection: 0.2
13 | m_MaxAngularCorrection: 8
14 | m_MaxTranslationSpeed: 100
15 | m_MaxRotationSpeed: 360
16 | m_BaumgarteScale: 0.2
17 | m_BaumgarteTimeOfImpactScale: 0.75
18 | m_TimeToSleep: 0.5
19 | m_LinearSleepTolerance: 0.01
20 | m_AngularSleepTolerance: 2
21 | m_DefaultContactOffset: 0.01
22 | m_JobOptions:
23 | serializedVersion: 2
24 | useMultithreading: 0
25 | useConsistencySorting: 0
26 | m_InterpolationPosesPerJob: 100
27 | m_NewContactsPerJob: 30
28 | m_CollideContactsPerJob: 100
29 | m_ClearFlagsPerJob: 200
30 | m_ClearBodyForcesPerJob: 200
31 | m_SyncDiscreteFixturesPerJob: 50
32 | m_SyncContinuousFixturesPerJob: 50
33 | m_FindNearestContactsPerJob: 100
34 | m_UpdateTriggerContactsPerJob: 100
35 | m_IslandSolverCostThreshold: 100
36 | m_IslandSolverBodyCostScale: 1
37 | m_IslandSolverContactCostScale: 10
38 | m_IslandSolverJointCostScale: 10
39 | m_IslandSolverBodiesPerJob: 50
40 | m_IslandSolverContactsPerJob: 50
41 | m_AutoSimulation: 1
42 | m_QueriesHitTriggers: 1
43 | m_QueriesStartInColliders: 1
44 | m_CallbacksOnDisable: 1
45 | m_ReuseCollisionCallbacks: 1
46 | m_AutoSyncTransforms: 0
47 | m_AlwaysShowColliders: 0
48 | m_ShowColliderSleep: 1
49 | m_ShowColliderContacts: 0
50 | m_ShowColliderAABB: 0
51 | m_ContactArrowScale: 0.2
52 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412}
53 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
54 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
55 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
56 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
57 |
--------------------------------------------------------------------------------
/ProjectSettings/PresetManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!1386491679 &1
4 | PresetManager:
5 | m_ObjectHideFlags: 0
6 | m_DefaultList: []
7 |
--------------------------------------------------------------------------------
/ProjectSettings/ProjectVersion.txt:
--------------------------------------------------------------------------------
1 | m_EditorVersion: 2020.3.25f1
2 | m_EditorVersionWithRevision: 2020.3.25f1 (9b9180224418)
3 |
--------------------------------------------------------------------------------
/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!78 &1
4 | TagManager:
5 | serializedVersion: 2
6 | tags: []
7 | layers:
8 | - Default
9 | - TransparentFX
10 | - Ignore Raycast
11 | -
12 | - Water
13 | - UI
14 | -
15 | -
16 | -
17 | -
18 | -
19 | -
20 | -
21 | -
22 | -
23 | -
24 | -
25 | -
26 | -
27 | -
28 | -
29 | -
30 | -
31 | -
32 | -
33 | -
34 | -
35 | -
36 | -
37 | -
38 | -
39 | -
40 | m_SortingLayers:
41 | - name: Default
42 | uniqueID: 0
43 | locked: 0
44 |
--------------------------------------------------------------------------------
/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!5 &1
4 | TimeManager:
5 | m_ObjectHideFlags: 0
6 | Fixed Timestep: 0.02
7 | Maximum Allowed Timestep: 0.33333334
8 | m_TimeScale: 1
9 | Maximum Particle Timestep: 0.03
10 |
--------------------------------------------------------------------------------
/ProjectSettings/UnityConnectSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!310 &1
4 | UnityConnectSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 1
7 | m_Enabled: 0
8 | m_TestMode: 0
9 | m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events
10 | m_EventUrl: https://cdp.cloud.unity3d.com/v1/events
11 | m_ConfigUrl: https://config.uca.cloud.unity3d.com
12 | m_TestInitMode: 0
13 | CrashReportingSettings:
14 | m_EventUrl: https://perf-events.cloud.unity3d.com
15 | m_Enabled: 0
16 | m_LogBufferSize: 10
17 | m_CaptureEditorExceptions: 1
18 | UnityPurchasingSettings:
19 | m_Enabled: 0
20 | m_TestMode: 0
21 | UnityAnalyticsSettings:
22 | m_Enabled: 0
23 | m_TestMode: 0
24 | m_InitializeOnStartup: 1
25 | UnityAdsSettings:
26 | m_Enabled: 0
27 | m_InitializeOnStartup: 1
28 | m_TestMode: 0
29 | m_IosGameId:
30 | m_AndroidGameId:
31 | m_GameIds: {}
32 | m_GameId:
33 | PerformanceReportingSettings:
34 | m_Enabled: 0
35 |
--------------------------------------------------------------------------------
/ProjectSettings/VFXManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!937362698 &1
4 | VFXManager:
5 | m_ObjectHideFlags: 0
6 | m_IndirectShader: {fileID: 0}
7 | m_CopyBufferShader: {fileID: 0}
8 | m_SortShader: {fileID: 0}
9 | m_RenderPipeSettingsPath:
10 | m_FixedTimeStep: 0.016666668
11 | m_MaxDeltaTime: 0.05
12 |
--------------------------------------------------------------------------------
/ProjectSettings/XRSettings.asset:
--------------------------------------------------------------------------------
1 | {
2 | "m_SettingKeys": [
3 | "VR Device Disabled",
4 | "VR Device User Alert"
5 | ],
6 | "m_SettingValues": [
7 | "False",
8 | "False"
9 | ]
10 | }
--------------------------------------------------------------------------------