A game about forced loneliness, made by TACStudios
1using System;
2using UnityEditor.Graphing;
3using UnityEditor.ShaderGraph.Internal;
4using UnityEngine;
5
6namespace UnityEditor.ShaderGraph
7{
8 [BlackboardInputInfo(80)]
9 class SamplerStateShaderProperty : AbstractShaderProperty<TextureSamplerState>
10 {
11 public SamplerStateShaderProperty()
12 {
13 displayName = "SamplerState";
14 value = new TextureSamplerState();
15 }
16
17 public override PropertyType propertyType => PropertyType.SamplerState;
18
19 // Sampler States cannot be exposed on a Material
20 internal override bool isExposable => false;
21
22 // subgraph Sampler States can be renamed
23 // just the actual properties they create will always have fixed names
24 internal override bool isRenamable => true;
25
26 internal override bool isReferenceRenamable => false;
27
28 // this is the fixed naming scheme for actual samplerstates properties
29 string propertyReferenceName => value.defaultPropertyName;
30 public override string referenceNameForEditing => propertyReferenceName;
31
32 internal override bool AllowHLSLDeclaration(HLSLDeclaration decl) => false; // disable UI, nothing to choose
33
34 internal override void ForeachHLSLProperty(Action<HLSLProperty> action)
35 {
36 action(new HLSLProperty(HLSLType._SamplerState, propertyReferenceName, HLSLDeclaration.Global));
37 }
38
39 internal override string GetPropertyAsArgumentString(string precisionString)
40 {
41 return $"UnitySamplerState {referenceName}";
42 }
43
44 internal override string GetHLSLVariableName(bool isSubgraphProperty, GenerationMode mode)
45 {
46 if (isSubgraphProperty)
47 return referenceName;
48 else
49 return $"UnityBuildSamplerStateStruct({propertyReferenceName})";
50 }
51
52 internal override AbstractMaterialNode ToConcreteNode()
53 {
54 return new SamplerStateNode()
55 {
56 filter = value.filter,
57 wrap = value.wrap
58 };
59 }
60
61 internal override PreviewProperty GetPreviewMaterialProperty()
62 {
63 return default(PreviewProperty);
64 }
65
66 internal override ShaderInput Copy()
67 {
68 return new SamplerStateShaderProperty()
69 {
70 displayName = displayName,
71 value = value,
72 };
73 }
74
75 public override int latestVersion => 1;
76 public override void OnAfterDeserialize(string json)
77 {
78 if (sgVersion == 0)
79 {
80 // we no longer require forced reference names on sampler state properties
81 // as we enforce custom property naming by simply not using the reference name
82 // this allows us to use the real reference name for subgraph parameters
83 // however we must clear out the old reference name first (as it was always hard-coded)
84 // this will fallback to the default ref name
85 overrideReferenceName = null;
86 var unused = referenceName;
87 ChangeVersion(1);
88 }
89 }
90 }
91}