Init
This commit is contained in:
93
Assets/Scripts/Editor/BuildTool.cs
Normal file
93
Assets/Scripts/Editor/BuildTool.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using YooAsset.Editor;
|
||||
using YooAsset;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Build.Pipeline;
|
||||
|
||||
public class BuildTool
|
||||
{
|
||||
[MenuItem("Tools/<2F><><EFBFBD><EFBFBD>Preload")]
|
||||
public static void BuildPreload()
|
||||
{
|
||||
CopyHotDll.CopyPreloadDll2Byte();
|
||||
ExecuteBuild("Preload",EBuildPipeline.ScriptableBuildPipeline, EditorUserBuildSettings.activeBuildTarget,EFileNameStyle.BundleName_HashName,EBuildinFileCopyOption.ClearAndCopyAll);
|
||||
Debug.Log($"<22><><EFBFBD><EFBFBD>Preload<61><64><EFBFBD><EFBFBD>");
|
||||
}
|
||||
[MenuItem("Tools/<2F><><EFBFBD><EFBFBD>Main %G")]
|
||||
public static void BuildMain()
|
||||
{
|
||||
CopyHotDll.CopyMainDll2Byte();
|
||||
ExecuteBuild("Main", EBuildPipeline.ScriptableBuildPipeline, EditorUserBuildSettings.activeBuildTarget, EFileNameStyle.BundleName_HashName, EBuildinFileCopyOption.None);
|
||||
Debug.Log($"<22><><EFBFBD><EFBFBD>Main<69><6E><EFBFBD><EFBFBD>");
|
||||
}
|
||||
[MenuItem("Tools/ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")]
|
||||
public static void BuildAll()
|
||||
{
|
||||
BuildPreload();
|
||||
BuildMain();
|
||||
}
|
||||
|
||||
public static void ExecuteBuild(string PackageName, EBuildPipeline BuildPipeline, BuildTarget BuildTarget, EFileNameStyle fileNameStyle, EBuildinFileCopyOption buildinFileCopyOption)
|
||||
{
|
||||
var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline);
|
||||
var compressOption = AssetBundleBuilderSetting.GetPackageCompressOption(PackageName, BuildPipeline);
|
||||
var clearBuildCache = AssetBundleBuilderSetting.GetPackageClearBuildCache(PackageName, BuildPipeline);
|
||||
var useAssetDependencyDB = AssetBundleBuilderSetting.GetPackageUseAssetDependencyDB(PackageName, BuildPipeline);
|
||||
var builtinShaderBundleName = GetBuiltinShaderBundleName(PackageName);
|
||||
|
||||
ScriptableBuildParameters buildParameters = new ScriptableBuildParameters();
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = BuildPipeline.ToString();
|
||||
buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle;
|
||||
buildParameters.BuildTarget = BuildTarget;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = GetPackageVersion();
|
||||
buildParameters.EnableSharePackRule = true;
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.FileNameStyle = fileNameStyle;
|
||||
buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
|
||||
buildParameters.BuildinFileCopyParams = buildinFileCopyParams;
|
||||
buildParameters.CompressOption = compressOption;
|
||||
buildParameters.ClearBuildCacheFiles = clearBuildCache;
|
||||
buildParameters.UseAssetDependencyDB = useAssetDependencyDB;
|
||||
buildParameters.BuiltinShadersBundleName = builtinShaderBundleName;
|
||||
buildParameters.EncryptionServices = CreateEncryptionInstance(PackageName, BuildPipeline);
|
||||
|
||||
ScriptableBuildPipeline pipeline = new ScriptableBuildPipeline();
|
||||
var buildResult = pipeline.Run(buildParameters, true);
|
||||
if (buildResult.Success)
|
||||
EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
|
||||
}
|
||||
|
||||
public static string GetPackageVersion()
|
||||
{
|
||||
int totalMinutes = DateTime.Now.Hour * 60 + DateTime.Now.Minute;
|
||||
return DateTime.Now.ToString("yyyy-MM-dd") + "-" + totalMinutes;
|
||||
}
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// ע<>⣺<EFBFBD><E2A3BA><EFBFBD>Զ<EFBFBD><D4B6>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>£<EFBFBD>
|
||||
/// </summary>
|
||||
public static string GetBuiltinShaderBundleName(string PackageName)
|
||||
{
|
||||
var uniqueBundleName = AssetBundleCollectorSettingData.Setting.UniqueBundleName;
|
||||
var packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||
return packRuleResult.GetBundleName(PackageName, uniqueBundleName);
|
||||
}
|
||||
|
||||
public static IEncryptionServices CreateEncryptionInstance(string PackageName, EBuildPipeline BuildPipeline)
|
||||
{
|
||||
var encyptionClassName = AssetBundleBuilderSetting.GetPackageEncyptionClassName(PackageName, BuildPipeline);
|
||||
var encryptionClassTypes = EditorTools.GetAssignableTypes(typeof(IEncryptionServices));
|
||||
var classType = encryptionClassTypes.Find(x => x.FullName.Equals(encyptionClassName));
|
||||
if (classType != null)
|
||||
return (IEncryptionServices)Activator.CreateInstance(classType);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
Assets/Scripts/Editor/BuildTool.cs.meta
Normal file
11
Assets/Scripts/Editor/BuildTool.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e57cfc5fd962f5746a2c991575785b97
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
63
Assets/Scripts/Editor/CopyHotDll.cs
Normal file
63
Assets/Scripts/Editor/CopyHotDll.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
|
||||
public class CopyHotDll
|
||||
{
|
||||
[MenuItem("Tools/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PreloadDll")]
|
||||
public static void CopyPreloadDll2Byte()
|
||||
{
|
||||
HybridCLR.Editor.Commands.CompileDllCommand.CompileDllActiveBuildTarget();
|
||||
string sourceDir = $"{Application.dataPath.Replace("/Assets", "")}/HybridCLRData/HotUpdateDlls/{UnityEditor.EditorUserBuildSettings.activeBuildTarget}/Preload.dll";
|
||||
string destDir = $"{Application.dataPath}/Res/Preload/HotUpdateDll/Preload.bytes";
|
||||
if (File.Exists(destDir))
|
||||
{
|
||||
File.Delete(destDir);
|
||||
}
|
||||
File.Copy(sourceDir, destDir);
|
||||
AssetDatabase.Refresh();
|
||||
Debug.Log($"copy {sourceDir} to {destDir}");
|
||||
}
|
||||
[MenuItem("Tools/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>MainDll")]
|
||||
public static void CopyMainDll2Byte()
|
||||
{
|
||||
HybridCLR.Editor.Commands.CompileDllCommand.CompileDllActiveBuildTarget();
|
||||
string sourceDir = $"{Application.dataPath.Replace("/Assets", "")}/HybridCLRData/HotUpdateDlls/{UnityEditor.EditorUserBuildSettings.activeBuildTarget}/Main.dll";
|
||||
string destDir = $"{Application.dataPath}/Res/Main/HotUpdateDll/Main.bytes";
|
||||
if (File.Exists(destDir))
|
||||
{
|
||||
File.Delete(destDir);
|
||||
}
|
||||
File.Copy(sourceDir, destDir);
|
||||
AssetDatabase.Refresh();
|
||||
Debug.Log($"copy {sourceDir} to {destDir}");
|
||||
}
|
||||
[MenuItem("Tools/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɲ<EFBFBD><C9B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ")]
|
||||
public static void CopyDepDll2Byte()
|
||||
{
|
||||
HybridCLR.Editor.Commands.CompileDllCommand.CompileDllActiveBuildTarget();
|
||||
string sourceDir = $"{Application.dataPath.Replace("/Assets", "")}/HybridCLRData/AssembliesPostIl2CppStrip/{UnityEditor.EditorUserBuildSettings.activeBuildTarget}/";
|
||||
string destDir = $"{Application.dataPath}/Res/Main/HotUpdateDll/";
|
||||
foreach (string dll in Boot.Inst.DepDlls)
|
||||
{
|
||||
string sourcePath = $"{sourceDir}/{dll}";
|
||||
string destPath = $"{destDir}/{dll}.bytes";
|
||||
if (File.Exists(sourcePath))
|
||||
{
|
||||
if (File.Exists(destPath))
|
||||
{
|
||||
File.Delete(destPath);
|
||||
}
|
||||
File.Copy(sourcePath, destPath);
|
||||
AssetDatabase.Refresh();
|
||||
Debug.Log($"copy {sourcePath} to {destPath}");
|
||||
}
|
||||
}
|
||||
Debug.Log("copy over");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Editor/CopyHotDll.cs.meta
Normal file
11
Assets/Scripts/Editor/CopyHotDll.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f880c60e7ea774c47a093b013d9469db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/Scripts/Editor/MyScripts.Editor.asmdef
Normal file
21
Assets/Scripts/Editor/MyScripts.Editor.asmdef
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "MyScripts.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
||||
"GUID:4d1926c9df5b052469a1c63448b7609a",
|
||||
"GUID:2373f786d14518f44b0f475db77ba4de",
|
||||
"GUID:8804cd4b3fef1e041ad4f6c94ec49e0c"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Assets/Scripts/Editor/MyScripts.Editor.asmdef.meta
Normal file
7
Assets/Scripts/Editor/MyScripts.Editor.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 632de22e4f40cf04bbaa1b1a2ded480d
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
67
Assets/Scripts/Editor/SchemaTools.cs
Normal file
67
Assets/Scripts/Editor/SchemaTools.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using YooAsset.Editor;
|
||||
|
||||
public class SchemaTools
|
||||
{
|
||||
/// <summary>
|
||||
/// 通用扫描快捷方法
|
||||
/// </summary>
|
||||
public static List<ReportElement> ScanAssets(string[] scanAssetList, System.Func<string, ReportElement> scanFun, int unloadAssetLimit = int.MaxValue)
|
||||
{
|
||||
int scanNumber = 0;
|
||||
int progressCount = 0;
|
||||
int totalCount = scanAssetList.Length;
|
||||
List<ReportElement> results = new List<ReportElement>(totalCount);
|
||||
|
||||
EditorTools.ClearProgressBar();
|
||||
foreach (string assetPath in scanAssetList)
|
||||
{
|
||||
scanNumber++;
|
||||
progressCount++;
|
||||
EditorTools.DisplayProgressBar("扫描中...", progressCount, totalCount);
|
||||
var scanResult = scanFun.Invoke(assetPath);
|
||||
if (scanResult != null)
|
||||
results.Add(scanResult);
|
||||
|
||||
// 释放编辑器未使用的资源
|
||||
if (scanNumber >= unloadAssetLimit)
|
||||
{
|
||||
scanNumber = 0;
|
||||
EditorUtility.UnloadUnusedAssetsImmediate(true);
|
||||
}
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通用修复快捷方法
|
||||
/// </summary>
|
||||
public static void FixAssets(List<ReportElement> fixAssetList, System.Action<ReportElement> fixFun, int unloadAssetLimit = int.MaxValue)
|
||||
{
|
||||
int scanNumber = 0;
|
||||
int totalCount = fixAssetList.Count;
|
||||
int progressCount = 0;
|
||||
EditorTools.ClearProgressBar();
|
||||
foreach (var scanResult in fixAssetList)
|
||||
{
|
||||
scanNumber++;
|
||||
progressCount++;
|
||||
EditorTools.DisplayProgressBar("修复中...", progressCount, totalCount);
|
||||
fixFun.Invoke(scanResult);
|
||||
|
||||
// 释放编辑器未使用的资源
|
||||
if (scanNumber >= unloadAssetLimit)
|
||||
{
|
||||
scanNumber = 0;
|
||||
EditorUtility.UnloadUnusedAssetsImmediate(true);
|
||||
}
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Editor/SchemaTools.cs.meta
Normal file
11
Assets/Scripts/Editor/SchemaTools.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97a68688a58fbb24ba31cd80e808d315
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
198
Assets/Scripts/Editor/TextureSchema.cs
Normal file
198
Assets/Scripts/Editor/TextureSchema.cs
Normal file
@@ -0,0 +1,198 @@
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using YooAsset.Editor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
[CreateAssetMenu(fileName = "TextureSchema", menuName = "YooAssetArt/Create TextureSchema")]
|
||||
public class TextureSchema : ScannerSchema
|
||||
{
|
||||
/// <summary>
|
||||
/// 图片最大宽度
|
||||
/// </summary>
|
||||
public int MaxWidth = 1024;
|
||||
|
||||
/// <summary>
|
||||
/// 图片最大高度
|
||||
/// </summary>
|
||||
public int MaxHeight = 1024;
|
||||
|
||||
/// <summary>
|
||||
/// 测试列表
|
||||
/// </summary>
|
||||
public List<string> TestStringValues = new List<string>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户指南信息
|
||||
/// </summary>
|
||||
public override string GetUserGuide()
|
||||
{
|
||||
return "规则介绍:检测图片的格式,尺寸";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 运行生成扫描报告
|
||||
/// </summary>
|
||||
public override ScanReport RunScanner(AssetArtScanner scanner)
|
||||
{
|
||||
// 创建扫描报告
|
||||
string name = "扫描所有纹理资产";
|
||||
string desc = GetUserGuide();
|
||||
var report = new ScanReport(name, desc);
|
||||
report.AddHeader("资源路径", 600, 500, 1000).SetStretchable().SetSearchable().SetSortable().SetCounter().SetHeaderType(EHeaderType.AssetPath);
|
||||
report.AddHeader("图片宽度", 100).SetSortable().SetHeaderType(EHeaderType.LongValue);
|
||||
report.AddHeader("图片高度", 100).SetSortable().SetHeaderType(EHeaderType.LongValue);
|
||||
report.AddHeader("内存大小", 120).SetSortable().SetUnits("bytes").SetHeaderType(EHeaderType.LongValue);
|
||||
report.AddHeader("苹果格式", 100);
|
||||
report.AddHeader("安卓格式", 100);
|
||||
report.AddHeader("错误信息", 500).SetStretchable();
|
||||
|
||||
// 获取扫描资源集合
|
||||
var searchDirectorys = scanner.Collectors.Select(c => { return c.CollectPath; });
|
||||
string[] findAssets = EditorTools.FindAssets(EAssetSearchType.Texture, searchDirectorys.ToArray());
|
||||
|
||||
// 开始扫描资源集合
|
||||
var results = SchemaTools.ScanAssets(findAssets, ScanAssetInternal);
|
||||
report.ReportElements.AddRange(results);
|
||||
return report;
|
||||
}
|
||||
private ReportElement ScanAssetInternal(string assetPath)
|
||||
{
|
||||
var importer = TextureTools.GetAssetImporter(assetPath);
|
||||
if (importer == null)
|
||||
return null;
|
||||
|
||||
// 加载纹理对象
|
||||
var texture = AssetDatabase.LoadAssetAtPath<Texture>(assetPath);
|
||||
var assetGUID = AssetDatabase.AssetPathToGUID(assetPath);
|
||||
var iosFormat = TextureTools.GetPlatformIOSFormat(importer);
|
||||
var androidFormat = TextureTools.GetPlatformAndroidFormat(importer);
|
||||
var memorySize = TextureTools.GetStorageMemorySize(texture);
|
||||
|
||||
// 获取错误信息
|
||||
string errorInfo = string.Empty;
|
||||
{
|
||||
// 苹果格式
|
||||
if (iosFormat != TextureImporterFormat.ASTC_4x4)
|
||||
{
|
||||
errorInfo += " | ";
|
||||
errorInfo += "苹果格式不对";
|
||||
}
|
||||
|
||||
// 安卓格式
|
||||
if (androidFormat != TextureImporterFormat.ASTC_4x4)
|
||||
{
|
||||
errorInfo += " | ";
|
||||
errorInfo += "安卓格式不对";
|
||||
}
|
||||
|
||||
// 多级纹理
|
||||
if (importer.isReadable)
|
||||
{
|
||||
errorInfo += " | ";
|
||||
errorInfo += "开启了可读写";
|
||||
}
|
||||
|
||||
// 超大纹理
|
||||
if (texture.width > MaxWidth || texture.height > MaxHeight)
|
||||
{
|
||||
errorInfo += " | ";
|
||||
errorInfo += "超大纹理";
|
||||
}
|
||||
}
|
||||
|
||||
// 添加扫描信息
|
||||
ReportElement result = new ReportElement(assetGUID);
|
||||
result.AddScanInfo("资源路径", assetPath);
|
||||
result.AddScanInfo("图片宽度", texture.width);
|
||||
result.AddScanInfo("图片高度", texture.height);
|
||||
result.AddScanInfo("内存大小", memorySize);
|
||||
result.AddScanInfo("苹果格式", iosFormat.ToString());
|
||||
result.AddScanInfo("安卓格式", androidFormat.ToString());
|
||||
result.AddScanInfo("错误信息", errorInfo);
|
||||
|
||||
// 判断是否通过
|
||||
result.Passes = string.IsNullOrEmpty(errorInfo);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修复扫描结果
|
||||
/// </summary>
|
||||
public override void FixResult(List<ReportElement> fixList)
|
||||
{
|
||||
SchemaTools.FixAssets(fixList, FixAssetInternal);
|
||||
}
|
||||
private void FixAssetInternal(ReportElement result)
|
||||
{
|
||||
var scanInfo = result.GetScanInfo("资源路径");
|
||||
var assetPath = scanInfo.ScanInfo;
|
||||
var importer = TextureTools.GetAssetImporter(assetPath);
|
||||
if (importer == null)
|
||||
return;
|
||||
|
||||
// 苹果格式
|
||||
var iosPlatformSetting = TextureTools.GetPlatformIOSSettings(importer);
|
||||
iosPlatformSetting.format = TextureImporterFormat.ASTC_4x4;
|
||||
iosPlatformSetting.overridden = true;
|
||||
|
||||
// 安卓格式
|
||||
var androidPlatformSetting = TextureTools.GetPlatformAndroidSettings(importer);
|
||||
androidPlatformSetting.format = TextureImporterFormat.ASTC_4x4;
|
||||
androidPlatformSetting.overridden = true;
|
||||
|
||||
// 可读写
|
||||
importer.isReadable = false;
|
||||
|
||||
// 保存配置
|
||||
importer.SetPlatformTextureSettings(iosPlatformSetting);
|
||||
importer.SetPlatformTextureSettings(androidPlatformSetting);
|
||||
importer.SaveAndReimport();
|
||||
Debug.Log($"修复了 : {assetPath}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建检视面板对
|
||||
/// </summary>
|
||||
public override SchemaInspector CreateInspector()
|
||||
{
|
||||
var container = new VisualElement();
|
||||
|
||||
// 图片最大宽度
|
||||
var maxWidthField = new IntegerField();
|
||||
maxWidthField.label = "图片最大宽度";
|
||||
maxWidthField.SetValueWithoutNotify(MaxWidth);
|
||||
maxWidthField.RegisterValueChangedCallback((evt) =>
|
||||
{
|
||||
MaxWidth = evt.newValue;
|
||||
});
|
||||
container.Add(maxWidthField);
|
||||
|
||||
// 图片最大高度
|
||||
var maxHeightField = new IntegerField();
|
||||
maxHeightField.label = "图片最大高度";
|
||||
maxHeightField.SetValueWithoutNotify(MaxHeight);
|
||||
maxHeightField.RegisterValueChangedCallback((evt) =>
|
||||
{
|
||||
MaxHeight = evt.newValue;
|
||||
});
|
||||
container.Add(maxHeightField);
|
||||
|
||||
// 创建测试列表
|
||||
#if UNITY_2021_3_OR_NEWER
|
||||
ReorderableListView reorderableListView = new ReorderableListView();
|
||||
reorderableListView.SourceData = TestStringValues;
|
||||
reorderableListView.HeaderName = "测试列表";
|
||||
container.Add(reorderableListView);
|
||||
#endif
|
||||
|
||||
SchemaInspector inspector = new SchemaInspector(container);
|
||||
return inspector;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
11
Assets/Scripts/Editor/TextureSchema.cs.meta
Normal file
11
Assets/Scripts/Editor/TextureSchema.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01b3d3fde6899514396008e1e4f6693b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
104
Assets/Scripts/Editor/TextureTools.cs
Normal file
104
Assets/Scripts/Editor/TextureTools.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using YooAsset.Editor;
|
||||
|
||||
public class TextureTools
|
||||
{
|
||||
/// <summary>
|
||||
/// POT尺寸检测
|
||||
/// </summary>
|
||||
public static bool IsPowerOfTwo(Texture tex)
|
||||
{
|
||||
if (Mathf.IsPowerOfTwo(tex.width) == false)
|
||||
return false;
|
||||
|
||||
if (Mathf.IsPowerOfTwo(tex.height) == false)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取纹理运行时内存大小
|
||||
/// </summary>
|
||||
public static long GetStorageMemorySize(Texture tex)
|
||||
{
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
var assembly = typeof(AssetDatabase).Assembly;
|
||||
var type = assembly.GetType("UnityEditor.TextureUtil");
|
||||
long size = (long)EditorTools.InvokePublicStaticMethod(type, "GetStorageMemorySizeLong", tex);
|
||||
return size;
|
||||
#else
|
||||
var assembly = typeof(AssetDatabase).Assembly;
|
||||
var type = assembly.GetType("UnityEditor.TextureUtil");
|
||||
int size = (int)EditorTools.InvokePublicStaticMethod(type, "GetStorageMemorySize", tex);
|
||||
return size;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前平台纹理的格式
|
||||
/// </summary>
|
||||
public static TextureFormat GetCurrentPlatformTextureFormat(Texture tex)
|
||||
{
|
||||
var assembly = typeof(AssetDatabase).Assembly;
|
||||
var type = assembly.GetType("UnityEditor.TextureUtil");
|
||||
TextureFormat format = (TextureFormat)EditorTools.InvokePublicStaticMethod(type, "GetTextureFormat", tex);
|
||||
return format;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取纹理的导入器
|
||||
/// </summary>
|
||||
public static TextureImporter GetAssetImporter(string assetPath)
|
||||
{
|
||||
TextureImporter importer = AssetImporter.GetAtPath(assetPath) as TextureImporter;
|
||||
if (importer == null)
|
||||
Debug.LogWarning($"Failed to load TextureImporter : {assetPath}");
|
||||
return importer;
|
||||
}
|
||||
|
||||
public static TextureImporterPlatformSettings GetPlatformPCSettings(TextureImporter importer)
|
||||
{
|
||||
TextureImporterPlatformSettings platformSetting = importer.GetPlatformTextureSettings("Standalone");
|
||||
return platformSetting;
|
||||
}
|
||||
public static TextureImporterPlatformSettings GetPlatformIOSSettings(TextureImporter importer)
|
||||
{
|
||||
TextureImporterPlatformSettings platformSetting = importer.GetPlatformTextureSettings("iPhone");
|
||||
return platformSetting;
|
||||
}
|
||||
public static TextureImporterPlatformSettings GetPlatformAndroidSettings(TextureImporter importer)
|
||||
{
|
||||
TextureImporterPlatformSettings platformSetting = importer.GetPlatformTextureSettings("Android");
|
||||
return platformSetting;
|
||||
}
|
||||
|
||||
public static TextureImporterFormat GetPlatformPCFormat(TextureImporter importer)
|
||||
{
|
||||
TextureImporterPlatformSettings platformSetting = GetPlatformPCSettings(importer);
|
||||
var format = platformSetting.format;
|
||||
if (format.ToString().StartsWith("Automatic"))
|
||||
format = importer.GetAutomaticFormat("Standalone");
|
||||
return format;
|
||||
}
|
||||
public static TextureImporterFormat GetPlatformIOSFormat(TextureImporter importer)
|
||||
{
|
||||
TextureImporterPlatformSettings platformSetting = GetPlatformIOSSettings(importer);
|
||||
var format = platformSetting.format;
|
||||
if (format.ToString().StartsWith("Automatic"))
|
||||
format = importer.GetAutomaticFormat("iPhone");
|
||||
return format;
|
||||
}
|
||||
public static TextureImporterFormat GetPlatformAndroidFormat(TextureImporter importer)
|
||||
{
|
||||
TextureImporterPlatformSettings platformSetting = GetPlatformAndroidSettings(importer);
|
||||
var format = platformSetting.format;
|
||||
if (format.ToString().StartsWith("Automatic"))
|
||||
format = importer.GetAutomaticFormat("Android");
|
||||
return format;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Editor/TextureTools.cs.meta
Normal file
11
Assets/Scripts/Editor/TextureTools.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58de59cc0b28bb1468c32bfa606d999d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user