public void UnloadContent() { if (HasEmptyContent) { return; } ContentState = Unity3DTileContentState.UNLOADED; if (Content != null && Content.Go != null) { GameObject.Destroy(Content.Go); Content = null; Tileset.Behaviour.RequestUnloadUnusedAssets(); } }
protected override void UpdateAndApply(Unity3DTilesetStyle targetStyle, Unity3DTileContent content) { SimpleShaderTilesetStyle target = (SimpleShaderTilesetStyle)targetStyle; // Check to see if style attributes are out of date and lazily update if (target.Shader != this.Shader) { this.Shader = target.Shader; var renderers = content.GetRenderers(); for (int i = 0; i < renderers.Length; i++) { var r = renderers[i]; for (int j = 0; j < r.materials.Length; j++) { r.materials[j].shader = this.Shader; } } } }
/// <summary> /// Lower priority will be loaded sooner /// </summary> /// <param name="priority"></param> public void RequestContent(float priority) { if (HasEmptyContent || ContentState != Unity3DTileContentState.UNLOADED) { return; } Promise <bool> finished = new Promise <bool>(); finished.Then((success) => { Tileset.Statistics.RequestsThisFrame++; Tileset.Statistics.NetworkErrorsThisFrame += success ? 0 : 1; bool duplicate = false; if (success && Tileset.TileCache.Add(this, out duplicate)) { ContentState = Unity3DTileContentState.PROCESSING; Tileset.ProcessingQueue.Enqueue(this); } else if (!duplicate) { UnloadContent(); } }); Promise started = new Promise(); started.Then(() => { GameObject go = new GameObject(Id); go.transform.parent = Tileset.Behaviour.transform; go.transform.localPosition = new Vector3(computedTransform.m03, computedTransform.m13, computedTransform.m23); go.transform.localRotation = computedTransform.rotation; go.transform.localScale = computedTransform.lossyScale; go.layer = Tileset.Behaviour.gameObject.layer; go.SetActive(false); var info = go.AddComponent <Unity3DTileInfo>(); info.Tile = this; info.FrameState = FrameState; Content = new Unity3DTileContent(go); if (ContentType == Unity3DTileContentType.B3DM) { B3DMComponent b3dmCo = go.AddComponent <B3DMComponent>(); b3dmCo.Url = ContentUrl; b3dmCo.Multithreaded = Tileset.TilesetOptions.GLTFMultithreadedLoad; b3dmCo.MaximumLod = Tileset.TilesetOptions.GLTFMaximumLOD; if (!string.IsNullOrEmpty(Tileset.TilesetOptions.ShaderOverride)) { b3dmCo.ShaderOverride = Shader.Find(Tileset.TilesetOptions.ShaderOverride); } b3dmCo.AddColliders = false; b3dmCo.DownloadOnStart = false; Tileset.Behaviour.StartCoroutine(b3dmCo.Download(finished)); } else if (ContentType == Unity3DTileContentType.PNTS) { PNTSComponent pntsCo = go.AddComponent <PNTSComponent>(); pntsCo.Url = UrlUtils.RemoveQuery(ContentUrl); pntsCo.ShaderOverride = Shader.Find("Point Cloud/Point"); pntsCo.DownloadOnStart = false; Tileset.Behaviour.StartCoroutine(pntsCo.Download(finished)); } }); Tileset.RequestManager.EnqueRequest(new Request(this, started, finished)); }
/// <summary> /// This method should copy any relevant attributes from the target style to 'this' style /// In cases where the attributes are different the method should update materials on the tile accordingly /// </summary> /// <param name="targetStyle"></param> /// <param name="tile"></param> protected abstract void UpdateAndApply(Unity3DTilesetStyle targetStyle, Unity3DTileContent content);