71 lines
2.3 KiB
C#
71 lines
2.3 KiB
C#
using System.Collections.Generic;
|
|
using Continentis.MainGame.Character;
|
|
using NaughtyAttributes;
|
|
using SLSUtilities.UModAssistance;
|
|
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
|
|
namespace Continentis.MainGame.UI
|
|
{
|
|
public class HUDContainer : MonoBehaviour
|
|
{
|
|
//预先保存的HUD信息
|
|
private Dictionary<string, HUDInfo> preservedHudInfos;
|
|
|
|
[Header("Runtime Info")]
|
|
public CombatCharacterViewBase characterView;
|
|
public Dictionary<string, HUDElementBase> enablingHUDs;
|
|
|
|
public void Initialize(CombatCharacterViewBase characterView)
|
|
{
|
|
this.characterView = characterView;
|
|
this.characterView.hudContainer = this;
|
|
this.enablingHUDs = new Dictionary<string, HUDElementBase>();
|
|
this.preservedHudInfos = new Dictionary<string, HUDInfo>();
|
|
|
|
foreach (string hudDataRef in this.characterView.character.data.hudDataRefs)
|
|
{
|
|
HUDData hudData = ModManager.GetData<HUDData>(hudDataRef);
|
|
foreach (KeyValuePair<string, HUDInfo> hudInfo in hudData.hudInfos)
|
|
{
|
|
preservedHudInfos.TryAdd(hudInfo.Key, hudInfo.Value);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void EnableHUD(string hudName)
|
|
{
|
|
if (preservedHudInfos.TryGetValue(hudName, out HUDInfo hudInfo))
|
|
{
|
|
if (!enablingHUDs.ContainsKey(hudName))
|
|
{
|
|
var hud = hudInfo.GenerateHUD(characterView, this);
|
|
hud.OnEnableHud();
|
|
enablingHUDs[hudName] = hud;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"HUD Info for {hudName} not found in character's HUD data.");
|
|
}
|
|
}
|
|
|
|
public void DisableHUD(string hudName)
|
|
{
|
|
if (enablingHUDs.TryGetValue(hudName, out HUDElementBase hud))
|
|
{
|
|
hud.OnDisableHud();
|
|
Destroy(hud.gameObject);
|
|
enablingHUDs.Remove(hudName);
|
|
}
|
|
}
|
|
|
|
public void UpdateAllHUD()
|
|
{
|
|
foreach (KeyValuePair<string, HUDElementBase> hud in enablingHUDs)
|
|
{
|
|
hud.Value.UpdateHud();
|
|
}
|
|
}
|
|
}
|
|
} |