OSDN Git Service

Added Assets for main menu
[mindgames/Mindgames_main.git] / Mindgames / Library / PackageCache / com.unity.shadergraph@6.9.0 / Editor / Data / Graphs / Matrix3MaterialSlot.cs
1 using System;
2 using System.Collections.Generic;
3 using UnityEditor.Graphing;
4 using UnityEditor.ShaderGraph.Drawing.Slots;
5 using UnityEngine;
6 using UnityEngine.UIElements;
7
8 namespace UnityEditor.ShaderGraph
9 {
10     [Serializable]
11     class Matrix3MaterialSlot : MaterialSlot, IMaterialSlotHasValue<Matrix4x4>
12     {
13         [SerializeField]
14         private Matrix4x4 m_Value = Matrix4x4.identity;
15
16         [SerializeField]
17         private Matrix4x4 m_DefaultValue = Matrix4x4.identity;
18
19         public Matrix3MaterialSlot()
20         {
21         }
22
23         public Matrix3MaterialSlot(
24             int slotId,
25             string displayName,
26             string shaderOutputName,
27             SlotType slotType,
28             ShaderStageCapability stageCapability = ShaderStageCapability.All,
29             bool hidden = false)
30             : base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
31         {
32         }
33
34         public override VisualElement InstantiateControl()
35         {
36             return new LabelSlotControlView("Identity");
37         }
38
39         public Matrix4x4 defaultValue { get { return m_DefaultValue; } }
40
41         public Matrix4x4 value
42         {
43             get { return m_Value; }
44             set { m_Value = value; }
45         }
46
47         protected override string ConcreteSlotValueAsVariable()
48         {
49             return "$precision3x3 (1,0,0,0,1,0,0,0,1)";
50         }
51
52         public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
53         {
54             if (!generationMode.IsPreview())
55                 return;
56
57             var matOwner = owner as AbstractMaterialNode;
58             if (matOwner == null)
59                 throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
60
61             var property = new Matrix3ShaderProperty()
62             {
63                 overrideReferenceName = matOwner.GetVariableNameForSlot(id),
64                 generatePropertyBlock = false,
65                 value = value
66             };
67             properties.AddShaderProperty(property);
68         }
69
70         public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
71         {
72             var pp = new PreviewProperty(PropertyType.Matrix3)
73             {
74                 name = name,
75                 matrixValue = value
76             };
77             properties.Add(pp);
78         }
79
80         public override SlotValueType valueType { get { return SlotValueType.Matrix3; } }
81         public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Matrix3; } }
82
83         public override void CopyValuesFrom(MaterialSlot foundSlot)
84         {
85             var slot = foundSlot as Matrix3MaterialSlot;
86             if (slot != null)
87                 value = slot.value;
88         }
89     }
90 }