A game about forced loneliness, made by TACStudios
1using System.Collections.Generic; 2using System.Globalization; 3using UnityEditor.ShaderGraph.Drawing.Controls; 4using UnityEngine; 5using UnityEditor.Graphing; 6 7namespace UnityEditor.ShaderGraph 8{ 9 enum ConstantType 10 { 11 PI, 12 TAU, 13 PHI, 14 E, 15 SQRT2 16 }; 17 18 [Title("Input", "Basic", "Constant")] 19 class ConstantNode : AbstractMaterialNode, IGeneratesBodyCode 20 { 21 static Dictionary<ConstantType, float> m_constantList = new Dictionary<ConstantType, float> 22 { 23 {ConstantType.PI, 3.1415926f }, 24 {ConstantType.TAU, 6.28318530f}, 25 {ConstantType.PHI, 1.618034f}, 26 {ConstantType.E, 2.718282f}, 27 {ConstantType.SQRT2, 1.414214f}, 28 }; 29 30 [SerializeField] 31 private ConstantType m_constant = ConstantType.PI; 32 33 private const int kOutputSlotId = 0; 34 private const string kOutputSlotName = "Out"; 35 36 [EnumControl("")] 37 public ConstantType constant 38 { 39 get { return m_constant; } 40 set 41 { 42 if (m_constant == value) 43 return; 44 45 m_constant = value; 46 Dirty(ModificationScope.Graph); 47 } 48 } 49 50 public ConstantNode() 51 { 52 name = "Constant"; 53 synonyms = new string[] { "pi", "tau", "phi" }; 54 UpdateNodeAfterDeserialization(); 55 } 56 57 public sealed override void UpdateNodeAfterDeserialization() 58 { 59 AddSlot(new Vector1MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0)); 60 RemoveSlotsNameNotMatching(new[] { kOutputSlotId }); 61 } 62 63 public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode) 64 { 65 sb.AppendLine(string.Format("$precision {0} = {1};" 66 , GetVariableNameForNode() 67 , m_constantList[constant].ToString(CultureInfo.InvariantCulture))); 68 } 69 70 public override string GetVariableNameForSlot(int slotId) 71 { 72 return GetVariableNameForNode(); 73 } 74 } 75}