Hidden Skills
using Esper.SkillWeb.UI;
using Esper.SkillWeb.UI.UGUI;
using UnityEngine;
public class LockedSkillHider : MonoBehaviour
{
private void Awake()
{
// Update hidden states skills when a web is loaded
RuntimeWebViewer.onLoadCompleted.AddListener(webView =>
{
UpdateHiddenSkillStates(webView as WebViewUGUI);
});
// Update the hidden states when any skill state is changed
SkillNodeUGUI.onStateChanged.AddListener(skillNodeUI =>
{
UpdateHiddenSkillStates(skillNodeUI.webView);
});
}
/// <summary>
/// Hides all locked skills while also revealing unlocked skills.
/// </summary>
/// <param name="webView">The target web view.</param>
public void UpdateHiddenSkillStates(WebViewUGUI webView)
{
foreach (var item in webView.loadedSkillNodes)
{
// Activate the skill based on its IsLocked state
var skillNodeUI = item.Value;
bool active = !skillNodeUI.skillNode.IsLocked;
skillNodeUI.gameObject.SetActive(active);
// Grab all connections of the skill
var connections = skillNodeUI.GetConnections();
foreach (var connection in connections)
{
// Disable connections if they're connected to a locked skill
var input = connection.Input;
var output = connection.Output;
bool activeConnection = (!input || !output) || (!input.skillNode.IsLocked && !output.skillNode.IsLocked);
connection.gameObject.SetActive(activeConnection);
}
}
}
}Last updated