86 lines
2.0 KiB
C#
86 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Superlazy.UI
|
|
{
|
|
[DisallowMultipleComponent]
|
|
[RequireComponent(typeof(Canvas))]
|
|
public class SLUICanvas : SLUIObjectOnOff
|
|
{
|
|
protected override bool ActiveSelf => !useOnOff || comparison.Result;
|
|
|
|
public string bindCamera;
|
|
public bool useOnOff;
|
|
public SLValueComparison comparison;
|
|
|
|
private Canvas canvas;
|
|
private List<GameObject> childs;
|
|
private bool oldResult;
|
|
|
|
protected override void Validate()
|
|
{
|
|
canvas = GetComponent<Canvas>();
|
|
}
|
|
|
|
protected override void Init()
|
|
{
|
|
childs = new List<GameObject>();
|
|
for (var i = 0; i < transform.childCount; ++i)
|
|
{
|
|
childs.Add(transform.GetChild(i).gameObject);
|
|
}
|
|
|
|
if (useOnOff)
|
|
{
|
|
oldResult = false;
|
|
|
|
foreach (var child in childs)
|
|
{
|
|
child.SetActive(false);
|
|
}
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(bindCamera) == false)
|
|
{
|
|
canvas.worldCamera = GameObject.Find(bindCamera).GetComponent<Camera>();
|
|
}
|
|
}
|
|
|
|
protected override void Enable()
|
|
{
|
|
if (useOnOff == false)
|
|
{
|
|
}
|
|
|
|
comparison.OnEnable(BindPath, OnChange);
|
|
}
|
|
|
|
protected override void Disable()
|
|
{
|
|
if (useOnOff == false) return;
|
|
|
|
comparison.OnDisable();
|
|
|
|
UpdateEnabled(false);
|
|
}
|
|
|
|
private void UpdateEnabled(bool result)
|
|
{
|
|
oldResult = result;
|
|
|
|
foreach (var child in childs)
|
|
{
|
|
child.SetActive(result);
|
|
}
|
|
}
|
|
|
|
private void OnChange()
|
|
{
|
|
var result = comparison.Result;
|
|
|
|
if (oldResult == result) return;
|
|
|
|
UpdateEnabled(result);
|
|
}
|
|
}
|
|
} |