上海虹口龙之梦项目
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.
 
 
 
 

285 lines
9.6 KiB

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<AssetManager>
{
public static List<string> SourceInfos = new List<string>();
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<GameObject> Icons = new List<GameObject>();
//设备列表
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<FloorController> Floors = new List<FloorController>();
//高亮
public HighlightPlus.HighlightProfile highlightProfile;
//态势标绘特效
public List<GameObject> powerEffacts = new List<GameObject>();
//态势标绘顶部信息
public GameObject powerInfo;
//态势标绘喷水特效
public GameObject hose;
//周边水源、行车路线信息
public GameObject annotationInfo;
public GameObject LoadingPanel;
public List<GameObject> characters = new List<GameObject>();
public GameObject yBot;
private void Awake()
{
MainCamera = Camera.main.gameObject;
if (windZone == null)
{
windZone = new GameObject().AddComponent<WindZone>();
windZone.transform.parent = transform;
windZone.name = "WindZone";
}
//获取模型旋转角度
HttpManager.Instance.Get<InitialAngele>(HttpManager.Instance.GetInitialAnge, data => InitialAngle = data.Angle);
//获取设备列表
HttpManager.Instance.Get<Devices>(HttpManager.Instance.GetDeiveceList, data => DeviceList = data);
}
private void Start()
{
UIManager.Instance.Show<MainButtonsPanel>();
UIManager.Instance.Show<CompassPanel>();
UIManager.Instance.Show<FloorButtonsPanel>();
LoadAssets();
ShiNei = new GameObject("ShiNei");
ShiNei.transform.parent = transform;
}
public void SetLoadingPanel(bool value)
{
LoadingPanel.SetActive(value);
}
private void LoadAssets()
{
Addressables.LoadAssetsAsync<GameObject>("Character", null).Completed += handle => { characters = handle.Result.ToList(); };
Addressables.LoadAssetAsync<GameObject>("YBot").Completed += handle => { yBot = handle.Result; };
//加载天空盒
Addressables.InstantiateAsync("SkyController").Completed += SkyHandle;
if (!IsLocalBuildingsData)
{
//外观
Addressables.LoadAssetsAsync<GameObject>("ZhuTi", null).Completed += ZhuTiHandle;
//室内
//Addressables.LoadAssetsAsync<GameObject>("ShiNei", null).Completed += ShiNeiHandle;
//场景
Addressables.LoadAssetsAsync<GameObject>("Scene", null).Completed += SceneHandle;
//透明建筑
//Addressables.InstantiateAsync("Transparent").Completed += TransparentHandle;
}
//加载高度和毗邻资源
Addressables.LoadAssetsAsync<GameObject>("Prop", null).Completed += PropHandle;
//加载默认资源
Addressables.LoadAssetsAsync<GameObject>("default", null).Completed += DefaultAssetsHandle;
//图片展示面板默认图片
Addressables.LoadAssetAsync<Sprite>("DefualtSprite").Completed += DefaultSpriteHandle;
//设备图标
Addressables.LoadAssetsAsync<GameObject>("Icon", null).Completed += IconsHandle;
//态势标绘图标
Addressables.LoadAssetAsync<SpriteAtlas>("Powers").Completed += PowerAtlasHandle;
//态势标绘粒子特效
Addressables.LoadAssetsAsync<GameObject>("power", null).Completed += PowerHandle;
//态势标绘信息
Addressables.LoadAssetAsync<GameObject>("PowerInfo").Completed += PowerInfoHandle;
//态势标绘水流
Addressables.LoadAssetAsync<GameObject>("Hose").Completed += HoseHandle;
//行车路线周边水源信息
Addressables.LoadAssetAsync<GameObject>("AnnotationInfo").Completed += AnnotationInfoHandle;
}
/// <summary>
/// 获取透明建筑
/// </summary>
public void GetTransparent()
{
SetLoadingPanel(true);
Addressables.InstantiateAsync("Transparent").Completed += TransparentHandle;
}
#region Private Funtions
private void AnnotationInfoHandle(AsyncOperationHandle<GameObject> obj)
{
annotationInfo = obj.Result;
}
private void HoseHandle(AsyncOperationHandle<GameObject> obj)
{
hose = obj.Result;
}
private void PowerInfoHandle(AsyncOperationHandle<GameObject> obj)
{
powerInfo = obj.Result;
}
private void PowerHandle(AsyncOperationHandle<IList<GameObject>> obj)
{
powerEffacts = obj.Result as List<GameObject>;
}
private void SkyHandle(AsyncOperationHandle<GameObject> obj)
{
var sky = obj.Result;
sky.name = "SkyController";
sky.transform.parent = transform;
//显示工具架
UIManager.Instance.Show<ToolBarPanel>();
}
/// <summary>
/// 加载态势标绘图标
/// </summary>
/// <param name="obj"></param>
private void PowerAtlasHandle(AsyncOperationHandle<SpriteAtlas> obj)
{
PowerAtlas = obj.Result;
}
/// <summary>
/// 加载高度和毗邻资源
/// </summary>
/// <param name="obj"></param>
private void PropHandle(AsyncOperationHandle<IList<GameObject>> 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;
}
}
/// <summary>
/// 加载默认图片
/// </summary>
/// <param name="obj"></param>
private void DefaultSpriteHandle(AsyncOperationHandle<Sprite> obj)
{
DefaultSprite = obj.Result;
}
/// <summary>
/// 加载设备图标
/// </summary>
/// <param name="obj"></param>
private void IconsHandle(AsyncOperationHandle<IList<GameObject>> obj)
{
Icons = obj.Result as List<GameObject>;
}
/// <summary>
/// 加载场景
/// </summary>
/// <param name="obj"></param>
private void SceneHandle(AsyncOperationHandle<IList<GameObject>> obj)
{
GameObject sc = new GameObject() { name = "Scene" };
sc.transform.parent = transform;
SpawnBuildings(obj, sc.transform, false);
}
/// <summary>
/// 加载室内模型
/// </summary>
/// <param name="obj"></param>
//private void ShiNeiHandle(AsyncOperationHandle<IList<GameObject>> obj)
//{
// GameObject shinei = new GameObject() { name = "ShiNei" };
// shinei.transform.parent = transform;
// ShiNei = shinei;
// SpawnBuildings(obj, shinei.transform, true);
//}
/// <summary>
/// 加载主体模型
/// </summary>
/// <param name="obj"></param>
private void ZhuTiHandle(AsyncOperationHandle<IList<GameObject>> obj)
{
GameObject zhuti = new GameObject() { name = "ZhuTi" };
zhuti.transform.parent = transform;
ZhuTi = zhuti;
SpawnBuildings(obj, zhuti.transform, false);
}
/// <summary>
/// 加载透明建筑
/// </summary>
/// <param name="obj"></param>
private void TransparentHandle(AsyncOperationHandle<GameObject> obj)
{
Transparent = obj.Result;
Transparent.name = "Transparent";
Transparent.transform.parent = transform;
SetLoadingPanel(false);
}
/// <summary>
/// 加载默认资源
/// </summary>
/// <param name="obj"></param>
private void DefaultAssetsHandle(AsyncOperationHandle<IList<GameObject>> obj)
{
var list = obj.Result as List<GameObject>;
//平面图相机
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<IList<GameObject>> 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;
}
}
}