初始化仓库

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,115 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework;
using UnityEditor;
using UnityEngine;
namespace UnityGameFramework.Editor.ResourceTools
{
/// <summary>
/// 资源同步工具。
/// </summary>
internal sealed class ResourceSyncTools : EditorWindow
{
private const float ButtonHeight = 60f;
private const float ButtonSpace = 5f;
private ResourceSyncToolsController m_Controller = null;
[MenuItem("Game Framework/Resource Tools/Resource Sync Tools", false, 44)]
private static void Open()
{
ResourceSyncTools window = GetWindow<ResourceSyncTools>("Resource Sync Tools", true);
#if UNITY_2019_3_OR_NEWER
window.minSize = new Vector2(400, 195f);
#else
window.minSize = new Vector2(400, 205f);
#endif
}
private void OnEnable()
{
m_Controller = new ResourceSyncToolsController();
m_Controller.OnLoadingResource += OnLoadingResource;
m_Controller.OnLoadingAsset += OnLoadingAsset;
m_Controller.OnCompleted += OnCompleted;
m_Controller.OnResourceDataChanged += OnResourceDataChanged;
}
private void OnGUI()
{
EditorGUILayout.BeginVertical(GUILayout.Width(position.width), GUILayout.Height(position.height));
{
GUILayout.Space(ButtonSpace);
if (GUILayout.Button("Remove All Asset Bundle Names in Project", GUILayout.Height(ButtonHeight)))
{
if (!m_Controller.RemoveAllAssetBundleNames())
{
Debug.LogWarning("Remove All Asset Bundle Names in Project failure.");
}
else
{
Debug.Log("Remove All Asset Bundle Names in Project completed.");
}
AssetDatabase.Refresh();
}
GUILayout.Space(ButtonSpace);
if (GUILayout.Button("Sync ResourceCollection.xml to Project", GUILayout.Height(ButtonHeight)))
{
if (!m_Controller.SyncToProject())
{
Debug.LogWarning("Sync ResourceCollection.xml to Project failure.");
}
else
{
Debug.Log("Sync ResourceCollection.xml to Project completed.");
}
AssetDatabase.Refresh();
}
GUILayout.Space(ButtonSpace);
if (GUILayout.Button("Sync ResourceCollection.xml from Project", GUILayout.Height(ButtonHeight)))
{
if (!m_Controller.SyncFromProject())
{
Debug.LogWarning("Sync Project to ResourceCollection.xml failure.");
}
else
{
Debug.Log("Sync Project to ResourceCollection.xml completed.");
}
AssetDatabase.Refresh();
}
}
EditorGUILayout.EndVertical();
}
private void OnLoadingResource(int index, int count)
{
EditorUtility.DisplayProgressBar("Loading Resources", Utility.Text.Format("Loading resources, {0}/{1} loaded.", index, count), (float)index / count);
}
private void OnLoadingAsset(int index, int count)
{
EditorUtility.DisplayProgressBar("Loading Assets", Utility.Text.Format("Loading assets, {0}/{1} loaded.", index, count), (float)index / count);
}
private void OnCompleted()
{
EditorUtility.ClearProgressBar();
}
private void OnResourceDataChanged(int index, int count, string assetName)
{
EditorUtility.DisplayProgressBar("Processing Assets", Utility.Text.Format("({0}/{1}) {2}", index, count, assetName), (float)index / count);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d691ed24af244ff41a3012f66ca3ef80
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,229 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
namespace UnityGameFramework.Editor.ResourceTools
{
public sealed class ResourceSyncToolsController
{
public ResourceSyncToolsController()
{
}
public event GameFrameworkAction<int, int> OnLoadingResource = null;
public event GameFrameworkAction<int, int> OnLoadingAsset = null;
public event GameFrameworkAction OnCompleted = null;
public event GameFrameworkAction<int, int, string> OnResourceDataChanged = null;
public string[] GetAllAssetBundleNames()
{
return AssetDatabase.GetAllAssetBundleNames();
}
public string[] GetUsedAssetBundleNames()
{
HashSet<string> hashSet = new HashSet<string>(GetAllAssetBundleNames());
hashSet.ExceptWith(GetUnusedAssetBundleNames());
return hashSet.ToArray();
}
public string[] GetUnusedAssetBundleNames()
{
return AssetDatabase.GetUnusedAssetBundleNames();
}
public string[] GetAssetPathsFromAssetBundle(string assetBundleName)
{
return AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
}
public string[] GetAssetPathsFromAssetBundleAndAssetName(string assetBundleName, string assetName)
{
return AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);
}
public bool RemoveAssetBundleName(string assetBundleName, bool forceRemove)
{
return AssetDatabase.RemoveAssetBundleName(assetBundleName, forceRemove);
}
public void RemoveUnusedAssetBundleNames()
{
AssetDatabase.RemoveUnusedAssetBundleNames();
}
public bool RemoveAllAssetBundleNames()
{
HashSet<string> allAssetNames = new HashSet<string>();
string[] assetBundleNames = GetUsedAssetBundleNames();
foreach (string assetBundleName in assetBundleNames)
{
string[] assetNames = GetAssetPathsFromAssetBundle(assetBundleName);
foreach (string assetName in assetNames)
{
allAssetNames.Add(assetName);
}
}
int assetIndex = 0;
int assetCount = allAssetNames.Count;
foreach (string assetName in allAssetNames)
{
AssetImporter assetImporter = AssetImporter.GetAtPath(assetName);
if (assetImporter == null)
{
if (OnCompleted != null)
{
OnCompleted();
}
return false;
}
assetImporter.assetBundleVariant = null;
assetImporter.assetBundleName = null;
assetImporter.SaveAndReimport();
if (OnResourceDataChanged != null)
{
OnResourceDataChanged(++assetIndex, assetCount, assetName);
}
}
RemoveUnusedAssetBundleNames();
if (OnCompleted != null)
{
OnCompleted();
}
return true;
}
public bool SyncToProject()
{
ResourceCollection resourceCollection = new ResourceCollection();
resourceCollection.OnLoadingResource += delegate (int index, int count)
{
if (OnLoadingResource != null)
{
OnLoadingResource(index, count);
}
};
resourceCollection.OnLoadingAsset += delegate (int index, int count)
{
if (OnLoadingAsset != null)
{
OnLoadingAsset(index, count);
}
};
resourceCollection.OnLoadCompleted += delegate ()
{
if (OnCompleted != null)
{
OnCompleted();
}
};
if (!resourceCollection.Load())
{
return false;
}
int assetIndex = 0;
int assetCount = resourceCollection.AssetCount;
Resource[] resources = resourceCollection.GetResources();
foreach (Resource resource in resources)
{
if (resource.IsLoadFromBinary)
{
continue;
}
Asset[] assets = resource.GetAssets();
foreach (Asset asset in assets)
{
AssetImporter assetImporter = AssetImporter.GetAtPath(asset.Name);
if (assetImporter == null)
{
if (OnCompleted != null)
{
OnCompleted();
}
return false;
}
assetImporter.assetBundleName = resource.Name;
assetImporter.assetBundleVariant = resource.Variant;
assetImporter.SaveAndReimport();
if (OnResourceDataChanged != null)
{
OnResourceDataChanged(++assetIndex, assetCount, asset.Name);
}
}
}
if (OnCompleted != null)
{
OnCompleted();
}
return true;
}
public bool SyncFromProject()
{
ResourceCollection resourceCollection = new ResourceCollection();
string[] assetBundleNames = GetUsedAssetBundleNames();
foreach (string assetBundleName in assetBundleNames)
{
string name = assetBundleName;
string variant = null;
int dotPosition = assetBundleName.LastIndexOf('.');
if (dotPosition > 0 && dotPosition < assetBundleName.Length - 1)
{
name = assetBundleName.Substring(0, dotPosition);
variant = assetBundleName.Substring(dotPosition + 1);
}
if (!resourceCollection.AddResource(name, variant, null, LoadType.LoadFromFile, false))
{
return false;
}
string[] assetNames = GetAssetPathsFromAssetBundle(assetBundleName);
foreach (string assetName in assetNames)
{
string guid = AssetDatabase.AssetPathToGUID(assetName);
if (string.IsNullOrEmpty(guid))
{
return false;
}
if (!resourceCollection.AssignAsset(guid, name, variant))
{
return false;
}
}
}
return resourceCollection.Save();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 210d0e0a522f6c540b17cf9fe64b71e4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: