A game about forced loneliness, made by TACStudios
1using System;
2using System.Collections.Generic;
3using UnityEditor.Graphing;
4using UnityEditor.ShaderGraph.Drawing.Slots;
5using UnityEditor.ShaderGraph.Internal;
6using UnityEngine;
7
8using UnityEngine.UIElements;
9
10namespace UnityEditor.ShaderGraph
11{
12 [Serializable]
13 class BooleanMaterialSlot : MaterialSlot, IMaterialSlotHasValue<bool>
14 {
15 [SerializeField]
16 private bool m_Value;
17
18 [SerializeField]
19 private bool m_DefaultValue;
20
21 public BooleanMaterialSlot()
22 { }
23
24 public BooleanMaterialSlot(
25 int slotId,
26 string displayName,
27 string shaderOutputName,
28 SlotType slotType,
29 bool value,
30 ShaderStageCapability stageCapability = ShaderStageCapability.All,
31 bool hidden = false)
32 : base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
33 {
34 m_DefaultValue = value;
35 m_Value = value;
36 }
37
38 public override VisualElement InstantiateControl()
39 {
40 return new BooleanSlotControlView(this);
41 }
42
43 public bool defaultValue { get { return m_DefaultValue; } }
44
45 public bool value
46 {
47 get { return m_Value; }
48 set { m_Value = value; }
49 }
50
51 public override bool isDefaultValue => value.Equals(defaultValue);
52
53 protected override string ConcreteSlotValueAsVariable()
54 {
55 return (value ? 1 : 0).ToString();
56 }
57
58 public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
59 {
60 if (!generationMode.IsPreview())
61 return;
62
63 var matOwner = owner as AbstractMaterialNode;
64 if (matOwner == null)
65 throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
66
67 var property = new BooleanShaderProperty()
68 {
69 overrideReferenceName = matOwner.GetVariableNameForSlot(id),
70 generatePropertyBlock = false,
71 value = value
72 };
73 properties.AddShaderProperty(property);
74 }
75
76 public override SlotValueType valueType { get { return SlotValueType.Boolean; } }
77 public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Boolean; } }
78
79 public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
80 {
81 var pp = new PreviewProperty(PropertyType.Boolean)
82 {
83 name = name,
84 booleanValue = value
85 };
86 properties.Add(pp);
87 }
88
89 public override void CopyValuesFrom(MaterialSlot foundSlot)
90 {
91 var slot = foundSlot as BooleanMaterialSlot;
92 if (slot != null)
93 value = slot.value;
94 }
95
96 public override void CopyDefaultValue(MaterialSlot other)
97 {
98 base.CopyDefaultValue(other);
99 if (other is IMaterialSlotHasValue<bool> ms)
100 {
101 m_DefaultValue = ms.defaultValue;
102 }
103 }
104 }
105}