UnlitSettingsView.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. namespace UnityEditor.ShaderGraph.Drawing
  10. {
  11. class UnlitSettingsView : VisualElement
  12. {
  13. UnlitMasterNode m_Node;
  14. public UnlitSettingsView(UnlitMasterNode node)
  15. {
  16. m_Node = node;
  17. PropertySheet ps = new PropertySheet();
  18. ps.Add(new PropertyRow(new Label("Surface")), (row) =>
  19. {
  20. row.Add(new EnumField(SurfaceType.Opaque), (field) =>
  21. {
  22. field.value = m_Node.surfaceType;
  23. field.RegisterValueChangedCallback(ChangeSurface);
  24. });
  25. });
  26. ps.Add(new PropertyRow(new Label("Blend")), (row) =>
  27. {
  28. row.Add(new EnumField(AlphaMode.Additive), (field) =>
  29. {
  30. field.value = m_Node.alphaMode;
  31. field.RegisterValueChangedCallback(ChangeAlphaMode);
  32. });
  33. });
  34. ps.Add(new PropertyRow(new Label("Two Sided")), (row) =>
  35. {
  36. row.Add(new Toggle(), (toggle) =>
  37. {
  38. toggle.value = m_Node.twoSided.isOn;
  39. toggle.OnToggleChanged(ChangeTwoSided);
  40. });
  41. });
  42. Add(ps);
  43. }
  44. void ChangeSurface(ChangeEvent<Enum> evt)
  45. {
  46. if (Equals(m_Node.surfaceType, evt.newValue))
  47. return;
  48. m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Change");
  49. m_Node.surfaceType = (SurfaceType)evt.newValue;
  50. }
  51. void ChangeAlphaMode(ChangeEvent<Enum> evt)
  52. {
  53. if (Equals(m_Node.alphaMode, evt.newValue))
  54. return;
  55. m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change");
  56. m_Node.alphaMode = (AlphaMode)evt.newValue;
  57. }
  58. void ChangeTwoSided(ChangeEvent<bool> evt)
  59. {
  60. m_Node.owner.owner.RegisterCompleteObjectUndo("Two Sided Change");
  61. ToggleData td = m_Node.twoSided;
  62. td.isOn = evt.newValue;
  63. m_Node.twoSided = td;
  64. }
  65. }
  66. }