PlatformReferenceSet.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. namespace AtlasUtility
  2. {
  3. using UnityEditor;
  4. using UnityEngine;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. public class PlatformReferenceSet
  9. {
  10. #region Variable
  11. public bool Valid
  12. {
  13. get { return MobileReference.GUID != "None" || DesktopReference.GUID != "None"; }
  14. }
  15. public string Content
  16. {
  17. get { return $"{EditorReference.GUID}|{MobileReference.GUID}|{DesktopReference.GUID}"; }
  18. }
  19. public Texture2D MobileTexture
  20. {
  21. get { return AssetDatabase.LoadAssetAtPath<Texture2D>(MobileReference.Path); }
  22. }
  23. public Texture2D DesktopTexture
  24. {
  25. get { return AssetDatabase.LoadAssetAtPath<Texture2D>(DesktopReference.Path); }
  26. }
  27. public Texture2D EditorTexture
  28. {
  29. get { return AssetDatabase.LoadAssetAtPath<Texture2D>(EditorReference.Path); }
  30. }
  31. public PlatformReference MobileReference;
  32. public PlatformReference DesktopReference;
  33. public PlatformReference EditorReference;
  34. #endregion
  35. public PlatformReferenceSet(string content)
  36. {
  37. MobileReference = new PlatformReference(content.Split('|')[1]);
  38. DesktopReference = new PlatformReference(content.Split('|')[2]);
  39. EditorReference = new PlatformReference(content.Split('|')[0]);
  40. }
  41. public PlatformReferenceSet(Texture2D editorTexture, string guid, ScalePlatform platform)
  42. {
  43. MobileReference = new PlatformReference("None");
  44. DesktopReference = new PlatformReference("None");
  45. EditorReference = new PlatformReference(AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(editorTexture)));
  46. SetPlatformReference(guid, platform);
  47. }
  48. public void SwitchPlatform(Platform toPlatform, List<string> fromList, List<string> toList)
  49. {
  50. if (toPlatform == Platform.Editor)
  51. {
  52. AssetBundleManager.SwitchAssetBundle(EditorReference.Path, MobileReference.Path, DesktopReference.Path, toPlatform);
  53. PackingTagManager.SwitchPackingTag(EditorReference.Path, MobileReference.Path, DesktopReference.Path, toPlatform);
  54. if (MobileReference.GUID != "None")
  55. {
  56. fromList.Add(MobileReference.GUID);
  57. toList.Add(EditorReference.GUID);
  58. }
  59. if (DesktopReference.GUID != "None")
  60. {
  61. fromList.Add(DesktopReference.GUID);
  62. toList.Add(EditorReference.GUID);
  63. }
  64. }
  65. else if (toPlatform == Platform.Mobile)
  66. {
  67. if (MobileReference.GUID == "None")
  68. {
  69. Debug.LogWarning(EditorReference.Path + " 没有移动版本");
  70. }
  71. else
  72. {
  73. AssetBundleManager.SwitchAssetBundle(EditorReference.Path, MobileReference.Path, DesktopReference.Path, toPlatform);
  74. PackingTagManager.SwitchPackingTag(EditorReference.Path, MobileReference.Path, DesktopReference.Path, toPlatform);
  75. if (EditorReference.GUID != "None")
  76. {
  77. fromList.Add(EditorReference.GUID);
  78. toList.Add(MobileReference.GUID);
  79. }
  80. if (DesktopReference.GUID != "None")
  81. {
  82. fromList.Add(DesktopReference.GUID);
  83. toList.Add(MobileReference.GUID);
  84. }
  85. }
  86. }
  87. else if (toPlatform == Platform.Desktop)
  88. {
  89. if (DesktopReference.GUID == "None")
  90. {
  91. Debug.LogWarning(EditorReference.Path + " 没有桌面版本");
  92. }
  93. else
  94. {
  95. AssetBundleManager.SwitchAssetBundle(EditorReference.Path, MobileReference.Path, DesktopReference.Path, toPlatform);
  96. PackingTagManager.SwitchPackingTag(EditorReference.Path, MobileReference.Path, DesktopReference.Path, toPlatform);
  97. if (EditorReference.GUID != "None")
  98. {
  99. fromList.Add(EditorReference.GUID);
  100. toList.Add(DesktopReference.GUID);
  101. }
  102. if (MobileReference.GUID != "None")
  103. {
  104. fromList.Add(MobileReference.GUID);
  105. toList.Add(DesktopReference.GUID);
  106. }
  107. }
  108. }
  109. else
  110. {
  111. throw new Exception();
  112. }
  113. }
  114. public void SetPlatformReference(string guid, ScalePlatform platform)
  115. {
  116. if (platform == ScalePlatform.Mobile)
  117. {
  118. if (MobileReference.GUID != "None" && MobileReference.GUID != guid)
  119. {
  120. Debug.LogWarning("注意 已经有一个移动版本了");
  121. }
  122. MobileReference.GUID = guid;
  123. }
  124. else if (platform == ScalePlatform.Desktop)
  125. {
  126. if (DesktopReference.GUID != "None" && DesktopReference.GUID != guid)
  127. {
  128. Debug.LogWarning("注意 已经有一个桌面版本了");
  129. }
  130. DesktopReference.GUID = guid;
  131. }
  132. else
  133. {
  134. throw new Exception("遇到了一个Bug");
  135. }
  136. }
  137. }
  138. }