| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.Assertions; |
| | 5 | |
|
| | 6 | | namespace DCL |
| | 7 | | { |
| | 8 | | public class AssetPromise_Mock : AssetPromise<Asset_Mock> |
| | 9 | | { |
| | 10 | | public bool forceFail = false; |
| | 11 | | public float loadTime; |
| | 12 | | public object idGenerator; |
| | 13 | | private object id; |
| | 14 | | Coroutine assetMockCoroutine; |
| | 15 | |
|
| | 16 | | public override object GetId() |
| | 17 | | { |
| 230 | 18 | | Assert.IsTrue(idGenerator != null, "idGenerator should not be null"); |
| | 19 | |
|
| 230 | 20 | | if (id == null) |
| 67 | 21 | | id = idGenerator.GetHashCode(); |
| | 22 | |
|
| 230 | 23 | | return id; |
| | 24 | | } |
| | 25 | |
|
| | 26 | | protected override void OnLoad(Action OnSuccess, Action OnFail) |
| | 27 | | { |
| 13 | 28 | | loadTime = 1; |
| 13 | 29 | | assetMockCoroutine = CoroutineStarter.Start(MockLoadingCoroutine(OnSuccess, OnFail)); |
| 13 | 30 | | } |
| | 31 | |
|
| 12 | 32 | | protected override void OnCancelLoading() { CoroutineStarter.Stop(assetMockCoroutine); } |
| | 33 | |
|
| | 34 | | IEnumerator MockLoadingCoroutine(Action OnSuccess, Action OnFail) |
| | 35 | | { |
| 13 | 36 | | yield return WaitForSecondsCache.Get(loadTime); |
| | 37 | |
|
| 8 | 38 | | if (forceFail) |
| | 39 | | { |
| 1 | 40 | | OnFail?.Invoke(); |
| 1 | 41 | | } |
| | 42 | | else |
| | 43 | | { |
| 7 | 44 | | OnSuccess?.Invoke(); |
| | 45 | | } |
| 8 | 46 | | } |
| | 47 | |
|
| | 48 | | //NOTE(Brian): Used for testing |
| 10 | 49 | | public void Load_Test() { Load(); } |
| | 50 | |
|
| 0 | 51 | | public Asset_Mock GetAsset_Test() { return asset; } |
| | 52 | |
|
| 16 | 53 | | public void Unload_Test() { Unload(); } |
| | 54 | |
|
| 0 | 55 | | public void SetLibrary_Test(AssetLibrary<Asset_Mock> library) { this.library = library; } |
| | 56 | |
|
| 67 | 57 | | protected override void OnBeforeLoadOrReuse() { } |
| | 58 | |
|
| 61 | 59 | | protected override void OnAfterLoadOrReuse() { } |
| | 60 | | } |
| | 61 | |
|
| | 62 | | public class AssetPromise_Mock_Alt_Loading_Approach : AssetPromise_Mock { } |
| | 63 | | } |