OSDN Git Service

Added Assets for main menu
[mindgames/Mindgames_main.git] / Mindgames / Library / PackageCache / com.unity.shadergraph@6.9.0 / Editor / Data / Graphs / Texture2DArrayInputMaterialSlot.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 Texture2DArrayInputMaterialSlot : Texture2DArrayMaterialSlot
12     {
13         [SerializeField]
14         private SerializableTextureArray m_TextureArray = new SerializableTextureArray();
15
16         public Texture2DArray textureArray
17         {
18             get { return m_TextureArray.textureArray; }
19             set { m_TextureArray.textureArray = value; }
20         }
21
22         public Texture2DArrayInputMaterialSlot()
23         {}
24
25         public Texture2DArrayInputMaterialSlot(
26             int slotId,
27             string displayName,
28             string shaderOutputName,
29             ShaderStageCapability shaderStageCapability = ShaderStageCapability.All,
30             bool hidden = false)
31             : base(slotId, displayName, shaderOutputName, SlotType.Input, shaderStageCapability, hidden)
32         {}
33
34         public override VisualElement InstantiateControl()
35         {
36             return new TextureArraySlotControlView(this);
37         }
38
39         public override string GetDefaultValue(GenerationMode generationMode)
40         {
41             var matOwner = owner as AbstractMaterialNode;
42             if (matOwner == null)
43                 throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
44
45             return matOwner.GetVariableNameForSlot(id);
46         }
47
48         public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
49         {
50             var matOwner = owner as AbstractMaterialNode;
51             if (matOwner == null)
52                 throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
53
54             var prop = new Texture2DArrayShaderProperty();
55             prop.overrideReferenceName = matOwner.GetVariableNameForSlot(id);
56             prop.modifiable = false;
57             prop.generatePropertyBlock = true;
58             prop.value.textureArray = textureArray;
59             properties.AddShaderProperty(prop);
60         }
61
62         public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
63         {
64             var pp = new PreviewProperty(PropertyType.Texture2DArray)
65             {
66                 name = name,
67                 textureValue = textureArray,
68             };
69             properties.Add(pp);
70         }
71
72         public override void CopyValuesFrom(MaterialSlot foundSlot)
73         {
74             var slot = foundSlot as Texture2DArrayInputMaterialSlot;
75             if (slot != null)
76                 m_TextureArray = slot.m_TextureArray;
77         }
78     }
79 }