using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.U2D; public class InitialAngele { public float Angle; } public class AssetManager : MonoSingleton { public static List SourceInfos = new List(); public bool IsLocalBuildingsData; //场景初始旋转角度 [HideInInspector] public float InitialAngle = 0; //主相机 [HideInInspector] public GameObject MainCamera; //平面图相机 [HideInInspector] public GameObject PlaneCamera; //主体 public GameObject ZhuTi; //室内 public GameObject ShiNei; //透明 public GameObject Transparent; //漫游 [HideInInspector] public GameObject RoamingAssets; //默认图片 [HideInInspector] public Sprite DefaultSprite; //图标集 [HideInInspector] public List Icons = new List(); //设备列表 public Devices DeviceList = new Devices(); //WindZone [HideInInspector] public WindZone windZone; //城市代码 [HideInInspector] public string CityCode = "110000"; //实时天气请求地址 [HideInInspector] public string WeatherCallPath = "https://restapi.amap.com/v3/weather/weatherInfo?city="; //天气Key [HideInInspector] public string Key = "3439b43eeadc76070ab66d522158a667"; //态势标绘力量图标 [HideInInspector] public SpriteAtlas PowerAtlas; //楼层按钮 [HideInInspector] public List Floors = new List(); //高亮 public HighlightPlus.HighlightProfile highlightProfile; //态势标绘特效 public List powerEffacts = new List(); //态势标绘顶部信息 public GameObject powerInfo; //态势标绘喷水特效 public GameObject hose; //周边水源、行车路线信息 public GameObject annotationInfo; public GameObject LoadingPanel; public List characters = new List(); public GameObject yBot; private void Awake() { MainCamera = Camera.main.gameObject; if (windZone == null) { windZone = new GameObject().AddComponent(); windZone.transform.parent = transform; windZone.name = "WindZone"; } //获取模型旋转角度 HttpManager.Instance.Get(HttpManager.Instance.GetInitialAnge, data => InitialAngle = data.Angle); //获取设备列表 HttpManager.Instance.Get(HttpManager.Instance.GetDeiveceList, data => DeviceList = data); } private void Start() { UIManager.Instance.Show(); UIManager.Instance.Show(); UIManager.Instance.Show(); LoadAssets(); ShiNei = new GameObject("ShiNei"); ShiNei.transform.parent = transform; } public void SetLoadingPanel(bool value) { LoadingPanel.SetActive(value); } private void LoadAssets() { Addressables.LoadAssetsAsync("Character", null).Completed += handle => { characters = handle.Result.ToList(); }; Addressables.LoadAssetAsync("YBot").Completed += handle => { yBot = handle.Result; }; //加载天空盒 Addressables.InstantiateAsync("SkyController").Completed += SkyHandle; if (!IsLocalBuildingsData) { //外观 Addressables.LoadAssetsAsync("ZhuTi", null).Completed += ZhuTiHandle; //室内 //Addressables.LoadAssetsAsync("ShiNei", null).Completed += ShiNeiHandle; //场景 Addressables.LoadAssetsAsync("Scene", null).Completed += SceneHandle; //透明建筑 //Addressables.InstantiateAsync("Transparent").Completed += TransparentHandle; } //加载高度和毗邻资源 Addressables.LoadAssetsAsync("Prop", null).Completed += PropHandle; //加载默认资源 Addressables.LoadAssetsAsync("default", null).Completed += DefaultAssetsHandle; //图片展示面板默认图片 Addressables.LoadAssetAsync("DefualtSprite").Completed += DefaultSpriteHandle; //设备图标 Addressables.LoadAssetsAsync("Icon", null).Completed += IconsHandle; //态势标绘图标 Addressables.LoadAssetAsync("Powers").Completed += PowerAtlasHandle; //态势标绘粒子特效 Addressables.LoadAssetsAsync("power", null).Completed += PowerHandle; //态势标绘信息 Addressables.LoadAssetAsync("PowerInfo").Completed += PowerInfoHandle; //态势标绘水流 Addressables.LoadAssetAsync("Hose").Completed += HoseHandle; //行车路线周边水源信息 Addressables.LoadAssetAsync("AnnotationInfo").Completed += AnnotationInfoHandle; } /// /// 获取透明建筑 /// public void GetTransparent() { SetLoadingPanel(true); Addressables.InstantiateAsync("Transparent").Completed += TransparentHandle; } #region Private Funtions private void AnnotationInfoHandle(AsyncOperationHandle obj) { annotationInfo = obj.Result; } private void HoseHandle(AsyncOperationHandle obj) { hose = obj.Result; } private void PowerInfoHandle(AsyncOperationHandle obj) { powerInfo = obj.Result; } private void PowerHandle(AsyncOperationHandle> obj) { powerEffacts = obj.Result as List; } private void SkyHandle(AsyncOperationHandle obj) { var sky = obj.Result; sky.name = "SkyController"; sky.transform.parent = transform; //显示工具架 UIManager.Instance.Show(); } /// /// 加载态势标绘图标 /// /// private void PowerAtlasHandle(AsyncOperationHandle obj) { PowerAtlas = obj.Result; } /// /// 加载高度和毗邻资源 /// /// private void PropHandle(AsyncOperationHandle> obj) { for (int i = 0; i < obj.Result.Count; i++) { GameObject go = Instantiate(obj.Result[i]); go.name = go.name.Replace("(Clone)", ""); go.transform.parent = transform; } } /// /// 加载默认图片 /// /// private void DefaultSpriteHandle(AsyncOperationHandle obj) { DefaultSprite = obj.Result; } /// /// 加载设备图标 /// /// private void IconsHandle(AsyncOperationHandle> obj) { Icons = obj.Result as List; } /// /// 加载场景 /// /// private void SceneHandle(AsyncOperationHandle> obj) { GameObject sc = new GameObject() { name = "Scene" }; sc.transform.parent = transform; SpawnBuildings(obj, sc.transform, false); } /// /// 加载室内模型 /// /// //private void ShiNeiHandle(AsyncOperationHandle> obj) //{ // GameObject shinei = new GameObject() { name = "ShiNei" }; // shinei.transform.parent = transform; // ShiNei = shinei; // SpawnBuildings(obj, shinei.transform, true); //} /// /// 加载主体模型 /// /// private void ZhuTiHandle(AsyncOperationHandle> obj) { GameObject zhuti = new GameObject() { name = "ZhuTi" }; zhuti.transform.parent = transform; ZhuTi = zhuti; SpawnBuildings(obj, zhuti.transform, false); } /// /// 加载透明建筑 /// /// private void TransparentHandle(AsyncOperationHandle obj) { Transparent = obj.Result; Transparent.name = "Transparent"; Transparent.transform.parent = transform; SetLoadingPanel(false); } /// /// 加载默认资源 /// /// private void DefaultAssetsHandle(AsyncOperationHandle> obj) { var list = obj.Result as List; //平面图相机 PlaneCamera = Instantiate(list.Find(go => go.name == "PlaneCamera")); PlaneCamera.name = "PlaneCamera"; PlaneCamera.SetActive(false); PlaneCamera.transform.parent = transform; //设备 var EM = Instantiate(list.Find(go => go.name == "EquipmentManager")); EM.name = "EquipmentManager"; EM.transform.parent = transform; //power var PM = Instantiate(list.Find(go => go.name == "PowerManager")); PM.name = "PowerManager"; PM.transform.parent = transform; } #endregion void SpawnBuildings(AsyncOperationHandle> obj, Transform Parent, bool indoor) { for (int i = 0; i < obj.Result.Count; i++) { GameObject go = Instantiate(obj.Result[i]); go.name = go.name.Replace("(Clone)", ""); go.transform.parent = Parent; } } }