A game about forced loneliness, made by TACStudios
at master 3.2 kB view raw
1using System; 2using System.Collections.Generic; 3using UnityEditor.Graphing; 4using UnityEditor.ShaderGraph.Drawing.Slots; 5using UnityEditor.ShaderGraph.Internal; 6using UnityEngine; 7using UnityEngine.UIElements; 8 9namespace UnityEditor.ShaderGraph 10{ 11 [Serializable] 12 class Matrix3MaterialSlot : MaterialSlot, IMaterialSlotHasValue<Matrix4x4> 13 { 14 [SerializeField] 15 private Matrix4x4 m_Value = Matrix4x4.identity; 16 17 [SerializeField] 18 private Matrix4x4 m_DefaultValue = Matrix4x4.identity; 19 20 public Matrix3MaterialSlot() 21 { 22 } 23 24 public Matrix3MaterialSlot( 25 int slotId, 26 string displayName, 27 string shaderOutputName, 28 SlotType slotType, 29 ShaderStageCapability stageCapability = ShaderStageCapability.All, 30 bool hidden = false) 31 : base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden) 32 { 33 } 34 35 public override VisualElement InstantiateControl() 36 { 37 return new LabelSlotControlView("Identity"); 38 } 39 40 public Matrix4x4 defaultValue { get { return m_DefaultValue; } } 41 42 public Matrix4x4 value 43 { 44 get { return m_Value; } 45 set { m_Value = value; } 46 } 47 48 public override bool isDefaultValue => value.Equals(defaultValue); 49 50 protected override string ConcreteSlotValueAsVariable() 51 { 52 return "$precision3x3 (1,0,0,0,1,0,0,0,1)"; 53 } 54 55 public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) 56 { 57 if (!generationMode.IsPreview()) 58 return; 59 60 var matOwner = owner as AbstractMaterialNode; 61 if (matOwner == null) 62 throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode))); 63 64 var property = new Matrix3ShaderProperty() 65 { 66 overrideReferenceName = matOwner.GetVariableNameForSlot(id), 67 generatePropertyBlock = false, 68 value = value 69 }; 70 properties.AddShaderProperty(property); 71 } 72 73 public override void GetPreviewProperties(List<PreviewProperty> properties, string name) 74 { 75 var pp = new PreviewProperty(PropertyType.Matrix3) 76 { 77 name = name, 78 matrixValue = value 79 }; 80 properties.Add(pp); 81 } 82 83 public override SlotValueType valueType { get { return SlotValueType.Matrix3; } } 84 public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Matrix3; } } 85 86 public override void CopyValuesFrom(MaterialSlot foundSlot) 87 { 88 var slot = foundSlot as Matrix3MaterialSlot; 89 if (slot != null) 90 value = slot.value; 91 } 92 93 public override void CopyDefaultValue(MaterialSlot other) 94 { 95 base.CopyDefaultValue(other); 96 if (other is IMaterialSlotHasValue<Matrix4x4> ms) 97 { 98 m_DefaultValue = ms.defaultValue; 99 } 100 } 101 } 102}