PreviewNode.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Reflection;
  2. using UnityEngine;
  3. namespace UnityEditor.ShaderGraph
  4. {
  5. [Title("Utility", "Preview")]
  6. class PreviewNode : CodeFunctionNode
  7. {
  8. public override bool hasPreview { get { return true; } }
  9. [SerializeField]
  10. float m_Width;
  11. [SerializeField]
  12. float m_Height;
  13. public void SetDimensions(float width, float height)
  14. {
  15. float newSize = Mathf.Clamp(Mathf.Min(width, height), 150f, 1000f);
  16. m_Width = newSize;
  17. m_Height = newSize;
  18. }
  19. public float width
  20. {
  21. get { return m_Width; }
  22. }
  23. public float height
  24. {
  25. get { return m_Height; }
  26. }
  27. public PreviewNode()
  28. {
  29. name = "Preview";
  30. m_Width = 208f;
  31. m_Height = 208f;
  32. }
  33. protected override MethodInfo GetFunctionToConvert()
  34. {
  35. return GetType().GetMethod("Unity_Preview", BindingFlags.Static | BindingFlags.NonPublic);
  36. }
  37. static string Unity_Preview(
  38. [Slot(0, Binding.None)] DynamicDimensionVector In,
  39. [Slot(1, Binding.None)] out DynamicDimensionVector Out)
  40. {
  41. return
  42. @"
  43. {
  44. Out = In;
  45. }
  46. ";
  47. }
  48. }
  49. }