85 lines
2.4 KiB
C#
85 lines
2.4 KiB
C#
using cfg.CampCfg;
|
|
using Cysharp.Threading.Tasks;
|
|
using Framework;
|
|
using Gameplay.Common;
|
|
using PhxhSDK;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Gameplay.Camp
|
|
{
|
|
public sealed partial class Camp
|
|
{
|
|
/// <summary>
|
|
/// 记录加载的数据
|
|
/// </summary>
|
|
private HashSet<string> setLoad;
|
|
|
|
private void InitLoad()
|
|
{
|
|
setLoad = new();
|
|
}
|
|
|
|
private void ExitLoad()
|
|
{
|
|
foreach (string path in setLoad)
|
|
{
|
|
AssetManager.Instance.Unload(path);
|
|
}
|
|
setLoad.Clear();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载所有营地单位
|
|
/// </summary>
|
|
public async UniTask SetInfoByLoad()
|
|
{
|
|
// TODO从服务器取得数据
|
|
|
|
int[] listCellIndex = new int[] { 60, 277 }; // 测试数据
|
|
int[] listCampItemId = new int[] { 100005, 100004 };
|
|
|
|
for (int i = 0; i < listCellIndex.Length; ++i)
|
|
{
|
|
await LoadBuilding(listCampItemId[i], listCellIndex[i]);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载建筑
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async UniTask LoadBuilding(int id, int cellIndex)
|
|
{
|
|
DataCampObject dataCampObject = TableManager.Instance.Tables.CampObjectConfig.Get(id);
|
|
if (null == dataCampObject)
|
|
return;
|
|
|
|
if (!CheckPlace(cellIndex, dataCampObject.ListPosOffset)) // 检查能否放置
|
|
return;
|
|
|
|
GameObject goCampObject = await LoadCampObject(dataCampObject.Path);
|
|
BuildingCampUnit buildingCampUnit = new(goCampObject, dataCampObject)
|
|
{
|
|
CellIndex = cellIndex
|
|
};
|
|
PlaceCampItem(buildingCampUnit);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载物件
|
|
/// </summary>
|
|
public async UniTask<GameObject> LoadCampObject(string path)
|
|
{
|
|
GameObject goCampObject = await AssetManager.Instance.LoadAssetAsync<GameObject>(path);
|
|
if (null == goCampObject)
|
|
return null;
|
|
|
|
setLoad.Add(path);
|
|
GameObject go = Object.Instantiate(goCampObject, tsCampObjectRoot);
|
|
go.SetLayerEx(LayerDefine.UIView);
|
|
return go;
|
|
}
|
|
}
|
|
} |