diff --git a/Assets/Editor/FilePathChecker.cs b/Assets/Editor/FilePathChecker.cs new file mode 100644 index 0000000..e19aa6c --- /dev/null +++ b/Assets/Editor/FilePathChecker.cs @@ -0,0 +1,145 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using UnityEditor; +using UnityEngine; + +public sealed class FilePathChecker : EditorWindow +{ + public const int MaxPathLen = 255; + public const int MaxFileNameLen = 63; + private List files; + private int curmaxPathLen = 180; + private int curmaxFileNameLen = 50; + private ConcurrentBag showFiles = new(); + + private Vector2 silderPos = Vector2.zero; + + private Tuple[] filters = new Tuple[] + { + new ("路径长度", false), + new ("文件名长度", true), + new ("材质", true), + new ("模型", false), + new ("场景", false), + new ("其它",false), + }; + + [MenuItem("Window/路径检查")] + private static void OpenFilePathCheckerWindow() + { + var wnd = GetWindow(); + wnd.titleContent = new GUIContent("资源路径检查"); + } + + private FilePathChecker() + { + ConcurrentBag fileBag = new ConcurrentBag(); + Parallel.ForEach(Directory.GetFiles(Application.dataPath, "*.*", SearchOption.AllDirectories), item => + { + if (item.EndsWith(".meta")) + { + return; + } + + fileBag.Add("Assets" + item.Replace('\\', '/').Replace(Application.dataPath.Replace('\\', '/'), "")); + }); + + files = fileBag.ToList(); + FilterResult(); + } + + private void FilterResult() + { + showFiles.Clear(); + Parallel.ForEach(files, f => + { + if (filters[0].Item2 && f.Length > curmaxPathLen || filters[1].Item2 && Path.GetFileNameWithoutExtension(f).Length > curmaxFileNameLen) + { + if (filters[2].Item2 && f.EndsWith(".mat")) + { + showFiles.Add(f); + } + else if (filters[3].Item2 && (f.ToLower() is string s && (s.EndsWith(".fbx") || s.EndsWith(".obj")))) + { + showFiles.Add(f); + } + else if (filters[4].Item2 && (f.ToLower() is string s1 && (s1.EndsWith(".unity") || s1.EndsWith(".scene")))) + { + showFiles.Add(f); + } + else if (filters[5].Item2) + { + showFiles.Add(f); + } + } + }); + } + + private void OnGUI() + { + EditorGUILayout.BeginVertical(); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField("路径长度"); + var _curmaxPathLen = EditorGUILayout.IntSlider(curmaxPathLen, 16, MaxPathLen); + if (_curmaxPathLen != curmaxPathLen) + { + curmaxPathLen = _curmaxPathLen; + FilterResult(); + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField("文件名长度"); + var _curmaxFileNameLen = EditorGUILayout.IntSlider(curmaxFileNameLen, 1, MaxFileNameLen); + if (_curmaxFileNameLen != curmaxFileNameLen) + { + curmaxFileNameLen = _curmaxFileNameLen; + FilterResult(); + } + + EditorGUILayout.EndHorizontal(); + EditorGUILayout.Space(); + EditorGUILayout.BeginHorizontal(); + + for (int i = 0; i < filters.Length; i++) + { + var filter = filters[i]; + var v = EditorGUILayout.Toggle(filter.Item1, filter.Item2); + if (v != filter.Item2) + { + filters[i] = new Tuple(filter.Item1, v); + FilterResult(); + } + } + + EditorGUILayout.EndHorizontal(); + EditorGUILayout.Space(); + + silderPos = EditorGUILayout.BeginScrollView(silderPos); + foreach (var item in showFiles) + { + FileItem(item); + } + + EditorGUILayout.EndScrollView(); + + EditorGUILayout.EndVertical(); + } + + + private void FileItem(string path) + { + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField(path); + if (GUILayout.Button("Ping")) + { + EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(path)); + } + EditorGUILayout.EndHorizontal(); + } +} diff --git a/Assets/Editor/FilePathChecker.cs.meta b/Assets/Editor/FilePathChecker.cs.meta new file mode 100644 index 0000000..085b4fe --- /dev/null +++ b/Assets/Editor/FilePathChecker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ffd5a5c15c510b34c94f1d0e05debbe7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/TexturePack.meta b/Assets/Editor/TexturePack.meta new file mode 100644 index 0000000..0b28336 --- /dev/null +++ b/Assets/Editor/TexturePack.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6258725997e3ca0418f2644062e6d916 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/TexturePack/Docker.cs b/Assets/Editor/TexturePack/Docker.cs new file mode 100644 index 0000000..d04b36f --- /dev/null +++ b/Assets/Editor/TexturePack/Docker.cs @@ -0,0 +1,159 @@ +#if UNITY_EDITOR +using System; +using System.Reflection; +using UnityEditor; +using UnityEngine; + +public static class Docker +{ + + #region Reflection Types + private class _EditorWindow + { + private EditorWindow instance; + private Type type; + + public _EditorWindow(EditorWindow instance) + { + this.instance = instance; + type = instance.GetType(); + } + + public object m_Parent + { + get + { + var field = type.GetField("m_Parent", BindingFlags.Instance | BindingFlags.NonPublic); + return field.GetValue(instance); + } + } + } + + private class _DockArea + { + private object instance; + private Type type; + + public _DockArea(object instance) + { + this.instance = instance; + type = instance.GetType(); + } + + public object window + { + get + { + var property = type.GetProperty("window", BindingFlags.Instance | BindingFlags.Public); + return property.GetValue(instance, null); + } + } + + public object s_OriginalDragSource + { + set + { + var field = type.GetField("s_OriginalDragSource", BindingFlags.Static | BindingFlags.NonPublic); + field.SetValue(null, value); + } + } + } + + private class _ContainerWindow + { + private object instance; + private Type type; + + public _ContainerWindow(object instance) + { + this.instance = instance; + type = instance.GetType(); + } + + + public object rootSplitView + { + get + { + var property = type.GetProperty("rootSplitView", BindingFlags.Instance | BindingFlags.Public); + return property.GetValue(instance, null); + } + } + } + + private class _SplitView + { + private object instance; + private Type type; + + public _SplitView(object instance) + { + this.instance = instance; + type = instance.GetType(); + } + + public object DragOver(EditorWindow child, Vector2 screenPoint) + { + var method = type.GetMethod("DragOver", BindingFlags.Instance | BindingFlags.Public); + return method.Invoke(instance, new object[] { child, screenPoint }); + } + + public void PerformDrop(EditorWindow child, object dropInfo, Vector2 screenPoint) + { + var method = type.GetMethod("PerformDrop", BindingFlags.Instance | BindingFlags.Public); + method.Invoke(instance, new object[] { child, dropInfo, screenPoint }); + } + } + #endregion + + public enum DockPosition + { + Left, + Top, + Right, + Bottom + } + + /// + /// Docks the second window to the first window at the given position + /// + public static void Dock(this EditorWindow wnd, EditorWindow other, DockPosition position) + { + var mousePosition = GetFakeMousePosition(wnd, position); + + var parent = new _EditorWindow(wnd); + var child = new _EditorWindow(other); + var dockArea = new _DockArea(parent.m_Parent); + var containerWindow = new _ContainerWindow(dockArea.window); + var splitView = new _SplitView(containerWindow.rootSplitView); + var dropInfo = splitView.DragOver(other, mousePosition); + dockArea.s_OriginalDragSource = child.m_Parent; + splitView.PerformDrop(other, dropInfo, mousePosition); + } + + private static Vector2 GetFakeMousePosition(EditorWindow wnd, DockPosition position) + { + Vector2 mousePosition = Vector2.zero; + + // The 20 is required to make the docking work. + // Smaller values might not work when faking the mouse position. + switch (position) + { + case DockPosition.Left: + mousePosition = new Vector2(20, wnd.position.size.y / 2); + break; + case DockPosition.Top: + mousePosition = new Vector2(wnd.position.size.x / 2, 20); + break; + case DockPosition.Right: + mousePosition = new Vector2(wnd.position.size.x - 20, wnd.position.size.y / 2); + break; + case DockPosition.Bottom: + mousePosition = new Vector2(wnd.position.size.x / 2, wnd.position.size.y - 20); + break; + } + + return GUIUtility.GUIToScreenPoint(mousePosition); + } +} +#endif \ No newline at end of file diff --git a/Assets/Editor/TexturePack/Docker.cs.meta b/Assets/Editor/TexturePack/Docker.cs.meta new file mode 100644 index 0000000..b950cc0 --- /dev/null +++ b/Assets/Editor/TexturePack/Docker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b25038136cd4d354fa7c02bca38c30dd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/TexturePack/Resources.meta b/Assets/Editor/TexturePack/Resources.meta new file mode 100644 index 0000000..af0ec66 --- /dev/null +++ b/Assets/Editor/TexturePack/Resources.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5eab531d55428ec4faf2565e8dccc92b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/TexturePack/Resources/25_10_30_084215.asset b/Assets/Editor/TexturePack/Resources/25_10_30_084215.asset new file mode 100644 index 0000000..43707a3 --- /dev/null +++ b/Assets/Editor/TexturePack/Resources/25_10_30_084215.asset @@ -0,0 +1,50 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 34bbc4130cb4b964aacff1ffb6ea7dd9, type: 3} + m_Name: 25_10_30_084215 + m_EditorClassIdentifier: + PackType: 1 + OriginTexture2TextureInfo: + m_Keys: + - {fileID: 2800000, guid: 07a6d0e57a3ecf045a4c126e11857e16, type: 3} + - {fileID: 2800000, guid: 0fe9d9cf76b17d7439a37e14b9efecec, type: 3} + - {fileID: 2800000, guid: 3cfd0258a2a2046a3a14bbd0266f5825, type: 3} + m_Values: + - OriginTexture: {fileID: 2800000, guid: 07a6d0e57a3ecf045a4c126e11857e16, type: 3} + ArrayIndex: 0 + ScaleOffset: + x: 0 + y: 0 + z: 0 + w: 0 + - OriginTexture: {fileID: 2800000, guid: 0fe9d9cf76b17d7439a37e14b9efecec, type: 3} + ArrayIndex: 2 + ScaleOffset: + x: 0 + y: 0 + z: 0 + w: 0 + - OriginTexture: {fileID: 2800000, guid: 3cfd0258a2a2046a3a14bbd0266f5825, type: 3} + ArrayIndex: 1 + ScaleOffset: + x: 0 + y: 0 + z: 0 + w: 0 + Textures: + - {fileID: 2800000, guid: 07a6d0e57a3ecf045a4c126e11857e16, type: 3} + - {fileID: 2800000, guid: 3cfd0258a2a2046a3a14bbd0266f5825, type: 3} + - {fileID: 2800000, guid: 0fe9d9cf76b17d7439a37e14b9efecec, type: 3} + TextureAtlas: {fileID: 0} + TextureAtlasPath: Assets/Editor/TexturePack/Resources/test.png + TextureArray: {fileID: 0} + TextureArrayPath: Assets/Editor/TexturePack/Resources/test.png diff --git a/Assets/Scenes/Garden/GardenScene/LightingData.asset.meta b/Assets/Editor/TexturePack/Resources/25_10_30_084215.asset.meta similarity index 63% rename from Assets/Scenes/Garden/GardenScene/LightingData.asset.meta rename to Assets/Editor/TexturePack/Resources/25_10_30_084215.asset.meta index fa28ffa..204c5ab 100644 --- a/Assets/Scenes/Garden/GardenScene/LightingData.asset.meta +++ b/Assets/Editor/TexturePack/Resources/25_10_30_084215.asset.meta @@ -1,8 +1,8 @@ fileFormatVersion: 2 -guid: 4c499845f447c484fb847ad545b279b9 +guid: 2eb1332f37c785c4e95627dc33fa7db2 NativeFormatImporter: externalObjects: {} - mainObjectFileID: 112000000 + mainObjectFileID: 11400000 userData: assetBundleName: assetBundleVariant: diff --git a/Assets/Editor/TexturePack/Resources/25_11_05_042429.asset b/Assets/Editor/TexturePack/Resources/25_11_05_042429.asset new file mode 100644 index 0000000..1928b75 --- /dev/null +++ b/Assets/Editor/TexturePack/Resources/25_11_05_042429.asset @@ -0,0 +1,37 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 34bbc4130cb4b964aacff1ffb6ea7dd9, type: 3} + m_Name: 25_11_05_042429 + m_EditorClassIdentifier: + PackType: 0 + OriginTexture2TextureInfo: + m_Keys: + - {fileID: 2800000, guid: 62a1c70c49ee48949804a1b9704d98f4, type: 3} + - {fileID: 2800000, guid: 511247e6f2319624b9f36b17c140f4fb, type: 3} + m_Values: + - OriginTexture: {fileID: 2800000, guid: 62a1c70c49ee48949804a1b9704d98f4, type: 3} + ArrayIndex: 0 + Offset: + x: 0 + y: 0 + - OriginTexture: {fileID: 2800000, guid: 511247e6f2319624b9f36b17c140f4fb, type: 3} + ArrayIndex: 0 + Offset: + x: 0.5 + y: 0 + Textures: [] + TextureAtlas: {fileID: 0} + AtlasScale: 0.5 + TextureAtlasPath: + TextureArray: {fileID: 0} + TextureArrayPath: + IsNormalMap: 0 diff --git a/Assets/Editor/TexturePack/Resources/25_11_05_042429.asset.meta b/Assets/Editor/TexturePack/Resources/25_11_05_042429.asset.meta new file mode 100644 index 0000000..354f7b9 --- /dev/null +++ b/Assets/Editor/TexturePack/Resources/25_11_05_042429.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2c07cd70a3d89b3489cd8988b2e92709 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/TexturePack/Resources/25_11_05_042515.asset b/Assets/Editor/TexturePack/Resources/25_11_05_042515.asset new file mode 100644 index 0000000..8bb4f32 --- /dev/null +++ b/Assets/Editor/TexturePack/Resources/25_11_05_042515.asset @@ -0,0 +1,37 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 34bbc4130cb4b964aacff1ffb6ea7dd9, type: 3} + m_Name: 25_11_05_042515 + m_EditorClassIdentifier: + PackType: 0 + OriginTexture2TextureInfo: + m_Keys: + - {fileID: 2800000, guid: 0cdf7154483eb934e8f18f84c31ae2a6, type: 3} + - {fileID: 2800000, guid: a5bfb97ceb81b244cb97df741fe3953c, type: 3} + m_Values: + - OriginTexture: {fileID: 2800000, guid: 0cdf7154483eb934e8f18f84c31ae2a6, type: 3} + ArrayIndex: 0 + Offset: + x: 0 + y: 0 + - OriginTexture: {fileID: 2800000, guid: a5bfb97ceb81b244cb97df741fe3953c, type: 3} + ArrayIndex: 0 + Offset: + x: 0.5 + y: 0 + Textures: [] + TextureAtlas: {fileID: 0} + AtlasScale: 0.5 + TextureAtlasPath: + TextureArray: {fileID: 0} + TextureArrayPath: + IsNormalMap: 1 diff --git a/Assets/Editor/TexturePack/Resources/25_11_05_042515.asset.meta b/Assets/Editor/TexturePack/Resources/25_11_05_042515.asset.meta new file mode 100644 index 0000000..6f6cf30 --- /dev/null +++ b/Assets/Editor/TexturePack/Resources/25_11_05_042515.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f9d6ad6c436222942b84ebc5c42300ef +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/TexturePack/Resources/25_11_05_042628.asset b/Assets/Editor/TexturePack/Resources/25_11_05_042628.asset new file mode 100644 index 0000000..28d2d77 --- /dev/null +++ b/Assets/Editor/TexturePack/Resources/25_11_05_042628.asset @@ -0,0 +1,39 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 34bbc4130cb4b964aacff1ffb6ea7dd9, type: 3} + m_Name: 25_11_05_042628 + m_EditorClassIdentifier: + PackType: 0 + OriginTexture2TextureInfo: + m_Keys: + - {fileID: 2800000, guid: facfa14bd567c904583bd41b3fa67655, type: 3} + - {fileID: 2800000, guid: f424fe2441e9bbb408f606da9d5ea74c, type: 3} + m_Values: + - OriginTexture: {fileID: 2800000, guid: facfa14bd567c904583bd41b3fa67655, type: 3} + ArrayIndex: 0 + Offset: + x: 0.5 + y: 0 + - OriginTexture: {fileID: 2800000, guid: f424fe2441e9bbb408f606da9d5ea74c, type: 3} + ArrayIndex: 0 + Offset: + x: 0 + y: 0 + Textures: + - {fileID: 2800000, guid: f424fe2441e9bbb408f606da9d5ea74c, type: 3} + - {fileID: 2800000, guid: facfa14bd567c904583bd41b3fa67655, type: 3} + TextureAtlas: {fileID: 2800000, guid: ff4f3681a7495974b9475e47d0559608, type: 3} + AtlasScale: 0.5 + TextureAtlasPath: Assets/mask.png + TextureArray: {fileID: 0} + TextureArrayPath: + IsNormalMap: 0 diff --git a/Assets/Editor/TexturePack/Resources/25_11_05_042628.asset.meta b/Assets/Editor/TexturePack/Resources/25_11_05_042628.asset.meta new file mode 100644 index 0000000..8fffc49 --- /dev/null +++ b/Assets/Editor/TexturePack/Resources/25_11_05_042628.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d74cdc82d14d5d547bdd58c495dd0535 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/TexturePack/Resources/25_11_05_102946.asset b/Assets/Editor/TexturePack/Resources/25_11_05_102946.asset new file mode 100644 index 0000000..3a55be1 --- /dev/null +++ b/Assets/Editor/TexturePack/Resources/25_11_05_102946.asset @@ -0,0 +1,37 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 34bbc4130cb4b964aacff1ffb6ea7dd9, type: 3} + m_Name: 25_11_05_102946 + m_EditorClassIdentifier: + PackType: 1 + OriginTexture2TextureInfo: + m_Keys: + - {fileID: 2800000, guid: 0cdf7154483eb934e8f18f84c31ae2a6, type: 3} + - {fileID: 2800000, guid: a5bfb97ceb81b244cb97df741fe3953c, type: 3} + m_Values: + - OriginTexture: {fileID: 2800000, guid: 0cdf7154483eb934e8f18f84c31ae2a6, type: 3} + ArrayIndex: 0 + Offset: + x: 0 + y: 0 + - OriginTexture: {fileID: 2800000, guid: a5bfb97ceb81b244cb97df741fe3953c, type: 3} + ArrayIndex: 1 + Offset: + x: 0 + y: 0 + Textures: [] + TextureAtlas: {fileID: 0} + AtlasScale: 0.5 + TextureAtlasPath: + TextureArray: {fileID: 0} + TextureArrayPath: + IsNormalMap: 1 diff --git a/Assets/Editor/TexturePack/Resources/25_11_05_102946.asset.meta b/Assets/Editor/TexturePack/Resources/25_11_05_102946.asset.meta new file mode 100644 index 0000000..72fa4b3 --- /dev/null +++ b/Assets/Editor/TexturePack/Resources/25_11_05_102946.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: be0526f343db1e14da67810237489026 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/TexturePack/Resources/25_11_05_110641.asset b/Assets/Editor/TexturePack/Resources/25_11_05_110641.asset new file mode 100644 index 0000000..e6da0e5 --- /dev/null +++ b/Assets/Editor/TexturePack/Resources/25_11_05_110641.asset @@ -0,0 +1,37 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 34bbc4130cb4b964aacff1ffb6ea7dd9, type: 3} + m_Name: 25_11_05_110641 + m_EditorClassIdentifier: + PackType: 1 + OriginTexture2TextureInfo: + m_Keys: + - {fileID: 2800000, guid: 62a1c70c49ee48949804a1b9704d98f4, type: 3} + - {fileID: 2800000, guid: 511247e6f2319624b9f36b17c140f4fb, type: 3} + m_Values: + - OriginTexture: {fileID: 2800000, guid: 62a1c70c49ee48949804a1b9704d98f4, type: 3} + ArrayIndex: 0 + Offset: + x: 0 + y: 0 + - OriginTexture: {fileID: 2800000, guid: 511247e6f2319624b9f36b17c140f4fb, type: 3} + ArrayIndex: 1 + Offset: + x: 0 + y: 0 + Textures: [] + TextureAtlas: {fileID: 0} + AtlasScale: 0 + TextureAtlasPath: + TextureArray: {fileID: 0} + TextureArrayPath: + IsNormalMap: 0 diff --git a/Assets/Editor/TexturePack/Resources/25_11_05_110641.asset.meta b/Assets/Editor/TexturePack/Resources/25_11_05_110641.asset.meta new file mode 100644 index 0000000..33bdaf0 --- /dev/null +++ b/Assets/Editor/TexturePack/Resources/25_11_05_110641.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ec48692bce2cb484ea1c3dd477b35bd1 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/TexturePack/Resources/texture_map_index.asset b/Assets/Editor/TexturePack/Resources/texture_map_index.asset new file mode 100644 index 0000000..64f9cee --- /dev/null +++ b/Assets/Editor/TexturePack/Resources/texture_map_index.asset @@ -0,0 +1,23 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 139452af06b79914f9cc56d83913a7e2, type: 3} + m_Name: texture_map_index + m_EditorClassIdentifier: + ResultGuid2TextureMap: + m_Keys: [] + m_Values: [] + TextureGuid2TextureMap: + m_Keys: [] + m_Values: [] + TextureMap2TextureGuid: + m_Keys: [] + m_Values: [] diff --git a/Assets/Editor/TexturePack/Resources/texture_map_index.asset.meta b/Assets/Editor/TexturePack/Resources/texture_map_index.asset.meta new file mode 100644 index 0000000..272f4e3 --- /dev/null +++ b/Assets/Editor/TexturePack/Resources/texture_map_index.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 53d1cbf3326c0b34d8f7ecf86e03738f +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/TexturePack/TextureMapIndex.cs b/Assets/Editor/TexturePack/TextureMapIndex.cs new file mode 100644 index 0000000..4f18a99 --- /dev/null +++ b/Assets/Editor/TexturePack/TextureMapIndex.cs @@ -0,0 +1,38 @@ +using System.IO; +using UnityEditor; +using UnityEngine; +using UnityEngine.Rendering; + +namespace TexturePacker +{ + internal class TextureMapIndex : ScriptableObject + { + public SerializedDictionary ResultGuid2TextureMap; + public SerializedDictionary TextureGuid2TextureMap; + public SerializedDictionary TextureMap2TextureGuid; + + public static readonly string TextureMapIndexPath = $"{TextureMapInfo.TextureMapDir}/texture_map_index.asset"; + + private static TextureMapIndex instance; + + public static TextureMapIndex Instance + { + get + { + if(instance == null) + { + if(File.Exists(TextureMapIndexPath)) + { + instance = AssetDatabase.LoadAssetAtPath(TextureMapIndexPath); + } + else + { + instance = ScriptableObject.CreateInstance(); + AssetDatabase.CreateAsset(instance, TextureMapIndexPath); + } + } + return instance; + } + } + } +} diff --git a/Assets/Editor/TexturePack/TextureMapIndex.cs.meta b/Assets/Editor/TexturePack/TextureMapIndex.cs.meta new file mode 100644 index 0000000..2381cda --- /dev/null +++ b/Assets/Editor/TexturePack/TextureMapIndex.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 139452af06b79914f9cc56d83913a7e2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/TexturePack/TextureMapInfo.cs b/Assets/Editor/TexturePack/TextureMapInfo.cs new file mode 100644 index 0000000..fb4e5e3 --- /dev/null +++ b/Assets/Editor/TexturePack/TextureMapInfo.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Unity.Mathematics; +using UnityEditor; +using UnityEngine; +using UnityEngine.Rendering; + +namespace TexturePacker +{ + public sealed class TextureMapInfo : ScriptableObject + { + public const string TextureMapDir = "Assets/Editor/TexturePack/Resources"; + + [Serializable] + public struct TextureInfo + { + public Texture2D OriginTexture; + public int ArrayIndex; + public float2 Offset; + } + + [Serializable] + public enum EPackType + { + Atlas, + Array + } + + public EPackType PackType = EPackType.Atlas; + public SerializedDictionary OriginTexture2TextureInfo = new(); + public List Textures; + public Texture2D TextureAtlas; + public float AtlasScale; + public string TextureAtlasPath; + public Texture2DArray TextureArray; + public string TextureArrayPath; + public bool IsNormalMap; + + [ContextMenu("Test")] + private void Test() + { + Texture2D offsetTex = new Texture2D(Textures.Count, 1, TextureFormat.RG16, false); + for (int i = 0; i < Textures.Count; i++) + { + var tex = Textures[i]; + var info = OriginTexture2TextureInfo[tex]; + offsetTex.SetPixel(i, 0, new Color(info.Offset.x, info.Offset.y, 0)); + } + + var path = EditorUtility.SaveFilePanelInProject("保存offset图", "OffsetMap", "png", ""); + File.WriteAllBytes(path, offsetTex.EncodeToPNG()); + } + } + +} diff --git a/Assets/Editor/TexturePack/TextureMapInfo.cs.meta b/Assets/Editor/TexturePack/TextureMapInfo.cs.meta new file mode 100644 index 0000000..859372d --- /dev/null +++ b/Assets/Editor/TexturePack/TextureMapInfo.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 34bbc4130cb4b964aacff1ffb6ea7dd9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/TexturePack/TexturePackerEditor.cs b/Assets/Editor/TexturePack/TexturePackerEditor.cs new file mode 100644 index 0000000..d97c786 --- /dev/null +++ b/Assets/Editor/TexturePack/TexturePackerEditor.cs @@ -0,0 +1,735 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using TexturePacker; +using Unity.Mathematics; +using UnityEditor; +using UnityEngine; +using UnityEngine.Experimental.Rendering; +using UnityEngine.Rendering; +using UnityEngine.UIElements; + +public sealed class TexturePackerEditor : EditorWindow +{ + [SerializeField] + private VisualTreeAsset m_VisualTreeAsset = default; + private TextureMapInfo textureMapInfo; + + private Texture2D textureAtlas; + private Texture2DArray textureArray; + + private IMGUIContainer imageListContainer; + private List selectedTexs = new(); + private List texRects = new(); + + private Vector2 cellSize = new Vector2(100, 100); + private const int MaxArraySize = 255; + + private int selectIndex = -1; + private int selectIndexForMove = -1; + private Vector2 toolbarOffset = new Vector2(0, 35); + + private int atlasPadding = 0; + private static Func fnOpenPropertyEditor; + private int textureSize = 512; + private EditorWindow atlasPropertiesWindow = null; + private EditorWindow arrayPropertiesWindow = null; + private Label imgCntLabel = null; + private Label infoLabel = null; + private GraphicsFormat graphicsFormat = GraphicsFormat.R32G32B32A32_SFloat; + + public enum ETextureSize + { + _128 = 1 << 7, + _256 = 1 << 8, + _512 = 1 << 9, + _1024 = 1 << 10, + } + + static TexturePackerEditor() + { + var editorCore = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name.Equals("UnityEditor.CoreModule")).FirstOrDefault(); + var type = editorCore.GetType("UnityEditor.PropertyEditor"); + var methodInfo = type.GetMethod("OpenPropertyEditor", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, null, new Type[] { typeof(UnityEngine.Object), typeof(bool) }, null); + fnOpenPropertyEditor = methodInfo.CreateDelegate(typeof(Func)) as Func; + } + + [MenuItem("Tools/Performance/TexturePackerEditor")] + public static void OpenTexturePackerEditor() + { + TexturePackerEditor wnd = GetWindow(); + wnd.titleContent = new GUIContent("TexturePackerEditor"); + } + + [UnityEditor.Callbacks.OnOpenAsset(0)] + private static bool OnOpenTextureMapInfo(int instanceID, int line) + { + var textureMapInfo = EditorUtility.InstanceIDToObject(instanceID) as TextureMapInfo; + if(!textureMapInfo) + { + return false; + } + + TexturePackerEditor wnd = GetWindow(); + wnd.titleContent = new GUIContent("TexturePackerEditor"); + wnd.InitWithTextureMapInfo(textureMapInfo); + EditorApplication.delayCall += () => + { + wnd.UpdateResult(); + }; + return false; + } + + private static readonly Color btNormalColor = ColorUtils.ToRGBA(0xFF585858); + private static readonly Color btClikedColor = ColorUtils.ToRGBA(0xFF46607C); + + public void CreateGUI() + { + // Each editor window contains a root VisualElement object + VisualElement root = rootVisualElement; + + // Instantiate UXML + VisualElement labelFromUXML = m_VisualTreeAsset.Instantiate(); + root.Add(labelFromUXML); + var btArray = root.Q