OSDN Git Service

Added Assets for main menu
[mindgames/Mindgames_main.git] / Mindgames / Library / PackageCache / com.unity.shadergraph@6.9.0 / Editor / Drawing / Views / Slots / TextureSlotControlView.cs
1 using System;
2 using UnityEditor.Graphing;
3 using UnityEngine;
4 using Object = UnityEngine.Object;
5 using UnityEditor.UIElements;
6 using UnityEngine.UIElements;
7
8 namespace UnityEditor.ShaderGraph.Drawing.Slots
9 {
10     class TextureSlotControlView : VisualElement
11     {
12         Texture2DInputMaterialSlot m_Slot;
13
14         public TextureSlotControlView(Texture2DInputMaterialSlot slot)
15         {
16             m_Slot = slot;
17             styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/TextureSlotControlView"));
18             var objectField = new ObjectField { objectType = typeof(Texture), value = m_Slot.texture };
19             objectField.RegisterValueChangedCallback(OnValueChanged);
20             Add(objectField);
21         }
22
23         void OnValueChanged(ChangeEvent<Object> evt)
24         {
25             var texture = evt.newValue as Texture;
26             if (texture != m_Slot.texture)
27             {
28                 m_Slot.owner.owner.owner.RegisterCompleteObjectUndo("Change Texture");
29                 m_Slot.texture = texture;
30                 m_Slot.owner.Dirty(ModificationScope.Node);
31             }
32         }
33     }
34 }