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", "Integer")]
10 class IntegerNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
11 {
12 [SerializeField]
13 private int m_Value;
14
15 public const int OutputSlotId = 0;
16 private const string kOutputSlotName = "Out";
17
18 public IntegerNode()
19 {
20 name = "Integer";
21 synonyms = new string[] { "whole number" };
22 UpdateNodeAfterDeserialization();
23 }
24
25 public sealed override void UpdateNodeAfterDeserialization()
26 {
27 AddSlot(new Vector1MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
28 RemoveSlotsNameNotMatching(new[] { OutputSlotId });
29 }
30
31 [IntegerControl("")]
32 public int value
33 {
34 get { return m_Value; }
35 set
36 {
37 if (m_Value == value)
38 return;
39
40 m_Value = value;
41
42 Dirty(ModificationScope.Node);
43 }
44 }
45
46 public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
47 {
48 if (!generationMode.IsPreview())
49 return;
50
51 properties.AddShaderProperty(new Vector1ShaderProperty()
52 {
53 overrideReferenceName = GetVariableNameForNode(),
54 generatePropertyBlock = false,
55 value = value,
56 floatType = FloatType.Integer
57 });
58 }
59
60 public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
61 {
62 if (generationMode.IsPreview())
63 return;
64
65 sb.AppendLine(string.Format("$precision {0} = {1};", GetVariableNameForNode(), m_Value));
66 }
67
68 public override string GetVariableNameForSlot(int slotId)
69 {
70 return GetVariableNameForNode();
71 }
72
73 public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
74 {
75 properties.Add(new PreviewProperty(PropertyType.Float)
76 {
77 name = GetVariableNameForNode(),
78 floatValue = m_Value
79 });
80 }
81
82 public AbstractShaderProperty AsShaderProperty()
83 {
84 return new Vector1ShaderProperty { value = value, floatType = FloatType.Integer };
85 }
86
87 public int outputSlotId { get { return OutputSlotId; } }
88 }
89}