123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- 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<Texture2D>(MobileReference.Path); }
- }
- public Texture2D DesktopTexture
- {
- get { return AssetDatabase.LoadAssetAtPath<Texture2D>(DesktopReference.Path); }
- }
- public Texture2D EditorTexture
- {
- get { return AssetDatabase.LoadAssetAtPath<Texture2D>(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<string> fromList, List<string> 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");
- }
- }
- }
- }
|