using GLTFast; using HighlightPlus; using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; /// /// 态势标绘对象池 /// public class PowerPool : Singleton { private Dictionary pool = new Dictionary(); private List Data = new List(); public override void Awake() { base.Awake(); var url = $"{Application.streamingAssetsPath}/Config/PowerAttributeConfig.json"; HttpManager.Instance.Get>(url, data => Data = data); } public async Task GetPower(string key,Vector3 position,Quaternion rotation,Transform parent) { var temp = FindPower(key); GameObject go; if (temp == null) { temp = await LoadPower(key); } go = Instantiate(temp, position, rotation); go.transform.parent = parent; go.SetActive(true); return go; } private async Task LoadPower(string key) { AssetManager.Instance.SetLoadingPanel(true); //var path = $"{Application.streamingAssetsPath}/ModelBase/Powers/{key}/{key}.gltf"; var path = string.Format(HttpManager.Instance.GetPowerModel, 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); root.SetActive(false); SetAttribute(key, root); root.tag="power"; AssetManager.Instance.SetLoadingPanel(false); return root; } return null; } private void SetAttribute(string key, GameObject go) { var data = Data.Find(temp => temp.id == key); if (data.isBoxcollider) { var collider = go.AddComponent(); collider.center = data.boxColliderCenter; collider.size = data.boxColliderSize; } if (data.isMeshCollider) { if (go.transform.Find("Scene/Plane")) { var mesh = go.transform.Find("Scene/Plane").GetComponent().mesh; go.AddComponent(); go.AddComponent().sharedMesh = mesh; } if (go.transform.Find("Scene/SD")) { var mesh = go.transform.Find("Scene/SD").GetComponent().mesh; go.AddComponent().sharedMesh = mesh; } if (go.transform.Find("Scene/JJX")) { var mesh = go.transform.Find("Scene/JJX").GetComponent().mesh; go.AddComponent().sharedMesh = mesh; } } var controller = go.AddComponent(); controller.PowerMode = data.createMode; controller.taskType = data.taskType; controller.PrefabName = key; if (data.isInfo) { var info = Instantiate(AssetManager.Instance.powerInfo); info.name = "Info"; info.transform.parent = go.transform; if (go.GetComponent()) { var pos = go.GetComponent().size; info.transform.localPosition = new Vector3(0, pos.y+0.5f, 0); } if(key == "WZ") { info.transform.Find("Task").GetComponent().text = "文本信息"; info.transform.Find("Name").GetComponent().enabled = false; } if (key == "QYSD") { info.transform.Find("Task").GetComponent().text = "区域设定"; info.transform.Find("Name").GetComponent().enabled = false; } if (key == "JJQ") { info.transform.Find("Task").GetComponent().text = "集结区"; info.transform.Find("Name").GetComponent().enabled = false; } } go.AddComponent(); go.AddComponent(); var effacr = go.AddComponent(); effacr.profile = AssetManager.Instance.highlightProfile; effacr.profile.Load(effacr); var select = go.AddComponent(); switch (controller.PowerMode) { case CreationMode.Single: select.selectMode = SelectMode.Single; break; case CreationMode.Multipoint: case CreationMode.Pipeline: select.selectMode = SelectMode.Multiple; break; } if (data.isFiremanController) go.AddComponent().InitData(); if (data.isShuiGuanCheController) go.AddComponent().InitData(); if (data.isGaoPenCheController) go.AddComponent().InitData(); if (data.isDenGaoCheController) go.AddComponent().InitData(); if (data.isYunTiCheController) go.AddComponent().InitData(); if (data.isZhaoMingCheController) go.AddComponent().InitData(); if (data.isAreaController) go.AddComponent(); if (data.isWaterMonitorController) go.AddComponent().InitData(); if (data.isLT6Controller) go.AddComponent(); if (data.isLT15Controller) go.AddComponent(); } private GameObject FindPower(string key) { //从列中中找出未激活的游戏对象并返回 return pool.ContainsKey(key) ? pool[key] : null; } }