OSDN Git Service

Added Assets for main menu
[mindgames/Mindgames_main.git] / Mindgames / Library / PackageCache / com.unity.shadergraph@6.9.0 / Editor / Data / Graphs / ColorMaterialSlot.cs
1 using System;
2 using System.Collections.Generic;
3 using UnityEditor.Graphing;
4 using UnityEditor.ShaderGraph.Drawing.Slots;
5 using UnityEngine;
6
7 using UnityEngine.UIElements;
8
9 namespace UnityEditor.ShaderGraph
10 {
11     class ColorRGBAMaterialSlot : Vector4MaterialSlot
12     {
13         public ColorRGBAMaterialSlot() {}
14
15         public ColorRGBAMaterialSlot(
16             int slotId,
17             string displayName,
18             string shaderOutputName,
19             SlotType slotType,
20             Vector4 value,
21             ShaderStageCapability stageCapability = ShaderStageCapability.All,
22             bool hidden = false)
23             : base(slotId, displayName, shaderOutputName, slotType, value, stageCapability, hidden: hidden)
24         {
25         }
26
27         public override VisualElement InstantiateControl()
28         {
29             return new ColorRGBASlotControlView(this);
30         }
31
32         protected override string ConcreteSlotValueAsVariable()
33         {
34             return string.Format("IsGammaSpace() ? $precision4({0}, {1}, {2}, {3}) : $precision4 (SRGBToLinear($precision3({0}, {1}, {2})), {3})"
35                 , NodeUtils.FloatToShaderValue(value.x)
36                 , NodeUtils.FloatToShaderValue(value.y)
37                 , NodeUtils.FloatToShaderValue(value.z)
38                 , NodeUtils.FloatToShaderValue(value.w));
39         }
40
41         public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
42         {
43             if (!generationMode.IsPreview())
44                 return;
45
46             var matOwner = owner as AbstractMaterialNode;
47             if (matOwner == null)
48                 throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
49
50             var property = new ColorShaderProperty()
51             {
52                 overrideReferenceName = matOwner.GetVariableNameForSlot(id),
53                 generatePropertyBlock = false,
54                 value = value
55             };
56             properties.AddShaderProperty(property);
57         }
58
59         public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
60         {
61             var pp = new PreviewProperty(PropertyType.Color)
62             {
63                 name = name,
64                 colorValue = new Color(value.x, value.x, value.z, value.w),
65             };
66             properties.Add(pp);
67         }
68     }
69 }