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