123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using System.Collections.Generic;
- using UnityEditor;
- using UnityEngine;
- namespace XGame.Editor.Build.AssetBundles
- {
- public partial class ABPackerInfoManifest : ScriptableObject
- {
- public AssetBundleNameMode bundleNameMode;
- /// <summary>
- /// 是否合并shader
- /// 将*.shadervariants文件和其所依赖的shader一起打在一个包内
- /// </summary>
- public bool isMergeShader;
- [SerializeField]
- private List<ABPackerInfo> packerInfos;
- public List<ABPackerInfo> PackerInfos
- {
- get
- {
- if (packerInfos == null)
- {
- packerInfos = new List<ABPackerInfo>();
- }
- return packerInfos;
- }
- }
- public bool AddPackerInfo(ABPackerInfo info)
- {
- if (packerInfos == null)
- {
- packerInfos = new List<ABPackerInfo>();
- }
- int index = packerInfos.FindIndex((item => item.GUID.Equals(info.GUID)));
- if (index < 0)
- {
- packerInfos.Add(info);
- return true;
- }
- else
- {
- Debug.LogError($"Add PackerInfo. but it's repeat. {info}");
- }
- return false;
- }
- public bool IsContainGUID(string guid)
- {
- if (!string.IsNullOrEmpty(guid))
- {
- var index = packerInfos?.FindIndex((info) => info.GUID.Equals(guid)) ?? -1;
- if (index != -1)
- {
- return true;
- }
- }
- return false;
- }
- public bool IsContainAssetPath(string assetPath)
- {
- var guid = AssetDatabase.AssetPathToGUID(assetPath);
- return IsContainGUID(guid);
- }
- public bool TryGetPackerInfoByGUID(string guid, out ABPackerInfo packerInfo)
- {
- if (!string.IsNullOrEmpty(guid))
- {
- var index = packerInfos?.FindIndex((info) => info.GUID.Equals(guid)) ?? -1;
- if (index != -1)
- {
- packerInfo = packerInfos[index];
- return true;
- }
- }
- packerInfo = default;
- return false;
- }
- public bool TryGetPackerInfoByAssetPath(string assetPath, out ABPackerInfo packerInfo)
- {
- return TryGetPackerInfoByGUID(AssetDatabase.AssetPathToGUID(assetPath), out packerInfo);
- }
- public bool VerifyInfoRepeat()
- {
- var listGUID = new List<string>();
- bool result = true;
- if (packerInfos != null)
- {
- foreach (var info in packerInfos)
- {
- if (listGUID.Contains(info.GUID))
- {
- Debug.LogError($"PackerInfo repeat. {info}");
- result = false;
- continue;
- }
- listGUID.Add(info.GUID);
- }
- }
- listGUID.Clear();
- return result;
- }
- public void Save()
- {
- EditorUtility.SetDirty(this);
- AssetDatabase.SaveAssets();
- AssetDatabase.Refresh();
- }
- }
- }
|