r2mods/ilspy_dump/ror2_csproj/HideIfSurvivorLocked.cs

54 lines
1.3 KiB
C#
Raw Normal View History

2024-10-04 07:26:37 +00:00
using System.Linq;
using RoR2;
using RoR2.EntitlementManagement;
using UnityEngine;
public class HideIfSurvivorLocked : MonoBehaviour
{
[Tooltip("Survivor Def(s) that must be unlocked in order to show this component's gameObject. (ANY)")]
public SurvivorDef[] requiredSurvivors;
[Tooltip("Indicator to show that none of the designated survivors are unlocked.")]
public GameObject lockedIndicator;
private void Awake()
{
EntitlementManager.onEntitlementsUpdated += Reset;
Reset();
}
private void OnDestroy()
{
EntitlementManager.onEntitlementsUpdated -= Reset;
}
private void Reset()
{
if (requiredSurvivors.Length != 0)
{
if (requiredSurvivors.Any((SurvivorDef survivorDef) => SurvivorCatalog.SurvivorIsUnlockedOnThisClient(survivorDef.survivorIndex) && survivorDef.CheckLocalUserHasRequiredEntitlement()))
{
base.gameObject.SetActive(value: true);
SetLockIndicator(value: false);
}
else
{
base.gameObject.SetActive(value: false);
SetLockIndicator(value: true);
}
}
else
{
Debug.LogWarning("No designated requiredSurvivors or lockedIndicator on HideIfSurvivorLocked. Consider updating or removing this component on gameObject:" + base.gameObject.name + ".");
}
}
private void SetLockIndicator(bool value)
{
if (lockedIndicator != null)
{
lockedIndicator.SetActive(value);
}
}
}