namespace AtlasUtility { using UnityEditor; using UnityEngine; using System; using System.Collections; using System.Collections.Generic; public class PlatformReferenceSet { #region Variable public bool Valid { get { return MobileReference.GUID != "None" || DesktopReference.GUID != "None"; } } public string Content { get { return $"{EditorReference.GUID}|{MobileReference.GUID}|{DesktopReference.GUID}"; } } public Texture2D MobileTexture { get { return AssetDatabase.LoadAssetAtPath(MobileReference.Path); } } public Texture2D DesktopTexture { get { return AssetDatabase.LoadAssetAtPath(DesktopReference.Path); } } public Texture2D EditorTexture { get { return AssetDatabase.LoadAssetAtPath(EditorReference.Path); } } public PlatformReference MobileReference; public PlatformReference DesktopReference; public PlatformReference EditorReference; #endregion public PlatformReferenceSet(string content) { MobileReference = new PlatformReference(content.Split('|')[1]); DesktopReference = new PlatformReference(content.Split('|')[2]); EditorReference = new PlatformReference(content.Split('|')[0]); } public PlatformReferenceSet(Texture2D editorTexture, string guid, ScalePlatform platform) { MobileReference = new PlatformReference("None"); DesktopReference = new PlatformReference("None"); EditorReference = new PlatformReference(AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(editorTexture))); SetPlatformReference(guid, platform); } public void SwitchPlatform(Platform toPlatform, List fromList, List toList) { if (toPlatform == Platform.Editor) { AssetBundleManager.SwitchAssetBundle(EditorReference.Path, MobileReference.Path, DesktopReference.Path, toPlatform); PackingTagManager.SwitchPackingTag(EditorReference.Path, MobileReference.Path, DesktopReference.Path, toPlatform); if (MobileReference.GUID != "None") { fromList.Add(MobileReference.GUID); toList.Add(EditorReference.GUID); } if (DesktopReference.GUID != "None") { fromList.Add(DesktopReference.GUID); toList.Add(EditorReference.GUID); } } else if (toPlatform == Platform.Mobile) { if (MobileReference.GUID == "None") { Debug.LogWarning(EditorReference.Path + " 没有移动版本"); } else { AssetBundleManager.SwitchAssetBundle(EditorReference.Path, MobileReference.Path, DesktopReference.Path, toPlatform); PackingTagManager.SwitchPackingTag(EditorReference.Path, MobileReference.Path, DesktopReference.Path, toPlatform); if (EditorReference.GUID != "None") { fromList.Add(EditorReference.GUID); toList.Add(MobileReference.GUID); } if (DesktopReference.GUID != "None") { fromList.Add(DesktopReference.GUID); toList.Add(MobileReference.GUID); } } } else if (toPlatform == Platform.Desktop) { if (DesktopReference.GUID == "None") { Debug.LogWarning(EditorReference.Path + " 没有桌面版本"); } else { AssetBundleManager.SwitchAssetBundle(EditorReference.Path, MobileReference.Path, DesktopReference.Path, toPlatform); PackingTagManager.SwitchPackingTag(EditorReference.Path, MobileReference.Path, DesktopReference.Path, toPlatform); if (EditorReference.GUID != "None") { fromList.Add(EditorReference.GUID); toList.Add(DesktopReference.GUID); } if (MobileReference.GUID != "None") { fromList.Add(MobileReference.GUID); toList.Add(DesktopReference.GUID); } } } else { throw new Exception(); } } public void SetPlatformReference(string guid, ScalePlatform platform) { if (platform == ScalePlatform.Mobile) { if (MobileReference.GUID != "None" && MobileReference.GUID != guid) { Debug.LogWarning("注意 已经有一个移动版本了"); } MobileReference.GUID = guid; } else if (platform == ScalePlatform.Desktop) { if (DesktopReference.GUID != "None" && DesktopReference.GUID != guid) { Debug.LogWarning("注意 已经有一个桌面版本了"); } DesktopReference.GUID = guid; } else { throw new Exception("遇到了一个Bug"); } } } }