ImageInputSettings.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace UnityEditor.Recorder.Input
  5. {
  6. /// <inheritdoc />
  7. /// <summary>
  8. /// Optional base class for image related inputs.
  9. /// </summary>
  10. public abstract class ImageInputSettings : RecorderInputSettings
  11. {
  12. /// <summary>
  13. /// Stores the output image width.
  14. /// </summary>
  15. public abstract int OutputWidth { get; set; }
  16. /// <summary>
  17. /// Stores the output image height.
  18. /// </summary>
  19. public abstract int OutputHeight { get; set; }
  20. /// <summary>
  21. /// Indicates if derived classes support transparency.
  22. /// </summary>
  23. public virtual bool SupportsTransparent
  24. {
  25. get { return true; }
  26. }
  27. internal bool AllowTransparency;
  28. }
  29. /// <inheritdoc />
  30. /// <summary>
  31. /// This class regroups settings required to specify the size of an image input using a size and an aspect ratio.
  32. /// </summary>
  33. [Serializable]
  34. public abstract class StandardImageInputSettings : ImageInputSettings
  35. {
  36. [SerializeField] OutputResolution m_OutputResolution = new OutputResolution();
  37. internal bool forceEvenSize;
  38. /// <inheritdoc />
  39. public override int OutputWidth
  40. {
  41. get { return ForceEvenIfNecessary(m_OutputResolution.GetWidth()); }
  42. set { m_OutputResolution.SetWidth(ForceEvenIfNecessary(value)); }
  43. }
  44. /// <inheritdoc />
  45. public override int OutputHeight
  46. {
  47. get { return ForceEvenIfNecessary(m_OutputResolution.GetHeight()); }
  48. set { m_OutputResolution.SetHeight(ForceEvenIfNecessary(value)); }
  49. }
  50. internal ImageHeight outputImageHeight
  51. {
  52. get { return m_OutputResolution.imageHeight; }
  53. set { m_OutputResolution.imageHeight = value; }
  54. }
  55. internal ImageHeight maxSupportedSize
  56. {
  57. get { return m_OutputResolution.maxSupportedHeight; }
  58. set { m_OutputResolution.maxSupportedHeight = value; }
  59. }
  60. int ForceEvenIfNecessary(int v)
  61. {
  62. if (forceEvenSize && outputImageHeight != ImageHeight.Custom)
  63. return (v + 1) & ~1;
  64. return v;
  65. }
  66. /// <inheritdoc />
  67. protected internal override bool ValidityCheck(List<string> errors)
  68. {
  69. var ok = true;
  70. var h = OutputHeight;
  71. if (h > (int) maxSupportedSize)
  72. {
  73. ok = false;
  74. errors.Add("Output size exceeds maximum supported size: " + (int) maxSupportedSize );
  75. }
  76. var w = OutputWidth;
  77. if (w <= 0 || h <= 0)
  78. {
  79. ok = false;
  80. errors.Add("Invalid output resolution: " + w + "x" + h);
  81. }
  82. return ok;
  83. }
  84. }
  85. }