using GLTFast; using HighlightPlus; using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; /// /// 周边水源和行车路线标记工具对象池 /// public class AnnotationPool : Singleton { private Dictionary pool = new Dictionary(); public async Task GetMarked(string key, Vector3 position, Quaternion rotation, Transform parent) { var temp = FindMarked(key); GameObject go; if (temp == null) { temp = await LoadMarked(key); } go = Instantiate(temp, position, rotation); go.transform.parent = parent; go.SetActive(true); return go; } private async Task LoadMarked(string key) { AssetManager.Instance.SetLoadingPanel(true); //var path = $"{Application.streamingAssetsPath}/ModelBase/Annotatios/{key}/{key}.gltf"; var path = string.Format(HttpManager.Instance.GetAnnotatioModel, key, key); var gltf = new GltfImport(); var success = await gltf.Load(path, new ImportSettings()); if (success) { var root = new GameObject(key); gltf.InstantiateMainScene(root.transform); pool.Add(key, root); SetAttribute(key, root); root.SetActive(false); AssetManager.Instance.SetLoadingPanel(false); return root; } return null; } private void SetAttribute(string key, GameObject go) { foreach (Transform t in go.GetComponentsInChildren()) t.gameObject.layer = LayerMask.NameToLayer("Annotation"); var boxCollider = go.AddComponent(); boxCollider.center = Vector3.zero; boxCollider.size = new Vector3(8, 5, 8); if (key.Contains("LX")) boxCollider.size = new Vector3(1f,0.5f,2f); var controller = go.AddComponent(); controller.OriginaName = key; if (key.Contains("LX")) controller.sourceMode = CreationMode.Multipoint; else controller.sourceMode = CreationMode.Single; go.AddComponent(); var effacr = go.AddComponent(); effacr.profile = AssetManager.Instance.highlightProfile; effacr.profile.Load(effacr); var info = Instantiate(AssetManager.Instance.annotationInfo); info.transform.parent = go.transform; info.name = "info"; switch (key) { case "Company": info.GetComponent().text = "单位名称"; break; case "DSXHS": info.GetComponent().text = "地上消火栓"; break; case "DXXHS": info.GetComponent().text = "地下消火栓"; break; case "TRSY": info.GetComponent().text = "天然水源"; break; case "XFSC": info.GetComponent().text = "消防水池"; break; case "XQZD": info.GetComponent().text = "辖区中队"; break; case "ZYZD": info.GetComponent().text = "增援中队"; break; case "XQZDLX": case "ZYZDLX": info.GetComponent().text = ""; break; } } private GameObject FindMarked(string key) { //从列中中找出未激活的游戏对象并返回 return pool.ContainsKey(key) ? pool[key] : null; } }