PBRSettingsView.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEditor.Graphing.Util;
  6. using UnityEditor.ShaderGraph.Drawing.Controls;
  7. using UnityEditor.UIElements;
  8. using UnityEngine.UIElements;
  9. using UnityEditor.ShaderGraph.Internal;
  10. namespace UnityEditor.ShaderGraph.Drawing
  11. {
  12. class PBRSettingsView : VisualElement
  13. {
  14. PBRMasterNode m_Node;
  15. public PBRSettingsView(PBRMasterNode node)
  16. {
  17. m_Node = node;
  18. PropertySheet ps = new PropertySheet();
  19. ps.Add(new PropertyRow(new Label("Workflow")), (row) =>
  20. {
  21. row.Add(new EnumField(PBRMasterNode.Model.Metallic), (field) =>
  22. {
  23. field.value = m_Node.model;
  24. field.RegisterValueChangedCallback(ChangeWorkFlow);
  25. });
  26. });
  27. ps.Add(new PropertyRow(new Label("Surface")), (row) =>
  28. {
  29. row.Add(new EnumField(SurfaceType.Opaque), (field) =>
  30. {
  31. field.value = m_Node.surfaceType;
  32. field.RegisterValueChangedCallback(ChangeSurface);
  33. });
  34. });
  35. ps.Add(new PropertyRow(new Label("Blend")), (row) =>
  36. {
  37. row.Add(new EnumField(AlphaMode.Additive), (field) =>
  38. {
  39. field.value = m_Node.alphaMode;
  40. field.RegisterValueChangedCallback(ChangeAlphaMode);
  41. });
  42. });
  43. ps.Add(new PropertyRow(new Label("Fragment Normal Space")), (row) =>
  44. {
  45. row.Add(new EnumField(NormalDropOffSpace.Tangent), (field) =>
  46. {
  47. field.value = m_Node.normalDropOffSpace;
  48. field.RegisterValueChangedCallback(ChangeSpaceOfNormalDropOffMode);
  49. });
  50. });
  51. ps.Add(new PropertyRow(new Label("Two Sided")), (row) =>
  52. {
  53. row.Add(new Toggle(), (toggle) =>
  54. {
  55. toggle.value = m_Node.twoSided.isOn;
  56. toggle.OnToggleChanged(ChangeTwoSided);
  57. });
  58. });
  59. Add(ps);
  60. }
  61. void ChangeWorkFlow(ChangeEvent<Enum> evt)
  62. {
  63. if (Equals(m_Node.model, evt.newValue))
  64. return;
  65. m_Node.owner.owner.RegisterCompleteObjectUndo("Work Flow Change");
  66. m_Node.model = (PBRMasterNode.Model)evt.newValue;
  67. }
  68. void ChangeSurface(ChangeEvent<Enum> evt)
  69. {
  70. if (Equals(m_Node.surfaceType, evt.newValue))
  71. return;
  72. m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Change");
  73. m_Node.surfaceType = (SurfaceType)evt.newValue;
  74. }
  75. void ChangeAlphaMode(ChangeEvent<Enum> evt)
  76. {
  77. if (Equals(m_Node.alphaMode, evt.newValue))
  78. return;
  79. m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change");
  80. m_Node.alphaMode = (AlphaMode)evt.newValue;
  81. }
  82. void ChangeSpaceOfNormalDropOffMode(ChangeEvent<Enum> evt)
  83. {
  84. if (Equals(m_Node.normalDropOffSpace, evt.newValue))
  85. return;
  86. m_Node.owner.owner.RegisterCompleteObjectUndo("Normal Space Drop-Off Mode Change");
  87. m_Node.normalDropOffSpace = (NormalDropOffSpace)evt.newValue;
  88. }
  89. void ChangeTwoSided(ChangeEvent<bool> evt)
  90. {
  91. m_Node.owner.owner.RegisterCompleteObjectUndo("Two Sided Change");
  92. ToggleData td = m_Node.twoSided;
  93. td.isOn = evt.newValue;
  94. m_Node.twoSided = td;
  95. }
  96. }
  97. }