| | 1 | | using DCL.Configuration; |
| | 2 | | using System.Collections; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityGLTF; |
| | 5 | |
|
| | 6 | | namespace DCL |
| | 7 | | { |
| | 8 | | public class Asset_GLTF : Asset_WithPoolableContainer |
| | 9 | | { |
| 1873 | 10 | | public override GameObject container { get; set; } |
| | 11 | | public string name; |
| 111 | 12 | | public bool visible = true; |
| | 13 | |
|
| | 14 | | Coroutine showCoroutine; |
| | 15 | |
|
| 111 | 16 | | public Asset_GLTF() |
| | 17 | | { |
| 111 | 18 | | container = new GameObject(); |
| 111 | 19 | | container.name = "Asset_GLTF Container"; |
| 111 | 20 | | visible = true; |
| 111 | 21 | | } |
| | 22 | |
|
| | 23 | | public override object Clone() |
| | 24 | | { |
| 113 | 25 | | Asset_GLTF result = this.MemberwiseClone() as Asset_GLTF; |
| 113 | 26 | | result.visible = true; |
| 113 | 27 | | return result; |
| | 28 | | } |
| | 29 | |
|
| 222 | 30 | | public override void Cleanup() { Object.Destroy(container); } |
| | 31 | |
|
| | 32 | | public void Hide() |
| | 33 | | { |
| 23 | 34 | | if (container != null) |
| | 35 | | { |
| 23 | 36 | | container.transform.parent = null; |
| 23 | 37 | | container.transform.position = EnvironmentSettings.MORDOR; |
| | 38 | | } |
| 23 | 39 | | visible = false; |
| 23 | 40 | | } |
| | 41 | |
|
| | 42 | | public void CancelShow() |
| | 43 | | { |
| 7 | 44 | | if (showCoroutine != null) |
| 1 | 45 | | CoroutineStarter.Stop(showCoroutine); |
| 7 | 46 | | } |
| | 47 | |
|
| | 48 | | public void Show(bool useMaterialTransition, System.Action OnFinish) |
| | 49 | | { |
| 26 | 50 | | if (showCoroutine != null) |
| 0 | 51 | | CoroutineStarter.Stop(showCoroutine); |
| | 52 | |
|
| 26 | 53 | | if (!visible) |
| | 54 | | { |
| 0 | 55 | | OnFinish?.Invoke(); |
| 0 | 56 | | return; |
| | 57 | | } |
| | 58 | |
|
| 26 | 59 | | bool renderingEnabled = CommonScriptableObjects.rendererState.Get(); |
| | 60 | |
|
| 26 | 61 | | if (!renderingEnabled || !useMaterialTransition) |
| | 62 | | { |
| 2 | 63 | | container.SetActive(true); |
| 2 | 64 | | OnFinish?.Invoke(); |
| 2 | 65 | | return; |
| | 66 | | } |
| | 67 | |
|
| 24 | 68 | | showCoroutine = CoroutineStarter.Start(ShowCoroutine(OnFinish)); |
| 24 | 69 | | } |
| | 70 | |
|
| | 71 | | public IEnumerator ShowCoroutine(System.Action OnFinish) |
| | 72 | | { |
| | 73 | | // NOTE(Brian): This fixes seeing the object in the scene 0,0 for a frame |
| 24 | 74 | | yield return new WaitForSeconds(Random.Range(0, 0.05f)); |
| | 75 | |
|
| | 76 | | // NOTE(Brian): This GameObject can be removed by distance after the delay |
| 23 | 77 | | if (container == null) |
| | 78 | | { |
| 0 | 79 | | OnFinish?.Invoke(); |
| 0 | 80 | | yield break; |
| | 81 | | } |
| | 82 | |
|
| 23 | 83 | | container?.SetActive(true); |
| 23 | 84 | | OnFinish?.Invoke(); |
| 23 | 85 | | } |
| | 86 | | } |
| | 87 | | } |