A game about forced loneliness, made by TACStudios
1using System; 2using System.Reflection; 3using UnityEngine; 4using UnityEditor.UIElements; 5using UnityEngine.UIElements; 6 7namespace UnityEditor.ShaderGraph.Drawing.Controls 8{ 9 [AttributeUsage(AttributeTargets.Property)] 10 class IdentifierControlAttribute : Attribute, IControlAttribute 11 { 12 string m_Label; 13 14 public IdentifierControlAttribute(string label = null) 15 { 16 m_Label = label; 17 } 18 19 public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo) 20 { 21 return new IdentifierControlView(m_Label, node, propertyInfo); 22 } 23 } 24 25 class IdentifierControlView : VisualElement 26 { 27 AbstractMaterialNode m_Node; 28 PropertyInfo m_PropertyInfo; 29 30 public IdentifierControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo) 31 { 32 var style = Resources.Load<StyleSheet>("Styles/Controls/IdentifierControlView"); 33 if (style) styleSheets.Add(style); 34 35 m_Node = node; 36 m_PropertyInfo = propertyInfo; 37 if (propertyInfo.PropertyType != typeof(string)) 38 throw new ArgumentException("Property must be of type string.", "propertyInfo"); 39 40 label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name); 41 if (!string.IsNullOrEmpty(label)) 42 Add(new Label(label)); 43 44 var strField = new IdentifierField() { value = (string)m_PropertyInfo.GetValue(m_Node, null) }; 45 strField.RegisterValueChangedCallback(OnChange); 46 Add(strField); 47 } 48 49 void OnChange(ChangeEvent<string> evt) 50 { 51 m_Node.owner.owner.RegisterCompleteObjectUndo("Identifier Change"); 52 m_PropertyInfo.SetValue(m_Node, evt.newValue, null); 53 this.MarkDirtyRepaint(); 54 } 55 } 56}