Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Matrix2MaterialSlot.cs 3.2KB

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