This commit is contained in:
2026-03-27 15:18:35 +08:00
parent a6a1847d8b
commit 2396a75504
1227 changed files with 79169 additions and 170265 deletions
@@ -1,57 +1,81 @@
using Newtonsoft.Json;
using Spine.Unity;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using static UnityEngine.AddressableAssets.Addressables;
[Serializable]
public class FishResourcesData
{
public int fishNumber;
public string prefabFishResourcesPath;
const string prefabFish_AAGroup="FishPrefab";
public string dieEffectAssets;
const string prefabFish_AALabel="FishPrefab";
const string dieSpine_AALabel = "DieSpine";
private static Dictionary<string,string> FishResourcesDatas ;
private static Dictionary<string,int> FishResourcesPrefabsDic ;//prefabpath--id
private static Dictionary<string,int> FishResourcesSpineDieDic ;//dieSpinepath--id
static FishResourcesData()
{
string prefabFishPath = Resources.Load<TextAsset>("tbfishresources").text;
var v = JsonConvert.DeserializeObject<List<FishResourcesData>>(prefabFishPath);
FishResourcesDatas=new Dictionary<string, string>();
FishResourcesPrefabsDic=new Dictionary<string, int>();
fishResourcesDatasDic = new Dictionary<int, FishResourcesData>();
FishResourcesSpineDieDic = new Dictionary<string, int>();
foreach (var item in v)
{
if (item.prefabFishResourcesPath!=null&& item.prefabFishResourcesPath != "")
{
Debug.Log($"添加鱼资源数据: {item.fishNumber} - {item.prefabFishResourcesPath}");
FishResourcesDatas.Add(item.prefabFishResourcesPath, item.fishNumber.ToString());
FishResourcesPrefabsDic.Add(item.prefabFishResourcesPath, item.fishNumber);
if (item.dieEffectAssets!=null&&item.dieEffectAssets!="")
{
FishResourcesSpineDieDic.Add(item.dieEffectAssets, item.fishNumber);
}
fishResourcesDatasDic.Add(item.fishNumber, item);
}
}
LoadFishPrefabs();
}
private static Dictionary<string, GameObject> fishPrefabDic;
private static Dictionary<int, GameObject> fishPrefabDic;//id--prefabs
public static Dictionary<int, FishResourcesData> fishResourcesDatasDic;//id--FishResourcesData
private static Dictionary<int, SkeletonDataAsset> diePrefabDic;//id--SkeletonDataAsset
public static async void LoadFishPrefabs()
public static async void LoadFishAssetsData()
{
if (fishPrefabDic != null)
return;
fishPrefabDic = new Dictionary<string, GameObject>();
fishPrefabDic = new Dictionary<int, GameObject>();
diePrefabDic= new Dictionary<int, SkeletonDataAsset>();
await Addressables.LoadAssetsAsync<GameObject>(prefabFish_AAGroup, prefab =>
var keys = new List<string> { prefabFish_AALabel, GameManager.Instance.gameData.currGameType.ToString() };
await Addressables.LoadAssetsAsync<GameObject>(keys, prefab =>
{
if (FishResourcesDatas.ContainsKey(prefab.name))
if (FishResourcesPrefabsDic.ContainsKey(prefab.name))
{
fishPrefabDic.Add(FishResourcesDatas[prefab.name], prefab);
prefab.GetComponent<MonsterContral>().fishTypeID = FishResourcesDatas[prefab.name].ToString();
fishPrefabDic.Add(FishResourcesPrefabsDic[prefab.name], prefab);
prefab.GetComponent<MonsterContral>().fishTypeID = FishResourcesPrefabsDic[prefab.name].ToString();
}
}).Task;
}, MergeMode.Intersection).Task;
keys = new List<string> {dieSpine_AALabel,/* GameManager.Instance.gameData.currGameType.ToString()*/"XJMH" };
await Addressables.LoadAssetsAsync<SkeletonDataAsset>(keys, data =>
{
if (FishResourcesSpineDieDic.ContainsKey(data.name))
{
diePrefabDic.Add(FishResourcesSpineDieDic[data.name], data); }
},MergeMode.Intersection).Task;
Debug.Log($"加载完成,共 {fishPrefabDic.Count} 个鱼Prefab");
}
public static GameObject GetFishPrefab(string fishNumber)
public static GameObject GetFishPrefab(int fishNumber)
{
if (fishPrefabDic != null && fishPrefabDic.ContainsKey(fishNumber))
{
@@ -63,5 +87,17 @@ public class FishResourcesData
return null;
}
}
public static SkeletonDataAsset GetFishDieSpine(int fishNumber)
{
if (diePrefabDic != null && diePrefabDic.ContainsKey(fishNumber))
{
return diePrefabDic[fishNumber];
}
else
{
Debug.LogError($"鱼死亡动效未找到: {fishNumber}");
return null;
}
}
}