You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
6.0 KiB
173 lines
6.0 KiB
using GLTFast; |
|
using HighlightPlus; |
|
using System.Collections.Generic; |
|
using System.Threading.Tasks; |
|
using UnityEngine; |
|
/// <summary> |
|
/// 态势标绘对象池 |
|
/// <summary> |
|
public class PowerPool : Singleton<PowerPool> |
|
{ |
|
private Dictionary<string, GameObject> pool = new Dictionary<string, GameObject>(); |
|
private List<PowerAttributeConfig> Data = new List<PowerAttributeConfig>(); |
|
|
|
public override void Awake() |
|
{ |
|
base.Awake(); |
|
var url = $"{Application.streamingAssetsPath}/Config/PowerAttributeConfig.json"; |
|
HttpManager.Instance.Get<List<PowerAttributeConfig>>(url, data => Data = data); |
|
} |
|
public async Task<GameObject> 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<GameObject> 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<BoxCollider>(); |
|
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<MeshFilter>().mesh; |
|
go.AddComponent<ModelMeshEditor>(); |
|
go.AddComponent<MeshCollider>().sharedMesh = mesh; |
|
} |
|
if (go.transform.Find("Scene/SD")) |
|
{ |
|
var mesh = go.transform.Find("Scene/SD").GetComponent<MeshFilter>().mesh; |
|
go.AddComponent<MeshCollider>().sharedMesh = mesh; |
|
} |
|
if (go.transform.Find("Scene/JJX")) |
|
{ |
|
var mesh = go.transform.Find("Scene/JJX").GetComponent<MeshFilter>().mesh; |
|
go.AddComponent<MeshCollider>().sharedMesh = mesh; |
|
} |
|
|
|
|
|
} |
|
|
|
var controller = go.AddComponent<PowerController>(); |
|
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<BoxCollider>()) |
|
{ |
|
var pos = go.GetComponent<BoxCollider>().size; |
|
info.transform.localPosition = new Vector3(0, pos.y+0.5f, 0); |
|
} |
|
if(key == "WZ") |
|
{ |
|
info.transform.Find("Task").GetComponent<TextMesh>().text = "文本信息"; |
|
info.transform.Find("Name").GetComponent<MeshRenderer>().enabled = false; |
|
|
|
} |
|
if (key == "QYSD") |
|
{ |
|
info.transform.Find("Task").GetComponent<TextMesh>().text = "区域设定"; |
|
info.transform.Find("Name").GetComponent<MeshRenderer>().enabled = false; |
|
|
|
} |
|
if (key == "JJQ") |
|
{ |
|
info.transform.Find("Task").GetComponent<TextMesh>().text = "集结区"; |
|
info.transform.Find("Name").GetComponent<MeshRenderer>().enabled = false; |
|
|
|
} |
|
} |
|
|
|
|
|
go.AddComponent<DragObject>(); |
|
go.AddComponent<PowerListening>(); |
|
var effacr = go.AddComponent<HighlightEffect>(); |
|
effacr.profile = AssetManager.Instance.highlightProfile; |
|
effacr.profile.Load(effacr); |
|
|
|
var select = go.AddComponent<Selectable>(); |
|
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<FiremanController>().InitData(); |
|
|
|
if (data.isShuiGuanCheController) |
|
go.AddComponent<ShuiGuanCheController>().InitData(); |
|
if (data.isGaoPenCheController) |
|
go.AddComponent<GaoPenCheController>().InitData(); |
|
if (data.isDenGaoCheController) |
|
go.AddComponent<DengGaoPingTaiCheController>().InitData(); |
|
if (data.isYunTiCheController) |
|
go.AddComponent<YunTiCheController>().InitData(); |
|
if (data.isZhaoMingCheController) |
|
go.AddComponent<ZhaoMingCheController>().InitData(); |
|
if (data.isAreaController) |
|
go.AddComponent<AreaController>(); |
|
if (data.isWaterMonitorController) |
|
go.AddComponent<WaterMonitorController>().InitData(); |
|
if (data.isLT6Controller) |
|
go.AddComponent<Ladder6Controller>(); |
|
if (data.isLT15Controller) |
|
go.AddComponent<Ladder15Controller>(); |
|
} |
|
|
|
private GameObject FindPower(string key) |
|
{ |
|
//从列中中找出未激活的游戏对象并返回 |
|
return pool.ContainsKey(key) ? pool[key] : null; |
|
} |
|
}
|
|
|