MediaReference.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace RenderHeads.Media.AVProVideo
  5. {
  6. [System.Serializable]
  7. [CreateAssetMenu(fileName = "MediaReference", menuName = "AVPro Video/Media Reference", order = 51)]
  8. public class MediaReference : ScriptableObject
  9. {
  10. [SerializeField] string _alias = string.Empty;
  11. public string Alias { get { return _alias; } set { _alias = value; } }
  12. [SerializeField] MediaPath _mediaPath = new MediaPath();
  13. public MediaPath MediaPath { get { return _mediaPath; } set { _mediaPath = value; } }
  14. [Header("Media Hints")]
  15. [SerializeField] MediaHints _hints = MediaHints.Default;
  16. public MediaHints Hints { get { return _hints; } set { _hints = value; } }
  17. [Header("Platform Overrides")]
  18. [SerializeField] MediaReference _macOS = null;
  19. [SerializeField] MediaReference _windows = null;
  20. [SerializeField] MediaReference _android = null;
  21. [SerializeField] MediaReference _iOS = null;
  22. [SerializeField] MediaReference _tvOS = null;
  23. [SerializeField] MediaReference _windowsUWP = null;
  24. [SerializeField] MediaReference _webGL = null;
  25. #if UNITY_EDITOR
  26. [SerializeField, HideInInspector] byte[] _preview = null;
  27. public Texture2D GeneratePreview(Texture2D texture)
  28. {
  29. _preview = null;
  30. if (texture)
  31. {
  32. texture.Apply(true, false);
  33. _preview = texture.GetRawTextureData();
  34. }
  35. UnityEditor.EditorUtility.SetDirty(this);
  36. return texture;
  37. }
  38. public bool GetPreview(Texture2D texture)
  39. {
  40. if (_preview != null && _preview.Length > 0 && _preview.Length > 128*128*4)
  41. {
  42. texture.LoadRawTextureData(_preview);
  43. texture.Apply(true, false);
  44. return true;
  45. }
  46. return false;
  47. }
  48. #endif
  49. public MediaReference GetCurrentPlatformMediaReference()
  50. {
  51. MediaReference result = null;
  52. #if (UNITY_EDITOR_OSX && UNITY_IOS) || (!UNITY_EDITOR && UNITY_IOS)
  53. result = GetPlatformMediaReference(Platform.iOS);
  54. #elif (UNITY_EDITOR_OSX && UNITY_TVOS) || (!UNITY_EDITOR && UNITY_TVOS)
  55. result = GetPlatformMediaReference(Platform.tvOS);
  56. #elif (UNITY_EDITOR_OSX || (!UNITY_EDITOR && UNITY_STANDALONE_OSX))
  57. result = GetPlatformMediaReference(Platform.MacOSX);
  58. #elif (UNITY_EDITOR_WIN) || (!UNITY_EDITOR && UNITY_STANDALONE_WIN)
  59. result = GetPlatformMediaReference(Platform.Windows);
  60. #elif (!UNITY_EDITOR && UNITY_WSA_10_0)
  61. result = GetPlatformMediaReference(Platform.WindowsUWP);
  62. #elif (!UNITY_EDITOR && UNITY_ANDROID)
  63. result = GetPlatformMediaReference(Platform.Android);
  64. #elif (!UNITY_EDITOR && UNITY_WEBGL)
  65. result = GetPlatformMediaReference(Platform.WebGL);
  66. #endif
  67. if (result == null)
  68. {
  69. result = this;
  70. }
  71. return result;
  72. }
  73. public MediaReference GetPlatformMediaReference(Platform platform)
  74. {
  75. MediaReference result = null;
  76. switch (platform)
  77. {
  78. case Platform.iOS:
  79. result = _iOS;
  80. break;
  81. case Platform.tvOS:
  82. result = _tvOS;
  83. break;
  84. case Platform.MacOSX:
  85. result = _macOS;
  86. break;
  87. case Platform.Windows:
  88. result = _windows;
  89. break;
  90. case Platform.WindowsUWP:
  91. result = _windowsUWP;
  92. break;
  93. case Platform.Android:
  94. result = _android;
  95. break;
  96. case Platform.WebGL:
  97. result = _webGL;
  98. break;
  99. }
  100. return result;
  101. }
  102. }
  103. }