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.
110 lines
3.7 KiB
110 lines
3.7 KiB
1 year ago
|
using GLTFast;
|
||
|
using HighlightPlus;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Threading.Tasks;
|
||
|
using UnityEngine;
|
||
|
/// <summary>
|
||
|
/// 周边水源和行车路线标记工具对象池
|
||
|
/// <summary>
|
||
|
public class AnnotationPool : Singleton<AnnotationPool>
|
||
|
{
|
||
|
private Dictionary<string, GameObject> pool = new Dictionary<string, GameObject>();
|
||
|
|
||
|
public async Task<GameObject> 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<GameObject> 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<Transform>())
|
||
|
t.gameObject.layer = LayerMask.NameToLayer("Annotation");
|
||
|
|
||
|
var boxCollider = go.AddComponent<BoxCollider>();
|
||
|
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<SourceController>();
|
||
|
controller.OriginaName = key;
|
||
|
if (key.Contains("LX"))
|
||
|
controller.sourceMode = CreationMode.Multipoint;
|
||
|
else
|
||
|
controller.sourceMode = CreationMode.Single;
|
||
|
go.AddComponent<DragObject>();
|
||
|
|
||
|
var effacr = go.AddComponent<HighlightEffect>();
|
||
|
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<TextMesh>().text = "单位名称";
|
||
|
break;
|
||
|
case "DSXHS":
|
||
|
info.GetComponent<TextMesh>().text = "地上消火栓";
|
||
|
break;
|
||
|
case "DXXHS":
|
||
|
info.GetComponent<TextMesh>().text = "地下消火栓";
|
||
|
break;
|
||
|
case "TRSY":
|
||
|
info.GetComponent<TextMesh>().text = "天然水源";
|
||
|
break;
|
||
|
case "XFSC":
|
||
|
info.GetComponent<TextMesh>().text = "消防水池";
|
||
|
break;
|
||
|
case "XQZD":
|
||
|
info.GetComponent<TextMesh>().text = "辖区中队";
|
||
|
break;
|
||
|
case "ZYZD":
|
||
|
info.GetComponent<TextMesh>().text = "增援中队";
|
||
|
break;
|
||
|
case "XQZDLX":
|
||
|
case "ZYZDLX":
|
||
|
info.GetComponent<TextMesh>().text = "";
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private GameObject FindMarked(string key)
|
||
|
{
|
||
|
//从列中中找出未激活的游戏对象并返回
|
||
|
return pool.ContainsKey(key) ? pool[key] : null;
|
||
|
}
|
||
|
}
|