记录副本更新ui
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
[Serializable]
|
||||
public class FishResourcesData
|
||||
{
|
||||
public int fishNumber;
|
||||
public string prefabFishResourcesPath;
|
||||
const string prefabFish_AAGroup="FishPrefab";
|
||||
|
||||
|
||||
private static Dictionary<string,string> FishResourcesDatas ;
|
||||
static FishResourcesData()
|
||||
{
|
||||
string prefabFishPath = Resources.Load<TextAsset>("tbfishresources").text;
|
||||
var v = JsonConvert.DeserializeObject<List<FishResourcesData>>(prefabFishPath);
|
||||
FishResourcesDatas=new Dictionary<string, string>();
|
||||
foreach (var item in v)
|
||||
{
|
||||
if (item.prefabFishResourcesPath!=null&& item.prefabFishResourcesPath != "")
|
||||
{
|
||||
Debug.Log($"添加鱼资源数据: {item.fishNumber} - {item.prefabFishResourcesPath}");
|
||||
FishResourcesDatas.Add(item.prefabFishResourcesPath, item.fishNumber.ToString());
|
||||
|
||||
}
|
||||
}
|
||||
LoadFishPrefabs();
|
||||
}
|
||||
|
||||
private static Dictionary<string, GameObject> fishPrefabDic;
|
||||
|
||||
public static async void LoadFishPrefabs()
|
||||
{
|
||||
if (fishPrefabDic != null)
|
||||
return;
|
||||
|
||||
fishPrefabDic = new Dictionary<string, GameObject>();
|
||||
|
||||
await Addressables.LoadAssetsAsync<GameObject>(prefabFish_AAGroup, prefab =>
|
||||
{
|
||||
if (FishResourcesDatas.ContainsKey(prefab.name))
|
||||
{
|
||||
fishPrefabDic.Add(FishResourcesDatas[prefab.name], prefab);
|
||||
}
|
||||
}).Task;
|
||||
|
||||
Debug.Log($"加载完成,共 {fishPrefabDic.Count} 个鱼Prefab");
|
||||
}
|
||||
public static GameObject GetFishPrefab(string fishNumber)
|
||||
{
|
||||
if (fishPrefabDic != null && fishPrefabDic.ContainsKey(fishNumber))
|
||||
{
|
||||
return fishPrefabDic[fishNumber];
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"鱼Prefab未找到: {fishNumber}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user