A game about forced loneliness, made by TACStudios
1using System.Collections.Generic;
2using UnityEditor.ShaderGraph.Drawing.Controls;
3using UnityEngine;
4using UnityEditor.Graphing;
5using UnityEditor.ShaderGraph.Internal;
6
7namespace UnityEditor.ShaderGraph
8{
9 [Title("Input", "Basic", "Boolean")]
10 class BooleanNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
11 {
12 [SerializeField]
13 internal bool m_Value;
14
15 public const int OutputSlotId = 0;
16 private const string kOutputSlotName = "Out";
17
18 public BooleanNode()
19 {
20 name = "Boolean";
21 synonyms = new string[] { "switch", "true", "false", "on", "off" };
22 UpdateNodeAfterDeserialization();
23 }
24
25 public sealed override void UpdateNodeAfterDeserialization()
26 {
27 AddSlot(new BooleanMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, false));
28 RemoveSlotsNameNotMatching(new[] { OutputSlotId });
29 }
30
31 [ToggleControl("")]
32 public ToggleData value
33 {
34 get { return new ToggleData(m_Value); }
35 set
36 {
37 if (m_Value == value.isOn)
38 return;
39 m_Value = value.isOn;
40 Dirty(ModificationScope.Node);
41 }
42 }
43
44 public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
45 {
46 if (!generationMode.IsPreview())
47 return;
48
49 properties.AddShaderProperty(new BooleanShaderProperty()
50 {
51 overrideReferenceName = GetVariableNameForNode(),
52 generatePropertyBlock = false,
53 value = m_Value
54 });
55 }
56
57 public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
58 {
59 if (generationMode.IsPreview())
60 return;
61
62 sb.AppendLine("$precision {0} = {1};", GetVariableNameForNode(), (m_Value ? 1 : 0));
63 }
64
65 public override string GetVariableNameForSlot(int slotId)
66 {
67 return GetVariableNameForNode();
68 }
69
70 public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
71 {
72 properties.Add(new PreviewProperty(PropertyType.Boolean)
73 {
74 name = GetVariableNameForNode(),
75 booleanValue = m_Value
76 });
77 }
78
79 public AbstractShaderProperty AsShaderProperty()
80 {
81 return new BooleanShaderProperty { value = m_Value };
82 }
83
84 public int outputSlotId { get { return OutputSlotId; } }
85 }
86}