diff --git a/Assets/Editor/TexturePack/Resources/test.png b/Assets/Editor/TexturePack/Resources/test.png new file mode 100644 index 0000000..ea5574e Binary files /dev/null and b/Assets/Editor/TexturePack/Resources/test.png differ diff --git a/Assets/Editor/TexturePack/Resources/test.png.meta b/Assets/Editor/TexturePack/Resources/test.png.meta new file mode 100644 index 0000000..98afef5 --- /dev/null +++ b/Assets/Editor/TexturePack/Resources/test.png.meta @@ -0,0 +1,114 @@ +fileFormatVersion: 2 +guid: f7da50a7dd2427945a04ecfb0815a421 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 13 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0 + mipMapFadeDistanceStart: 0 + mipMapFadeDistanceEnd: 0 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 0 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 0 + maxTextureSize: 0 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: 0 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 0 + spriteMode: 0 + spriteExtrude: 0 + spriteMeshType: 0 + alignment: 0 + spritePivot: {x: 0, y: 0} + spritePixelsToUnits: 0 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 0 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: 0 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/TexturePack/TextureMapInfo.cs b/Assets/Editor/TexturePack/TextureMapInfo.cs index fb4e5e3..0ded9a5 100644 --- a/Assets/Editor/TexturePack/TextureMapInfo.cs +++ b/Assets/Editor/TexturePack/TextureMapInfo.cs @@ -30,27 +30,13 @@ namespace TexturePacker public EPackType PackType = EPackType.Atlas; public SerializedDictionary OriginTexture2TextureInfo = new(); public List Textures; + public List Fbxs; 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/TexturePackerEditor.cs b/Assets/Editor/TexturePack/TexturePackerEditor.cs index d97c786..79af337 100644 --- a/Assets/Editor/TexturePack/TexturePackerEditor.cs +++ b/Assets/Editor/TexturePack/TexturePackerEditor.cs @@ -1,11 +1,15 @@ +using log4net.Util; using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Linq.Expressions; using System.Reflection; using TexturePacker; +using Unity.Collections; using Unity.Mathematics; using UnityEditor; +using UnityEditor.Formats.Fbx.Exporter; using UnityEngine; using UnityEngine.Experimental.Rendering; using UnityEngine.Rendering; @@ -24,6 +28,12 @@ public sealed class TexturePackerEditor : EditorWindow private List selectedTexs = new(); private List texRects = new(); + private static Type gameObjectInspectorType; + private List gameObjectInspectorView = new(); + private List models = new(); + private List modelRects = new(); + private Button btApplyMesh; + private Vector2 cellSize = new Vector2(100, 100); private const int MaxArraySize = 255; @@ -40,6 +50,8 @@ public sealed class TexturePackerEditor : EditorWindow private Label infoLabel = null; private GraphicsFormat graphicsFormat = GraphicsFormat.R32G32B32A32_SFloat; + private bool dockPreviewWindowFail = false; + public enum ETextureSize { _128 = 1 << 7, @@ -48,26 +60,105 @@ public sealed class TexturePackerEditor : EditorWindow _1024 = 1 << 10, } + static readonly object fbxExportSetting = null; + static Delegate exportObjectFunc; + 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; + gameObjectInspectorType = editorCore.GetType("UnityEditor.GameObjectInspector"); + + var fbxAssembly = Assembly.GetAssembly(typeof(ModelExporter)); + + var exportMethodInfo = typeof(ModelExporter).GetMethod("ExportObject", BindingFlags.NonPublic | BindingFlags.Static); + exportObjectFunc = exportMethodInfo.CreateDelegate(Expression.GetDelegateType(exportMethodInfo.GetParameters().Select(p => p.ParameterType).Concat(new[] { exportMethodInfo.ReturnType }).ToArray())); + Type exportModelSettingsSerialize = fbxAssembly.GetType("UnityEditor.Formats.Fbx.Exporter.ExportModelSettingsSerialize"); + fbxExportSetting = Activator.CreateInstance(exportModelSettingsSerialize); + + foreach (var item in exportModelSettingsSerialize.GetMethods().Union(exportModelSettingsSerialize.BaseType.GetMethods())) + { + switch (item.Name) + { + case "SetExportFormat": + { + item.Invoke(fbxExportSetting, new object[] { 1 }); + item.Invoke(fbxExportSetting, new object[] { Enum.Parse(fbxAssembly.GetType("UnityEditor.Formats.Fbx.Exporter.ExportSettings+ExportFormat"), "1") }); + break; + } + case "SetAnimatedSkinnedMesh": + { + item.Invoke(fbxExportSetting, new object[] { false }); + break; + } + case "SetUseMayaCompatibleNames": + { + item.Invoke(fbxExportSetting, new object[] { false }); + break; + } + case "SetModelAnimIncludeOption": + { + + item.Invoke(fbxExportSetting, new object[] { Enum.Parse(fbxAssembly.GetType("UnityEditor.Formats.Fbx.Exporter.ExportSettings+Include"), "0") }); + break; + } + case "SetLODExportType": + { + item.Invoke(fbxExportSetting, new object[] { Enum.Parse(fbxAssembly.GetType("UnityEditor.Formats.Fbx.Exporter.ExportSettings+LODExportType"), "0") }); + break; + } + case "SetEmbedTextures": + { + item.Invoke(fbxExportSetting, new object[] { false }); + break; + } + case "SetPreserveImportSettings": + { + item.Invoke(fbxExportSetting, new object[] { false }); + break; + } + case "SetKeepInstances": + { + item.Invoke(fbxExportSetting, new object[] { false }); + break; + } + case "SetExportUnredererd": + { + item.Invoke(fbxExportSetting, new object[] { false }); + break; + } + default: + break; + } + } } [MenuItem("Tools/Performance/TexturePackerEditor")] public static void OpenTexturePackerEditor() { - TexturePackerEditor wnd = GetWindow(); + TexturePackerEditor wnd = CreateInstance(); wnd.titleContent = new GUIContent("TexturePackerEditor"); + wnd.Show(); + } + + public static void OpenTexturePackerEditor(Texture2D[] textures) + { + TexturePackerEditor wnd = CreateInstance(); + wnd.titleContent = new GUIContent("TexturePackerEditor"); + for (int i = 0; i < textures.Length; i++) + { + wnd.AddTexture(textures[i]); + } + wnd.Show(); } [UnityEditor.Callbacks.OnOpenAsset(0)] private static bool OnOpenTextureMapInfo(int instanceID, int line) { var textureMapInfo = EditorUtility.InstanceIDToObject(instanceID) as TextureMapInfo; - if(!textureMapInfo) + if (!textureMapInfo) { return false; } @@ -96,6 +187,8 @@ public sealed class TexturePackerEditor : EditorWindow var btArray = root.Q