您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
84 行
2.5 KiB
84 行
2.5 KiB
using System.Collections.Generic;
|
|
using UnityEditor.ShaderGraph.Drawing.Controls;
|
|
using UnityEngine;
|
|
using UnityEditor.Graphing;
|
|
|
|
namespace UnityEditor.ShaderGraph
|
|
{
|
|
[Title("Input", "Basic", "Boolean")]
|
|
public class BooleanNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
|
|
{
|
|
[SerializeField]
|
|
private bool m_Value;
|
|
|
|
public const int OutputSlotId = 0;
|
|
private const string kOutputSlotName = "Out";
|
|
|
|
public BooleanNode()
|
|
{
|
|
name = "Boolean";
|
|
UpdateNodeAfterDeserialization();
|
|
}
|
|
|
|
public sealed override void UpdateNodeAfterDeserialization()
|
|
{
|
|
AddSlot(new BooleanMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, false));
|
|
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
|
|
}
|
|
|
|
[ToggleControl("")]
|
|
public Toggle value
|
|
{
|
|
get { return new Toggle(m_Value); }
|
|
set
|
|
{
|
|
if (m_Value == value.isOn)
|
|
return;
|
|
m_Value = value.isOn;
|
|
Dirty(ModificationScope.Node);
|
|
}
|
|
}
|
|
|
|
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
|
|
{
|
|
if (!generationMode.IsPreview())
|
|
return;
|
|
|
|
properties.AddShaderProperty(new BooleanShaderProperty()
|
|
{
|
|
overrideReferenceName = GetVariableNameForNode(),
|
|
generatePropertyBlock = false,
|
|
value = m_Value
|
|
});
|
|
}
|
|
|
|
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
|
|
{
|
|
if (generationMode.IsPreview())
|
|
return;
|
|
|
|
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + (m_Value ? 1 : 0) + ";", true);
|
|
}
|
|
|
|
public override string GetVariableNameForSlot(int slotId)
|
|
{
|
|
return GetVariableNameForNode();
|
|
}
|
|
|
|
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
|
|
{
|
|
properties.Add(new PreviewProperty(PropertyType.Boolean)
|
|
{
|
|
name = GetVariableNameForNode(),
|
|
booleanValue = m_Value
|
|
});
|
|
}
|
|
|
|
public IShaderProperty AsShaderProperty()
|
|
{
|
|
return new BooleanShaderProperty { value = m_Value };
|
|
}
|
|
|
|
public int outputSlotId { get { return OutputSlotId; } }
|
|
}
|
|
}
|