| | 1 | | using DCL.Configuration; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityGLTF; |
| | 6 | |
|
| | 7 | | namespace DCL |
| | 8 | | { |
| | 9 | | public class Asset_GLTF : Asset_WithPoolableContainer |
| | 10 | | { |
| | 11 | | public string name; |
| 212 | 12 | | public bool visible = true; |
| | 13 | |
|
| 2268 | 14 | | public override GameObject container { get; set; } |
| | 15 | |
|
| 212 | 16 | | public HashSet<Mesh> meshes = new HashSet<Mesh>(); |
| 212 | 17 | | public Dictionary<Mesh, int> meshToTriangleCount = new Dictionary<Mesh, int>(); |
| 212 | 18 | | public HashSet<Renderer> renderers = new HashSet<Renderer>(); |
| 212 | 19 | | public HashSet<Material> materials = new HashSet<Material>(); |
| 212 | 20 | | public HashSet<Texture> textures = new HashSet<Texture>(); |
| 212 | 21 | | public HashSet<AnimationClip> animationClips = new HashSet<AnimationClip>(); |
| | 22 | | public int totalTriangleCount = 0; |
| | 23 | | public long animationClipSize = 0; |
| | 24 | | public long meshDataSize = 0; |
| | 25 | |
|
| | 26 | | Coroutine showCoroutine; |
| | 27 | |
|
| 212 | 28 | | public Asset_GLTF() |
| | 29 | | { |
| 212 | 30 | | container = new GameObject("Asset_GLTF Container"); |
| 212 | 31 | | visible = true; |
| 212 | 32 | | } |
| | 33 | |
|
| | 34 | | public override object Clone() |
| | 35 | | { |
| 135 | 36 | | Asset_GLTF result = this.MemberwiseClone() as Asset_GLTF; |
| 135 | 37 | | result.visible = true; |
| 135 | 38 | | result.meshes = new HashSet<Mesh>(meshes); |
| 135 | 39 | | result.renderers = new HashSet<Renderer>(renderers); |
| 135 | 40 | | result.materials = new HashSet<Material>(materials); |
| 135 | 41 | | result.textures = new HashSet<Texture>(textures); |
| 135 | 42 | | result.meshToTriangleCount = new Dictionary<Mesh, int>(meshToTriangleCount); |
| 135 | 43 | | result.animationClips = new HashSet<AnimationClip>(animationClips); |
| | 44 | |
|
| 135 | 45 | | return result; |
| | 46 | | } |
| | 47 | |
|
| | 48 | | public override void Cleanup() |
| | 49 | | { |
| | 50 | | #if UNITY_STANDALONE || UNITY_EDITOR |
| 250 | 51 | | if (DataStore.i.common.isApplicationQuitting.Get()) |
| 0 | 52 | | return; |
| | 53 | | #endif |
| | 54 | |
|
| 250 | 55 | | Object.Destroy(container); |
| 250 | 56 | | } |
| | 57 | |
|
| | 58 | | public void Hide() |
| | 59 | | { |
| 3 | 60 | | if (container != null) |
| | 61 | | { |
| 3 | 62 | | container.transform.parent = null; |
| 3 | 63 | | container.transform.position = EnvironmentSettings.MORDOR; |
| | 64 | | } |
| | 65 | |
|
| 3 | 66 | | visible = false; |
| 3 | 67 | | } |
| | 68 | |
|
| | 69 | | public void CancelShow() |
| | 70 | | { |
| 110 | 71 | | if (showCoroutine != null) |
| 1 | 72 | | CoroutineStarter.Stop(showCoroutine); |
| 110 | 73 | | } |
| | 74 | |
|
| | 75 | | public void Show(bool useMaterialTransition, System.Action OnFinish) |
| | 76 | | { |
| 33 | 77 | | if (showCoroutine != null) |
| 0 | 78 | | CoroutineStarter.Stop(showCoroutine); |
| | 79 | |
|
| 33 | 80 | | if (!visible) |
| | 81 | | { |
| 0 | 82 | | OnFinish?.Invoke(); |
| 0 | 83 | | return; |
| | 84 | | } |
| | 85 | |
|
| 33 | 86 | | bool renderingEnabled = CommonScriptableObjects.rendererState.Get(); |
| | 87 | |
|
| 33 | 88 | | if (!renderingEnabled || !useMaterialTransition) |
| | 89 | | { |
| 10 | 90 | | container.SetActive(true); |
| 10 | 91 | | OnFinish?.Invoke(); |
| 10 | 92 | | return; |
| | 93 | | } |
| | 94 | |
|
| 23 | 95 | | showCoroutine = CoroutineStarter.Start(ShowCoroutine(OnFinish)); |
| 23 | 96 | | } |
| | 97 | |
|
| | 98 | | public IEnumerator ShowCoroutine(System.Action OnFinish) |
| | 99 | | { |
| | 100 | | // NOTE(Brian): This fixes seeing the object in the scene 0,0 for a frame |
| 23 | 101 | | yield return new WaitForSeconds(Random.Range(0, 0.05f)); |
| | 102 | |
|
| | 103 | | // NOTE(Brian): This GameObject can be removed by distance after the delay |
| 22 | 104 | | if (container == null) |
| | 105 | | { |
| 0 | 106 | | OnFinish?.Invoke(); |
| 0 | 107 | | yield break; |
| | 108 | | } |
| | 109 | |
|
| 22 | 110 | | container?.SetActive(true); |
| 22 | 111 | | OnFinish?.Invoke(); |
| 22 | 112 | | } |
| | 113 | | } |
| | 114 | | } |