首次提交
This commit is contained in:
64
Assets/Scripts/NBC/Asset/Editor/Cache/BuildAsset.cs
Normal file
64
Assets/Scripts/NBC/Asset/Editor/Cache/BuildAsset.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class BuildAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// </summary>
|
||||
public string Path;
|
||||
|
||||
/// <summary>
|
||||
/// 可寻址地址
|
||||
/// </summary>
|
||||
public string Address;
|
||||
|
||||
/// <summary>
|
||||
/// 资源类型
|
||||
/// </summary>
|
||||
public string Type;
|
||||
|
||||
/// <summary>
|
||||
/// 资源所属的bundle包
|
||||
/// </summary>
|
||||
public string Bundle;
|
||||
|
||||
/// <summary>
|
||||
/// 资源标签
|
||||
/// </summary>
|
||||
public string Tags;
|
||||
|
||||
// /// <summary>
|
||||
// /// 资源依赖
|
||||
// /// </summary>
|
||||
// public string[] Dependencies = Array.Empty<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 资源所属组
|
||||
/// </summary>
|
||||
[HideInInspector] public GroupConfig Group;
|
||||
|
||||
private long _size;
|
||||
|
||||
public long Size
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_size == 0)
|
||||
{
|
||||
if (File.Exists(Path))
|
||||
{
|
||||
FileInfo info = new FileInfo(Path);
|
||||
_size = info.Length;
|
||||
}
|
||||
}
|
||||
|
||||
return _size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/Asset/Editor/Cache/BuildAsset.cs.meta
Normal file
3
Assets/Scripts/NBC/Asset/Editor/Cache/BuildAsset.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee63ea9c2adb468981d4e5c12832fe8d
|
||||
timeCreated: 1673939334
|
||||
46
Assets/Scripts/NBC/Asset/Editor/Cache/BuildBundle.cs
Normal file
46
Assets/Scripts/NBC/Asset/Editor/Cache/BuildBundle.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class BuildBundle
|
||||
{
|
||||
public string Name;
|
||||
public string Hash;
|
||||
public int Size;
|
||||
public List<BuildAsset> Assets = new List<BuildAsset>();
|
||||
public string[] Dependencies;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包标签
|
||||
/// </summary>
|
||||
public string Tags;
|
||||
|
||||
public void AddAsset(ICollection<BuildAsset> assets)
|
||||
{
|
||||
foreach (var asset in assets)
|
||||
{
|
||||
AddAsset(asset);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddAsset(BuildAsset asset)
|
||||
{
|
||||
asset.Bundle = Name;
|
||||
Assets.Add(asset);
|
||||
}
|
||||
|
||||
public string[] GetAssetNames()
|
||||
{
|
||||
HashSet<string> assetNames = new HashSet<string>();
|
||||
foreach (var asset in Assets)
|
||||
{
|
||||
assetNames.Add(asset.Path);
|
||||
}
|
||||
|
||||
return assetNames.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cb3d650a76f48d5bfddfbe05a6d6ab7
|
||||
timeCreated: 1675311242
|
||||
99
Assets/Scripts/NBC/Asset/Editor/Cache/BuildPackage.cs
Normal file
99
Assets/Scripts/NBC/Asset/Editor/Cache/BuildPackage.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class BuildPackage
|
||||
{
|
||||
public string Name;
|
||||
public int Size;
|
||||
public int Def;
|
||||
public List<BuildBundle> Bundles = new List<BuildBundle>();
|
||||
|
||||
[NonSerialized] public List<BuildAsset> Assets = new List<BuildAsset>();
|
||||
|
||||
public int GetBundleIndex(string name)
|
||||
{
|
||||
return Bundles.FindIndex(p => p.Name == name);
|
||||
}
|
||||
|
||||
public int GetAssetIndex(string asset)
|
||||
{
|
||||
return Assets.FindIndex(p => p.Path == asset);
|
||||
}
|
||||
|
||||
public PackageData ToPackagesData()
|
||||
{
|
||||
PackageData packageData = new PackageData
|
||||
{
|
||||
Name = Name,
|
||||
Def = Def,
|
||||
Bundles = new List<BundleData>(),
|
||||
Assets = new List<AssetData>()
|
||||
};
|
||||
|
||||
foreach (var bundle in Bundles)
|
||||
{
|
||||
var b = new BundleData
|
||||
{
|
||||
Name = bundle.Name,
|
||||
Hash = bundle.Hash,
|
||||
Size = bundle.Size,
|
||||
Tags = EditUtil.GetTagsArr(bundle.Tags),
|
||||
};
|
||||
if (bundle.Dependencies != null && bundle.Dependencies.Length > 0)
|
||||
{
|
||||
foreach (var dependency in bundle.Dependencies)
|
||||
{
|
||||
b.Deps.Add(GetBundleIndex(dependency));
|
||||
}
|
||||
}
|
||||
|
||||
Assets.AddRange(bundle.Assets);
|
||||
packageData.Bundles.Add(b);
|
||||
}
|
||||
|
||||
HashSet<string> dirs = new HashSet<string>();
|
||||
foreach (var asset in Assets)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(asset.Path)?.Replace("\\", "/");
|
||||
if (!string.IsNullOrEmpty(dir))
|
||||
{
|
||||
dirs.Add(dir);
|
||||
}
|
||||
}
|
||||
|
||||
packageData.Dirs = dirs.ToList();
|
||||
|
||||
foreach (var asset in Assets)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(asset.Path)?.Replace("\\", "/");
|
||||
var a = new AssetData
|
||||
{
|
||||
Name = Path.GetFileName(asset.Path),
|
||||
Dir = packageData.Dirs.FindIndex(b => b == dir),
|
||||
Address = asset.Address,
|
||||
// Tags = EditUtil.GetTagsArr(asset.Tags),
|
||||
Bundle = GetBundleIndex(asset.Bundle)
|
||||
};
|
||||
// if (asset.Dependencies != null && asset.Dependencies.Length > 0)
|
||||
// {
|
||||
// foreach (var dependency in asset.Dependencies)
|
||||
// {
|
||||
// var index = GetAssetIndex(dependency);
|
||||
// if (index >= 0)
|
||||
// a.Deps.Add(index);
|
||||
// }
|
||||
// }
|
||||
|
||||
packageData.Assets.Add(a);
|
||||
}
|
||||
|
||||
|
||||
return packageData;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6581ebcb347b4d4dbe2de0886dd23562
|
||||
timeCreated: 1680321488
|
||||
61
Assets/Scripts/NBC/Asset/Editor/Cache/Caches.cs
Normal file
61
Assets/Scripts/NBC/Asset/Editor/Cache/Caches.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
[FilePath("Assets/AssetCaches.asset")]
|
||||
public class Caches : ScriptableSingleton<Caches>
|
||||
{
|
||||
public List<BuildAsset> Assets = new List<BuildAsset>();
|
||||
public List<BuildBundle> Bundles = new List<BuildBundle>();
|
||||
|
||||
public void ClearBundles()
|
||||
{
|
||||
Bundles.Clear();
|
||||
Save();
|
||||
}
|
||||
public void ClearAssets()
|
||||
{
|
||||
Assets.Clear();
|
||||
Save();
|
||||
}
|
||||
|
||||
public void AddOrUpdate(ICollection<BuildAsset> assets)
|
||||
{
|
||||
foreach (var asset in assets)
|
||||
{
|
||||
AddOrUpdate(asset);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddOrUpdate(BuildAsset asset)
|
||||
{
|
||||
Assets.Add(asset);
|
||||
}
|
||||
|
||||
public void AddOrUpdate(ICollection<BuildBundle> bundles)
|
||||
{
|
||||
foreach (var bundle in bundles)
|
||||
{
|
||||
AddBundle(bundle);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddBundle(BuildBundle bundle)
|
||||
{
|
||||
Bundles.Add(bundle);
|
||||
}
|
||||
|
||||
public BuildBundle GetBundle(string name)
|
||||
{
|
||||
return Bundles.FirstOrDefault(bundle => bundle.Name == name);
|
||||
}
|
||||
|
||||
|
||||
public void Save()
|
||||
{
|
||||
EditorUtility.SetDirty(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/Asset/Editor/Cache/Caches.cs.meta
Normal file
3
Assets/Scripts/NBC/Asset/Editor/Cache/Caches.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9fa072029bab4df48fef4d84ac836775
|
||||
timeCreated: 1677727983
|
||||
180
Assets/Scripts/NBC/Asset/Editor/Cache/Histories.cs
Normal file
180
Assets/Scripts/NBC/Asset/Editor/Cache/Histories.cs
Normal file
@@ -0,0 +1,180 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class HistoryData
|
||||
{
|
||||
public int Index;
|
||||
public List<BuildBundle> Bundles = new List<BuildBundle>();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class HistoriesData
|
||||
{
|
||||
private int _historyCount = 5;
|
||||
public List<HistoryData> Histories = new List<HistoryData>();
|
||||
|
||||
public HistoryData LastHistoryData => Histories.Last();
|
||||
|
||||
public int LastIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
var index = 0;
|
||||
if (Histories.Count > 0)
|
||||
{
|
||||
index = Histories[^1].Index;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
public bool AddHistory(List<BuildBundle> bundles)
|
||||
{
|
||||
var data = new HistoryData();
|
||||
|
||||
foreach (var bundle in bundles)
|
||||
{
|
||||
var b = new BuildBundle
|
||||
{
|
||||
Name = bundle.Name,
|
||||
Hash = bundle.Hash,
|
||||
Size = bundle.Size
|
||||
};
|
||||
data.Bundles.Add(b);
|
||||
}
|
||||
|
||||
if (CanAdd(data))
|
||||
{
|
||||
data.Index = LastIndex + 1;
|
||||
Histories.Add(data);
|
||||
}
|
||||
|
||||
if (Histories.Count > _historyCount)
|
||||
{
|
||||
var count = Histories.Count - _historyCount;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
Histories.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanAdd(HistoryData data)
|
||||
{
|
||||
var changes = new List<BuildBundle>();
|
||||
|
||||
if (Histories.Count > 0 && Histories.Last() != null)
|
||||
{
|
||||
var last = Histories.Last();
|
||||
foreach (var bundle in data.Bundles)
|
||||
{
|
||||
var old = last.Bundles.Find(t => t.Name == bundle.Name);
|
||||
if (old != null)
|
||||
{
|
||||
if (old.Size != bundle.Size || old.Hash != bundle.Hash)
|
||||
{
|
||||
changes.Add(bundle);
|
||||
}
|
||||
}
|
||||
else changes.Add(bundle);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
changes.AddRange(data.Bundles);
|
||||
}
|
||||
|
||||
return changes.Count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Histories
|
||||
{
|
||||
private static readonly string FilePath = BuildSettings.GetCachePath("BuildHistories.json");
|
||||
|
||||
private static HistoriesData _data;
|
||||
|
||||
public static HistoryData LastHistoryData => _data != null ? _data.LastHistoryData : null;
|
||||
|
||||
public static void AddHistory(List<BuildBundle> bundles)
|
||||
{
|
||||
if (_data == null)
|
||||
{
|
||||
Reload();
|
||||
}
|
||||
|
||||
if (_data != null && _data.AddHistory(bundles))
|
||||
{
|
||||
Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("添加历史记录失败!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void Reload()
|
||||
{
|
||||
_data = Util.ReadJson<HistoriesData>(FilePath) ?? new HistoriesData();
|
||||
}
|
||||
|
||||
public static void Save()
|
||||
{
|
||||
if (_data != null)
|
||||
{
|
||||
Util.WriteJson(_data, FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
public static VersionData GetLastVersion()
|
||||
{
|
||||
if (!Directory.Exists(BuildSettings.PlatformPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var files = Directory.GetFiles(BuildSettings.PlatformPath);
|
||||
List<string> paths = new List<string>();
|
||||
foreach (var file in files)
|
||||
{
|
||||
var name = Path.GetFileName(file);
|
||||
if (name.StartsWith("version")) paths.Add(file);
|
||||
}
|
||||
|
||||
var lastFilePath = string.Empty;
|
||||
if (paths.Count > 0)
|
||||
{
|
||||
long lastCreationTime = 0;
|
||||
foreach (var path in paths)
|
||||
{
|
||||
var file = new FileInfo(path);
|
||||
if (file.Exists)
|
||||
{
|
||||
var t = file.CreationTime.ToFileTime();
|
||||
if (t > lastCreationTime)
|
||||
{
|
||||
lastCreationTime = t;
|
||||
lastFilePath = path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(lastFilePath))
|
||||
{
|
||||
return Util.ReadJson<VersionData>(lastFilePath);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/Asset/Editor/Cache/Histories.cs.meta
Normal file
3
Assets/Scripts/NBC/Asset/Editor/Cache/Histories.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed799f6364ab4e8c9a4179410f5756e7
|
||||
timeCreated: 1675909929
|
||||
137
Assets/Scripts/NBC/Asset/Editor/Cache/VersionHistory.cs
Normal file
137
Assets/Scripts/NBC/Asset/Editor/Cache/VersionHistory.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class VersionHistoryData
|
||||
{
|
||||
public string ShowName; // => $"version_{Index}_{VersionData?.BuildTime}";
|
||||
public string FileName;
|
||||
public VersionData VersionData;
|
||||
|
||||
/// <summary>
|
||||
/// 版本包
|
||||
/// </summary>
|
||||
public readonly List<PackageData> Packages = new List<PackageData>();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class PackageChangeData
|
||||
{
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 变化的bundle
|
||||
/// </summary>
|
||||
public List<BundleData> ChangeBundles = new List<BundleData>();
|
||||
|
||||
/// <summary>
|
||||
/// 新增的bundle
|
||||
/// </summary>
|
||||
public List<BundleData> AddBundles = new List<BundleData>();
|
||||
|
||||
/// <summary>
|
||||
/// 减少的bundle
|
||||
/// </summary>
|
||||
public List<BundleData> RemoveBundles = new List<BundleData>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 版本变化简略信息
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class VersionSimpleChangeData
|
||||
{
|
||||
/// <summary>
|
||||
/// 需要下载总数
|
||||
/// </summary>
|
||||
public long DownloadSize;
|
||||
|
||||
/// <summary>
|
||||
/// 每个资源包需要下载总数
|
||||
/// </summary>
|
||||
public Dictionary<string, long> PackageDownloadSize = new Dictionary<string, long>();
|
||||
|
||||
/// <summary>
|
||||
/// 每个资源包新增bundle
|
||||
/// </summary>
|
||||
public Dictionary<string, List<string>> PackageAddBundle = new Dictionary<string, List<string>>();
|
||||
|
||||
/// <summary>
|
||||
/// 每个资源包移除bundle
|
||||
/// </summary>
|
||||
public Dictionary<string, List<string>> PackageRemoveBundle = new Dictionary<string, List<string>>();
|
||||
|
||||
/// <summary>
|
||||
/// 每个资源包变化的bundle
|
||||
/// </summary>
|
||||
public Dictionary<string, List<string>> PackageChangeBundle = new Dictionary<string, List<string>>();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class VersionChangeData
|
||||
{
|
||||
public string NewVersionName;
|
||||
public string OldVersionName;
|
||||
public VersionSimpleChangeData SimpleChangeData = new VersionSimpleChangeData();
|
||||
|
||||
/// <summary>
|
||||
/// 变化的package
|
||||
/// </summary>
|
||||
public List<PackageChangeData> ChangePackage = new List<PackageChangeData>();
|
||||
|
||||
public enum TypeEnum
|
||||
{
|
||||
Add,
|
||||
Change,
|
||||
Remove
|
||||
}
|
||||
|
||||
public void Change(BundleData bundleData, TypeEnum typeEnum)
|
||||
{
|
||||
var packageChangeData = ChangePackage.Find(p => p.PackageName == bundleData.PackageName);
|
||||
if (packageChangeData == null)
|
||||
{
|
||||
packageChangeData = new PackageChangeData();
|
||||
packageChangeData.PackageName = bundleData.PackageName;
|
||||
ChangePackage.Add(packageChangeData);
|
||||
}
|
||||
|
||||
switch (typeEnum)
|
||||
{
|
||||
case TypeEnum.Add:
|
||||
packageChangeData.AddBundles.Add(bundleData);
|
||||
break;
|
||||
case TypeEnum.Remove:
|
||||
packageChangeData.RemoveBundles.Add(bundleData);
|
||||
break;
|
||||
case TypeEnum.Change:
|
||||
packageChangeData.ChangeBundles.Add(bundleData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Processing()
|
||||
{
|
||||
SimpleChangeData = new VersionSimpleChangeData();
|
||||
long allSize = 0;
|
||||
foreach (var package in ChangePackage)
|
||||
{
|
||||
var name = package.PackageName;
|
||||
var size = package.AddBundles.Sum(b => b.Size) + package.ChangeBundles.Sum(b => b.Size);
|
||||
allSize += size;
|
||||
SimpleChangeData.PackageDownloadSize[name] = size;
|
||||
|
||||
SimpleChangeData.PackageAddBundle[name] = package.AddBundles.Select(bundle => bundle.Name).ToList();
|
||||
SimpleChangeData.PackageRemoveBundle[name] =
|
||||
package.RemoveBundles.Select(bundle => bundle.Name).ToList();
|
||||
SimpleChangeData.PackageChangeBundle[name] =
|
||||
package.ChangeBundles.Select(bundle => bundle.Name).ToList();
|
||||
}
|
||||
|
||||
SimpleChangeData.DownloadSize = allSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7dfb832d1f340d4bd50c2f8922a44f0
|
||||
timeCreated: 1680151006
|
||||
Reference in New Issue
Block a user