Files
ichni_Official/Packages/NB_FX/XuanXuanRenderUtility/Editor/ShaderGUIItems/ToggleItem.cs
SoulliesOfficial 40fa80cd70 NB_FX
2026-07-17 17:46:16 -04:00

59 lines
1.7 KiB
C#

using System;
using UnityEditor;
using UnityEngine;
namespace NBShaderEditor
{
public class ToggleItem : ShaderGUIItem
{
private readonly Func<GUIContent> _contentProvider;
private readonly Func<bool> _isVisible;
private readonly Action<bool> _onValueChanged;
public ToggleItem(
ShaderGUIRootItem rootItem,
ShaderGUIItem parentItem,
string propertyName,
Func<GUIContent> contentProvider,
Action<bool> onValueChanged = null,
Func<bool> isVisible = null) : base(rootItem, parentItem)
{
PropertyName = propertyName;
_contentProvider = contentProvider ?? (() => GUIContent.none);
_onValueChanged = onValueChanged;
_isVisible = isVisible;
GuiContent = _contentProvider();
InitTriggerByChild();
}
public override void OnGUI()
{
if (_isVisible != null && !_isVisible())
{
return;
}
base.OnGUI();
}
public override void DrawController()
{
bool value = PropertyInfo.Property.floatValue > 0.5f;
value = EditorGUI.Toggle(ControlRect, value);
SetFloatIfDifferent(PropertyInfo.Property, value ? 1f : 0f);
}
public override void OnEndChange()
{
base.OnEndChange();
_onValueChanged?.Invoke(PropertyInfo.Property.floatValue > 0.5f);
}
public override void ExecuteReset(bool isCallByParent = false)
{
base.ExecuteReset(isCallByParent);
_onValueChanged?.Invoke(PropertyInfo.Property.floatValue > 0.5f);
}
}
}