初始化仓库

This commit is contained in:
SepComet
2026-02-07 19:38:49 +08:00
commit 88641dae11
1540 changed files with 371772 additions and 0 deletions
@@ -0,0 +1,487 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework;
using System;
using UnityEditor;
using UnityEngine;
namespace UnityGameFramework.Editor.ResourceTools
{
/// <summary>
/// 资源包生成器。
/// </summary>
internal sealed class ResourcePackBuilder : EditorWindow
{
private static readonly string[] PlatformForDisplay = new string[] { "Windows", "Windows x64", "macOS", "Linux", "iOS", "Android", "Windows Store", "WebGL" };
private static readonly int[] LengthLimit = new int[] { 0, 128, 256, 512, 1024, 2048, 4096 };
private static readonly string[] LengthLimitForDisplay = new string[] { "<Unlimited>", "128 MB", "256 MB", "512 MB", "1 GB", "2 GB", "4 GB", "<Custom>" };
private ResourcePackBuilderController m_Controller = null;
private string[] m_VersionNames = null;
private string[] m_VersionNamesForTargetDisplay = null;
private string[] m_VersionNamesForSourceDisplay = null;
private int m_PlatformIndex = 0;
private int m_CompressionHelperTypeNameIndex = 0;
private int m_LengthLimitIndex = 0;
private int m_TargetVersionIndex = 0;
private bool[] m_SourceVersionIndexes = null;
private int m_SourceVersionCount = 0;
[MenuItem("Game Framework/Resource Tools/Resource Pack Builder", false, 43)]
private static void Open()
{
ResourcePackBuilder window = GetWindow<ResourcePackBuilder>("Resource Pack Builder", true);
window.minSize = new Vector2(800f, 400f);
}
private void OnEnable()
{
m_Controller = new ResourcePackBuilderController();
m_Controller.OnBuildResourcePacksStarted += OnBuildResourcePacksStarted;
m_Controller.OnBuildResourcePacksCompleted += OnBuildResourcePacksCompleted;
m_Controller.OnBuildResourcePackSuccess += OnBuildResourcePackSuccess;
m_Controller.OnBuildResourcePackFailure += OnBuildResourcePackFailure;
m_Controller.Load();
RefreshVersionNames();
m_CompressionHelperTypeNameIndex = 0;
string[] compressionHelperTypeNames = m_Controller.GetCompressionHelperTypeNames();
for (int i = 0; i < compressionHelperTypeNames.Length; i++)
{
if (m_Controller.CompressionHelperTypeName == compressionHelperTypeNames[i])
{
m_CompressionHelperTypeNameIndex = i;
break;
}
}
m_Controller.RefreshCompressionHelper();
}
private void Update()
{
}
private void OnGUI()
{
EditorGUILayout.BeginVertical(GUILayout.Width(position.width), GUILayout.Height(position.height));
{
GUILayout.Space(5f);
EditorGUILayout.LabelField("Environment Information", EditorStyles.boldLabel);
EditorGUILayout.BeginVertical("box");
{
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Product Name", GUILayout.Width(160f));
EditorGUILayout.LabelField(m_Controller.ProductName);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Company Name", GUILayout.Width(160f));
EditorGUILayout.LabelField(m_Controller.CompanyName);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Game Identifier", GUILayout.Width(160f));
EditorGUILayout.LabelField(m_Controller.GameIdentifier);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Game Framework Version", GUILayout.Width(160f));
EditorGUILayout.LabelField(m_Controller.GameFrameworkVersion);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Unity Version", GUILayout.Width(160f));
EditorGUILayout.LabelField(m_Controller.UnityVersion);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Applicable Game Version", GUILayout.Width(160f));
EditorGUILayout.LabelField(m_Controller.ApplicableGameVersion);
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndVertical();
GUILayout.Space(5f);
EditorGUILayout.LabelField("Build", EditorStyles.boldLabel);
EditorGUILayout.BeginVertical("box");
{
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Working Directory", GUILayout.Width(160f));
string directory = EditorGUILayout.TextField(m_Controller.WorkingDirectory);
if (m_Controller.WorkingDirectory != directory)
{
m_Controller.WorkingDirectory = directory;
RefreshVersionNames();
}
if (GUILayout.Button("Browse...", GUILayout.Width(80f)))
{
BrowseWorkingDirectory();
RefreshVersionNames();
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Platform", GUILayout.Width(160f));
int platformIndex = EditorGUILayout.Popup(m_PlatformIndex, PlatformForDisplay);
if (m_PlatformIndex != platformIndex)
{
m_PlatformIndex = platformIndex;
m_Controller.Platform = (Platform)(1 << platformIndex);
RefreshVersionNames();
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Compression Helper", GUILayout.Width(160f));
string[] names = m_Controller.GetCompressionHelperTypeNames();
int selectedIndex = EditorGUILayout.Popup(m_CompressionHelperTypeNameIndex, names);
if (selectedIndex != m_CompressionHelperTypeNameIndex)
{
m_CompressionHelperTypeNameIndex = selectedIndex;
m_Controller.CompressionHelperTypeName = selectedIndex <= 0 ? string.Empty : names[selectedIndex];
if (m_Controller.RefreshCompressionHelper())
{
Debug.Log("Set compression helper success.");
}
else
{
Debug.LogWarning("Set compression helper failure.");
}
}
}
EditorGUILayout.EndHorizontal();
if (m_Controller.Platform == Platform.Undefined || string.IsNullOrEmpty(m_Controller.CompressionHelperTypeName) || !m_Controller.IsValidWorkingDirectory)
{
string message = string.Empty;
if (!m_Controller.IsValidWorkingDirectory)
{
if (!string.IsNullOrEmpty(message))
{
message += Environment.NewLine;
}
message += "Working directory is invalid.";
}
if (m_Controller.Platform == Platform.Undefined)
{
if (!string.IsNullOrEmpty(message))
{
message += Environment.NewLine;
}
message += "Platform is invalid.";
}
if (string.IsNullOrEmpty(m_Controller.CompressionHelperTypeName))
{
if (!string.IsNullOrEmpty(message))
{
message += Environment.NewLine;
}
message += "Compression helper is invalid.";
}
EditorGUILayout.HelpBox(message, MessageType.Error);
}
else if (m_VersionNamesForTargetDisplay.Length <= 0)
{
EditorGUILayout.HelpBox("No version was found in the specified working directory and platform.", MessageType.Warning);
}
else
{
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Source Path", GUILayout.Width(160f));
GUILayout.Label(m_Controller.SourcePathForDisplay);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Output Path", GUILayout.Width(160f));
GUILayout.Label(m_Controller.OutputPath);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Backup Diff", GUILayout.Width(160f));
m_Controller.BackupDiff = EditorGUILayout.Toggle(m_Controller.BackupDiff);
}
EditorGUILayout.EndHorizontal();
if (m_Controller.BackupDiff)
{
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Backup Version", GUILayout.Width(160f));
m_Controller.BackupVersion = EditorGUILayout.Toggle(m_Controller.BackupVersion);
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Length Limit", GUILayout.Width(160f));
EditorGUILayout.BeginVertical();
{
int lengthLimitIndex = EditorGUILayout.Popup(m_LengthLimitIndex, LengthLimitForDisplay);
if (m_LengthLimitIndex != lengthLimitIndex)
{
m_LengthLimitIndex = lengthLimitIndex;
if (m_LengthLimitIndex < LengthLimit.Length)
{
m_Controller.LengthLimit = LengthLimit[m_LengthLimitIndex];
}
}
if (m_LengthLimitIndex >= LengthLimit.Length)
{
EditorGUILayout.BeginHorizontal();
{
m_Controller.LengthLimit = EditorGUILayout.IntField(m_Controller.LengthLimit);
if (m_Controller.LengthLimit < 0)
{
m_Controller.LengthLimit = 0;
}
GUILayout.Label(" MB", GUILayout.Width(30f));
}
EditorGUILayout.EndHorizontal();
}
}
EditorGUILayout.EndVertical();
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Target Version", GUILayout.Width(160f));
int value = EditorGUILayout.Popup(m_TargetVersionIndex, m_VersionNamesForTargetDisplay);
if (m_TargetVersionIndex != value)
{
m_TargetVersionIndex = value;
RefreshSourceVersionCount();
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Source Version", GUILayout.Width(160f));
EditorGUILayout.BeginVertical();
{
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField(m_SourceVersionCount.ToString() + (m_SourceVersionCount > 1 ? " items" : " item") + " selected.");
if (GUILayout.Button("Select All Except <None>", GUILayout.Width(180f)))
{
m_SourceVersionIndexes[0] = false;
for (int i = 1; i < m_SourceVersionIndexes.Length; i++)
{
m_SourceVersionIndexes[i] = true;
}
RefreshSourceVersionCount();
}
if (GUILayout.Button("Select All", GUILayout.Width(100f)))
{
for (int i = 0; i < m_SourceVersionIndexes.Length; i++)
{
m_SourceVersionIndexes[i] = true;
}
RefreshSourceVersionCount();
}
if (GUILayout.Button("Select None", GUILayout.Width(100f)))
{
for (int i = 0; i < m_SourceVersionIndexes.Length; i++)
{
m_SourceVersionIndexes[i] = false;
}
RefreshSourceVersionCount();
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
int count = m_VersionNamesForSourceDisplay.Length;
int column = 5;
int row = (count - 1) / column + 1;
for (int i = 0; i < column && i < count; i++)
{
EditorGUILayout.BeginVertical();
{
for (int j = 0; j < row; j++)
{
int index = j * column + i;
if (index < count)
{
bool isTarget = index - 1 == m_TargetVersionIndex;
EditorGUI.BeginDisabledGroup(isTarget);
{
bool selected = GUILayout.Toggle(m_SourceVersionIndexes[index], isTarget ? m_VersionNamesForSourceDisplay[index] + " [Target]" : m_VersionNamesForSourceDisplay[index], "button");
if (m_SourceVersionIndexes[index] != selected)
{
m_SourceVersionIndexes[index] = selected;
RefreshSourceVersionCount();
}
}
EditorGUI.EndDisabledGroup();
}
}
}
EditorGUILayout.EndVertical();
}
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndVertical();
}
EditorGUILayout.EndHorizontal();
}
GUILayout.Space(2f);
}
EditorGUILayout.EndVertical();
GUILayout.Space(2f);
EditorGUILayout.BeginHorizontal();
{
EditorGUI.BeginDisabledGroup(m_Controller.Platform == Platform.Undefined || string.IsNullOrEmpty(m_Controller.CompressionHelperTypeName) || !m_Controller.IsValidWorkingDirectory || m_SourceVersionCount <= 0);
{
if (GUILayout.Button("Start Build Resource Packs"))
{
string[] sourceVersions = new string[m_SourceVersionCount];
int count = 0;
for (int i = 0; i < m_SourceVersionIndexes.Length; i++)
{
if (m_SourceVersionIndexes[i])
{
sourceVersions[count++] = i > 0 ? m_VersionNames[i - 1] : null;
}
}
m_Controller.BuildResourcePacks(sourceVersions, m_VersionNames[m_TargetVersionIndex]);
}
}
EditorGUI.EndDisabledGroup();
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndVertical();
}
private void BrowseWorkingDirectory()
{
string directory = EditorUtility.OpenFolderPanel("Select Working Directory", m_Controller.WorkingDirectory, string.Empty);
if (!string.IsNullOrEmpty(directory))
{
m_Controller.WorkingDirectory = directory;
}
}
private void RefreshVersionNames()
{
m_VersionNames = m_Controller.GetVersionNames();
m_VersionNamesForTargetDisplay = new string[m_VersionNames.Length];
m_VersionNamesForSourceDisplay = new string[m_VersionNames.Length + 1];
m_VersionNamesForSourceDisplay[0] = "<None>";
for (int i = 0; i < m_VersionNames.Length; i++)
{
string versionNameForDisplay = GetVersionNameForDisplay(m_VersionNames[i]);
m_VersionNamesForTargetDisplay[i] = versionNameForDisplay;
m_VersionNamesForSourceDisplay[i + 1] = versionNameForDisplay;
}
m_TargetVersionIndex = m_VersionNames.Length - 1;
m_SourceVersionIndexes = new bool[m_VersionNames.Length + 1];
m_SourceVersionCount = 0;
}
private void RefreshSourceVersionCount()
{
m_SourceVersionIndexes[m_TargetVersionIndex + 1] = false;
m_SourceVersionCount = 0;
if (m_SourceVersionIndexes == null)
{
return;
}
for (int i = 0; i < m_SourceVersionIndexes.Length; i++)
{
if (m_SourceVersionIndexes[i])
{
m_SourceVersionCount++;
}
}
}
private string GetVersionNameForDisplay(string versionName)
{
if (string.IsNullOrEmpty(versionName))
{
return "<None>";
}
string[] splitedVersionNames = versionName.Split('_');
if (splitedVersionNames.Length < 2)
{
return null;
}
string text = splitedVersionNames[0];
for (int i = 1; i < splitedVersionNames.Length - 1; i++)
{
text += "." + splitedVersionNames[i];
}
return Utility.Text.Format("{0} ({1})", text, splitedVersionNames[splitedVersionNames.Length - 1]);
}
private void OnBuildResourcePacksStarted(int count)
{
Debug.Log(Utility.Text.Format("Build resource packs started, '{0}' items to be built.", count));
EditorUtility.DisplayProgressBar("Build Resource Packs", Utility.Text.Format("Build resource packs, {0} items to be built.", count), 0f);
}
private void OnBuildResourcePacksCompleted(int successCount, int count)
{
int failureCount = count - successCount;
string str = Utility.Text.Format("Build resource packs completed, '{0}' items, '{1}' success, '{2}' failure.", count, successCount, failureCount);
if (failureCount > 0)
{
Debug.LogWarning(str);
}
else
{
Debug.Log(str);
}
EditorUtility.ClearProgressBar();
}
private void OnBuildResourcePackSuccess(int index, int count, string sourceVersion, string targetVersion)
{
Debug.Log(Utility.Text.Format("Build resource packs success, source version '{0}', target version '{1}'.", GetVersionNameForDisplay(sourceVersion), GetVersionNameForDisplay(targetVersion)));
EditorUtility.DisplayProgressBar("Build Resource Packs", Utility.Text.Format("Build resource packs, {0}/{1} completed.", index + 1, count), (float)index / count);
}
private void OnBuildResourcePackFailure(int index, int count, string sourceVersion, string targetVersion)
{
Debug.LogWarning(Utility.Text.Format("Build resource packs failure, source version '{0}', target version '{1}'.", GetVersionNameForDisplay(sourceVersion), GetVersionNameForDisplay(targetVersion)));
EditorUtility.DisplayProgressBar("Build Resource Packs", Utility.Text.Format("Build resource packs, {0}/{1} completed.", index + 1, count), (float)index / count);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e260afdf322bd1f4897314c0d2c777d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,558 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework;
using GameFramework.Resource;
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using UnityEditor;
using UnityEngine;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Editor.ResourceTools
{
public sealed class ResourcePackBuilderController
{
private const string DefaultResourcePackName = "GameFrameworkResourcePack";
private const string DefaultExtension = "dat";
private const string NoneOptionName = "<None>";
private static readonly string[] EmptyStringArray = new string[0];
private static readonly UpdatableVersionList.Resource[] EmptyResourceArray = new UpdatableVersionList.Resource[0];
private readonly string m_ConfigurationPath;
private readonly List<string> m_CompressionHelperTypeNames;
private readonly UpdatableVersionListSerializer m_UpdatableVersionListSerializer;
private readonly ResourcePackVersionListSerializer m_ResourcePackVersionListSerializer;
public ResourcePackBuilderController()
{
m_ConfigurationPath = Type.GetConfigurationPath<ResourceBuilderConfigPathAttribute>() ?? Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "GameFramework/Configs/ResourceBuilder.xml"));
m_UpdatableVersionListSerializer = new UpdatableVersionListSerializer();
m_UpdatableVersionListSerializer.RegisterDeserializeCallback(0, BuiltinVersionListSerializer.UpdatableVersionListDeserializeCallback_V0);
m_UpdatableVersionListSerializer.RegisterDeserializeCallback(1, BuiltinVersionListSerializer.UpdatableVersionListDeserializeCallback_V1);
m_UpdatableVersionListSerializer.RegisterDeserializeCallback(2, BuiltinVersionListSerializer.UpdatableVersionListDeserializeCallback_V2);
m_ResourcePackVersionListSerializer = new ResourcePackVersionListSerializer();
m_ResourcePackVersionListSerializer.RegisterSerializeCallback(0, BuiltinVersionListSerializer.ResourcePackVersionListSerializeCallback_V0);
m_CompressionHelperTypeNames = new List<string>
{
NoneOptionName
};
m_CompressionHelperTypeNames.AddRange(Type.GetRuntimeOrEditorTypeNames(typeof(Utility.Compression.ICompressionHelper)));
Platform = Platform.Windows;
CompressionHelperTypeName = string.Empty;
}
public string ProductName
{
get
{
return PlayerSettings.productName;
}
}
public string CompanyName
{
get
{
return PlayerSettings.companyName;
}
}
public string GameIdentifier
{
get
{
#if UNITY_5_6_OR_NEWER
return PlayerSettings.applicationIdentifier;
#else
return PlayerSettings.bundleIdentifier;
#endif
}
}
public string GameFrameworkVersion
{
get
{
return GameFramework.Version.GameFrameworkVersion;
}
}
public string UnityVersion
{
get
{
return Application.unityVersion;
}
}
public string ApplicableGameVersion
{
get
{
return Application.version;
}
}
public string WorkingDirectory
{
get;
set;
}
public Platform Platform
{
get;
set;
}
public string CompressionHelperTypeName
{
get;
set;
}
public bool BackupDiff
{
get;
set;
}
public bool BackupVersion
{
get;
set;
}
public int LengthLimit
{
get;
set;
}
public bool IsValidWorkingDirectory
{
get
{
if (string.IsNullOrEmpty(WorkingDirectory))
{
return false;
}
if (!Directory.Exists(WorkingDirectory))
{
return false;
}
return true;
}
}
public string SourcePath
{
get
{
if (!IsValidWorkingDirectory)
{
return string.Empty;
}
return Utility.Path.GetRegularPath(new DirectoryInfo(Utility.Text.Format("{0}/Full/", WorkingDirectory)).FullName);
}
}
public string SourcePathForDisplay
{
get
{
if (!IsValidWorkingDirectory)
{
return string.Empty;
}
return Utility.Path.GetRegularPath(new DirectoryInfo(Utility.Text.Format("{0}/Full/*/{1}/", WorkingDirectory, Platform)).FullName);
}
}
public string OutputPath
{
get
{
if (!IsValidWorkingDirectory)
{
return string.Empty;
}
return Utility.Path.GetRegularPath(new DirectoryInfo(Utility.Text.Format("{0}/ResourcePack/{1}/", WorkingDirectory, Platform)).FullName);
}
}
public event GameFrameworkAction<int> OnBuildResourcePacksStarted = null;
public event GameFrameworkAction<int, int> OnBuildResourcePacksCompleted = null;
public event GameFrameworkAction<int, int, string, string> OnBuildResourcePackSuccess = null;
public event GameFrameworkAction<int, int, string, string> OnBuildResourcePackFailure = null;
public bool Load()
{
if (!File.Exists(m_ConfigurationPath))
{
return false;
}
try
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(m_ConfigurationPath);
XmlNode xmlRoot = xmlDocument.SelectSingleNode("UnityGameFramework");
XmlNode xmlEditor = xmlRoot.SelectSingleNode("ResourceBuilder");
XmlNode xmlSettings = xmlEditor.SelectSingleNode("Settings");
XmlNodeList xmlNodeList = null;
XmlNode xmlNode = null;
xmlNodeList = xmlSettings.ChildNodes;
for (int i = 0; i < xmlNodeList.Count; i++)
{
xmlNode = xmlNodeList.Item(i);
switch (xmlNode.Name)
{
case "CompressionHelperTypeName":
CompressionHelperTypeName = xmlNode.InnerText;
break;
case "OutputDirectory":
WorkingDirectory = xmlNode.InnerText;
break;
}
}
}
catch
{
return false;
}
return true;
}
public string[] GetCompressionHelperTypeNames()
{
return m_CompressionHelperTypeNames.ToArray();
}
public string[] GetVersionNames()
{
if (Platform == Platform.Undefined || !IsValidWorkingDirectory)
{
return EmptyStringArray;
}
string platformName = Platform.ToString();
DirectoryInfo sourceDirectoryInfo = new DirectoryInfo(SourcePath);
if (!sourceDirectoryInfo.Exists)
{
return EmptyStringArray;
}
List<string> versionNames = new List<string>();
foreach (DirectoryInfo directoryInfo in sourceDirectoryInfo.GetDirectories())
{
string[] splitedVersionNames = directoryInfo.Name.Split('_');
if (splitedVersionNames.Length < 2)
{
continue;
}
bool invalid = false;
int value = 0;
for (int i = 0; i < splitedVersionNames.Length; i++)
{
if (!int.TryParse(splitedVersionNames[i], out value))
{
invalid = true;
break;
}
}
if (invalid)
{
continue;
}
DirectoryInfo platformDirectoryInfo = new DirectoryInfo(Path.Combine(directoryInfo.FullName, platformName));
if (!platformDirectoryInfo.Exists)
{
continue;
}
FileInfo[] versionListFiles = platformDirectoryInfo.GetFiles("GameFrameworkVersion.*.dat", SearchOption.TopDirectoryOnly);
if (versionListFiles.Length != 1)
{
continue;
}
versionNames.Add(directoryInfo.Name);
}
versionNames.Sort((x, y) =>
{
return int.Parse(x.Substring(x.LastIndexOf('_') + 1)).CompareTo(int.Parse(y.Substring(y.LastIndexOf('_') + 1)));
});
return versionNames.ToArray();
}
public bool RefreshCompressionHelper()
{
bool retVal = false;
if (!string.IsNullOrEmpty(CompressionHelperTypeName) && m_CompressionHelperTypeNames.Contains(CompressionHelperTypeName))
{
System.Type compressionHelperType = Utility.Assembly.GetType(CompressionHelperTypeName);
if (compressionHelperType != null)
{
Utility.Compression.ICompressionHelper compressionHelper = (Utility.Compression.ICompressionHelper)Activator.CreateInstance(compressionHelperType);
if (compressionHelper != null)
{
Utility.Compression.SetCompressionHelper(compressionHelper);
return true;
}
}
}
else
{
retVal = true;
}
CompressionHelperTypeName = string.Empty;
Utility.Compression.SetCompressionHelper(null);
return retVal;
}
public void BuildResourcePacks(string[] sourceVersions, string targetVersion)
{
int count = sourceVersions.Length;
if (OnBuildResourcePacksStarted != null)
{
OnBuildResourcePacksStarted(count);
}
int successCount = 0;
for (int i = 0; i < count; i++)
{
if (BuildResourcePack(sourceVersions[i], targetVersion))
{
successCount++;
if (OnBuildResourcePackSuccess != null)
{
OnBuildResourcePackSuccess(i, count, sourceVersions[i], targetVersion);
}
}
else
{
if (OnBuildResourcePackFailure != null)
{
OnBuildResourcePackFailure(i, count, sourceVersions[i], targetVersion);
}
}
}
if (OnBuildResourcePacksCompleted != null)
{
OnBuildResourcePacksCompleted(successCount, count);
}
}
public bool BuildResourcePack(string sourceVersion, string targetVersion)
{
try
{
if (!Directory.Exists(OutputPath))
{
Directory.CreateDirectory(OutputPath);
}
string defaultBackupDiffPath = Path.Combine(OutputPath, DefaultResourcePackName);
string defaultResourcePackName = Utility.Text.Format("{0}.{1}", defaultBackupDiffPath, DefaultExtension);
if (File.Exists(defaultResourcePackName))
{
File.Delete(defaultResourcePackName);
}
if (BackupDiff)
{
if (Directory.Exists(defaultBackupDiffPath))
{
Directory.Delete(defaultBackupDiffPath, true);
}
Directory.CreateDirectory(defaultBackupDiffPath);
}
UpdatableVersionList sourceUpdatableVersionList = default(UpdatableVersionList);
if (sourceVersion != null)
{
DirectoryInfo sourceDirectoryInfo = new DirectoryInfo(Path.Combine(Path.Combine(SourcePath, sourceVersion), Platform.ToString()));
FileInfo[] sourceVersionListFiles = sourceDirectoryInfo.GetFiles("GameFrameworkVersion.*.dat", SearchOption.TopDirectoryOnly);
byte[] sourceVersionListBytes = File.ReadAllBytes(sourceVersionListFiles[0].FullName);
sourceVersionListBytes = Utility.Compression.Decompress(sourceVersionListBytes);
using (Stream stream = new MemoryStream(sourceVersionListBytes))
{
sourceUpdatableVersionList = m_UpdatableVersionListSerializer.Deserialize(stream);
}
}
UpdatableVersionList targetUpdatableVersionList = default(UpdatableVersionList);
DirectoryInfo targetDirectoryInfo = new DirectoryInfo(Path.Combine(Path.Combine(SourcePath, targetVersion), Platform.ToString()));
FileInfo[] targetVersionListFiles = targetDirectoryInfo.GetFiles("GameFrameworkVersion.*.dat", SearchOption.TopDirectoryOnly);
byte[] targetVersionListBytes = File.ReadAllBytes(targetVersionListFiles[0].FullName);
targetVersionListBytes = Utility.Compression.Decompress(targetVersionListBytes);
using (Stream stream = new MemoryStream(targetVersionListBytes))
{
targetUpdatableVersionList = m_UpdatableVersionListSerializer.Deserialize(stream);
}
List<ResourcePackVersionList.Resource> resources = new List<ResourcePackVersionList.Resource>();
UpdatableVersionList.Resource[] sourceResources = sourceUpdatableVersionList.IsValid ? sourceUpdatableVersionList.GetResources() : EmptyResourceArray;
UpdatableVersionList.Resource[] targetResources = targetUpdatableVersionList.GetResources();
long offset = 0L;
foreach (UpdatableVersionList.Resource targetResource in targetResources)
{
bool ready = false;
foreach (UpdatableVersionList.Resource sourceResource in sourceResources)
{
if (sourceResource.Name != targetResource.Name || sourceResource.Variant != targetResource.Variant || sourceResource.Extension != targetResource.Extension)
{
continue;
}
if (sourceResource.LoadType == targetResource.LoadType && sourceResource.Length == targetResource.Length && sourceResource.HashCode == targetResource.HashCode)
{
ready = true;
}
break;
}
if (!ready)
{
resources.Add(new ResourcePackVersionList.Resource(targetResource.Name, targetResource.Variant, targetResource.Extension, targetResource.LoadType, offset, targetResource.Length, targetResource.HashCode, targetResource.CompressedLength, targetResource.CompressedHashCode));
offset += targetResource.CompressedLength;
}
}
ResourcePackVersionList.Resource[] resourceArray = resources.ToArray();
using (FileStream fileStream = new FileStream(defaultResourcePackName, FileMode.Create, FileAccess.Write))
{
if (!m_ResourcePackVersionListSerializer.Serialize(fileStream, new ResourcePackVersionList(0, 0L, 0, resourceArray)))
{
return false;
}
}
int position = 0;
int hashCode = 0;
string targetDirectoryPath = targetDirectoryInfo.FullName;
using (FileStream fileStream = new FileStream(defaultResourcePackName, FileMode.Open, FileAccess.ReadWrite))
{
position = (int)fileStream.Length;
fileStream.Position = position;
foreach (ResourcePackVersionList.Resource resource in resourceArray)
{
string resourceName = Path.Combine(targetDirectoryPath, GetResourceFullName(resource.Name, resource.Variant, resource.HashCode));
if (!File.Exists(resourceName))
{
return false;
}
byte[] resourceBytes = File.ReadAllBytes(resourceName);
fileStream.Write(resourceBytes, 0, resourceBytes.Length);
if (BackupDiff)
{
string backupDiffName = Path.Combine(defaultBackupDiffPath, GetResourceFullName(resource.Name, resource.Variant, resource.HashCode));
string directoryName = Path.GetDirectoryName(backupDiffName);
if (!Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
}
File.WriteAllBytes(backupDiffName, resourceBytes);
}
}
if (fileStream.Position - position != offset)
{
return false;
}
fileStream.Position = position;
hashCode = Utility.Verifier.GetCrc32(fileStream);
fileStream.Position = 0L;
if (!m_ResourcePackVersionListSerializer.Serialize(fileStream, new ResourcePackVersionList(position, offset, hashCode, resourceArray)))
{
return false;
}
}
string backupDiffPath = Path.Combine(OutputPath, Utility.Text.Format("{0}-{1}-{2}", DefaultResourcePackName, sourceVersion ?? GetNoneVersion(targetVersion), targetVersion));
string resourcePackName = Utility.Text.Format("{0}.{1:x8}.{2}", backupDiffPath, hashCode, DefaultExtension);
if (File.Exists(resourcePackName))
{
File.Delete(resourcePackName);
}
File.Move(defaultResourcePackName, resourcePackName);
if (BackupDiff)
{
if (BackupVersion)
{
File.Copy(targetVersionListFiles[0].FullName, Path.Combine(defaultBackupDiffPath, Path.GetFileName(targetVersionListFiles[0].FullName)));
}
if (Directory.Exists(backupDiffPath))
{
Directory.Delete(backupDiffPath, true);
}
Directory.Move(defaultBackupDiffPath, backupDiffPath);
}
return true;
}
catch
{
return false;
}
}
private string GetNoneVersion(string targetVersion)
{
string[] splitedVersionNames = targetVersion.Split('_');
for (int i = 0; i < splitedVersionNames.Length; i++)
{
splitedVersionNames[i] = "0";
}
return string.Join("_", splitedVersionNames);
}
private string GetResourceFullName(string name, string variant, int hashCode)
{
return !string.IsNullOrEmpty(variant) ? Utility.Text.Format("{0}.{1}.{2:x8}.{3}", name, variant, hashCode, DefaultExtension) : Utility.Text.Format("{0}.{1:x8}.{2}", name, hashCode, DefaultExtension);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 886e7d3c19662474caeb030f5b2d9a4e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: