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