OSDN Git Service

Added Assets for main menu
[mindgames/Mindgames_main.git] / Mindgames / Library / PackageCache / com.unity.shadergraph@6.9.0 / Editor / Drawing / Controls / ButtonControl.cs
1 using System;
2 using System.Reflection;
3 using UnityEditor.UIElements;
4 using UnityEngine;
5 using UnityEngine.UIElements;
6
7 namespace UnityEditor.ShaderGraph.Drawing.Controls
8 {
9     [AttributeUsage(AttributeTargets.Property)]
10     class ButtonControlAttribute : Attribute, IControlAttribute
11     {
12         public ButtonControlAttribute()
13         {
14         }
15
16         public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
17         {
18             return new ButtonControlView(node, propertyInfo);
19         }
20     }
21
22     [Serializable]
23     struct ButtonConfig
24     {
25         public string text;
26         public Action action;
27     }
28
29     class ButtonControlView : VisualElement
30     {
31         public ButtonControlView(AbstractMaterialNode node, PropertyInfo propertyInfo)
32         {
33             AbstractMaterialNode m_Node;
34
35             m_Node = node;
36
37             Type type = propertyInfo.PropertyType;
38             if (type != typeof(ButtonConfig))
39             {
40                 throw new ArgumentException("Property must be a ButtonConfig.", "propertyInfo");
41             }
42             var value = (ButtonConfig)propertyInfo.GetValue(m_Node, null);
43
44             Add(new Button(value.action) { text = value.text});
45         }
46     }
47 }