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;
7using UnityEngine.UIElements;
8
9
10namespace UnityEditor.ShaderGraph
11{
12 [Serializable]
13 class GradientInputMaterialSlot : GradientMaterialSlot, IMaterialSlotHasValue<Gradient>
14 {
15 [SerializeField]
16 Gradient m_Value = new Gradient();
17
18 [SerializeField]
19 Gradient m_DefaultValue = new Gradient();
20
21 public GradientInputMaterialSlot()
22 {
23 }
24
25 public GradientInputMaterialSlot(
26 int slotId,
27 string displayName,
28 string shaderOutputName,
29 ShaderStageCapability stageCapability = ShaderStageCapability.All,
30 bool hidden = false)
31 : base(slotId, displayName, shaderOutputName, SlotType.Input, stageCapability, hidden)
32 {
33 }
34
35 public Gradient value
36 {
37 get { return m_Value; }
38 set { m_Value = value; }
39 }
40
41 public Gradient defaultValue { get { return m_DefaultValue; } }
42
43 public override bool isDefaultValue => value.Equals(defaultValue);
44
45 public override VisualElement InstantiateControl()
46 {
47 return new GradientSlotControlView(this);
48 }
49
50 public override string GetDefaultValue(GenerationMode generationMode)
51 {
52 var matOwner = owner as AbstractMaterialNode;
53 if (matOwner == null)
54 throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
55
56 if (generationMode.IsPreview())
57 return GradientUtil.GetGradientForPreview(matOwner.GetVariableNameForSlot(id));
58
59 return ConcreteSlotValueAsVariable();
60 }
61
62 protected override string ConcreteSlotValueAsVariable()
63 {
64 return GradientUtil.GetGradientValue(value, "");
65 }
66
67 public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
68 {
69 var matOwner = owner as AbstractMaterialNode;
70 if (matOwner == null)
71 throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
72
73 if (generationMode != GenerationMode.Preview)
74 return;
75
76 GradientUtil.GetGradientPropertiesForPreview(properties, matOwner.GetVariableNameForSlot(id), value);
77 }
78
79 public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
80 {
81 properties.Add(new PreviewProperty(PropertyType.Gradient)
82 {
83 name = name,
84 gradientValue = value
85 });
86 }
87
88 public override void CopyValuesFrom(MaterialSlot foundSlot)
89 {
90 var slot = foundSlot as GradientInputMaterialSlot;
91 if (slot != null)
92 value = slot.value;
93 }
94 }
95}