[Obfuscator] Rename : nameTranslation.txt
Unity 2021.3.32f1
Obfuscator 3.11.6
----
Obfuscator에 난독화 기능을 쓸 때,
난독화 전/후 Naming 매칭 리스트를 뽑아주는 옵션이 있다.(아래 스샷 참조)
체크하면 기본 파일명이 nameTranslation.txt인데 빌드 할 때마다 덮어버리니 관리가 안돼서 빌드마다 별도로 만들어질 수 있도록 PostProcess로 파일명을 Rename 하도록 처리했다.
아래 소스를 프로젝트에 추가하면,
[Android] namteTranslation.txt 파일을 빌드 파일명에 매칭해서 자동으로 변경해준다.
ex) 빌드 파일명 : abc_v1.0.0.apk
변경되는 파일명 : abc_v1.0.0.apk_ namteTranslation.txt
[iOS] iOS는 빌드 시점에 파일명이 지정되는게 아니라서 별도의 조합으로 진행되도록 했다.
ex) abc_live_1.0.0(100)_20231206_183400_iOS_nameTranslation.txt
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor.Callbacks;
using System;
/// <summary>
/// [PostProcess] Obfuscator : Rename nameTranslation.txt -> {BuildFileName.ext}_nameTranslation.txt
/// </summary>
public sealed class PostProcessBuild_Obfuscator_NameTransition_Renamer : IPreprocessBuildWithReport, IPostprocessBuildWithReport
{
public int callbackOrder => 0;
private static readonly string m_strNameTranslation_Src = "nameTranslation"; // Obfuscator 기본값
private static readonly string m_strExt_txt = "txt";
public void OnPreprocessBuild(BuildReport report)
{
// 1. ./BUILD_PATH/nameTranslation.txt 파일 유무 체크
// 2. 있으면 - Delete(Clear)
string strBuildPath = Path.GetDirectoryName(report.summary.outputPath);
string strNameTranslation_txt_Src = string.Format("{0}/{1}.{2}", strBuildPath, m_strNameTranslation_Src, m_strExt_txt);
if (true == File.Exists(strNameTranslation_txt_Src))
{
File.Delete(strNameTranslation_txt_Src);
Debug.LogWarningFormat("[Delete] {0}", strNameTranslation_txt_Src);
}
}
public void OnPostprocessBuild(BuildReport report)
{
Debug.LogWarningFormat("[OnPostprocessBuild][platform] {0} [pathToBuildProject] {1}", report.summary.platform, report.summary.outputPath);
string strBuildPath = Path.GetDirectoryName(report.summary.outputPath);
string strBuildFileName_with_Ext = Path.GetFileName(report.summary.outputPath);
string strNameTranslation_txt_Src = string.Empty;
string strNameTranslation_txt_Dest = string.Empty;
string strLunarConsole = "";
if (true == LunarConsolePluginInternal.LunarConsoleConfig.consoleEnabled)
{
strLunarConsole = string.Format("_LunarConsole");
}
switch (report.summary.platform)
{
case BuildTarget.Android:
{
strNameTranslation_txt_Src = string.Format("{0}/{1}.{2}", strBuildPath, m_strNameTranslation_Src, m_strExt_txt);
// Build File과 매칭하기 쉽도록
// BuildFileName.ext_nameTranslation.txt 형태로 Dest 생성
strNameTranslation_txt_Dest = string.Format("{0}/{1}_{2}.{3}", strBuildPath, strBuildFileName_with_Ext, m_strNameTranslation_Src, m_strExt_txt);
}
break;
case BuildTarget.iOS:
{
strNameTranslation_txt_Src = string.Format("{0}/{1}.{2}", strBuildPath, m_strNameTranslation_Src, m_strExt_txt);
string strProductName = string.Format("{0}", Application.productName.Replace(" ", ""));
string strServer = string.Format("{0}", Anne.ClientSettings.ServerType.ToString()); // 이 부분은 본인에 맞게 알아서 수정..
string strVersion = string.Format("{0}", Application.version);
string strBuildNumber = string.Format("{0}", PlayerSettings.iOS.buildNumber);
string strDateTime = string.Format("{0}", DateTime.Now.ToString("yyyyMMdd_HHmmss", System.Globalization.CultureInfo.InvariantCulture));
string strPlatform = string.Format("{0}", report.summary.platform);
strNameTranslation_txt_Dest = string.Format("{0}/{1}_{2}_{3}({4})_{5}_{6}{7}_{8}.{9}",
strBuildPath,
strProductName,
strServer,
strVersion,
strBuildNumber,
strDateTime,
strPlatform,
strLunarConsole,
m_strNameTranslation_Src,
m_strExt_txt
);
}
break;
}
Debug.LogWarningFormat("[strNameTranslation_txt_Src] {0} [strNameTranslation_txt_Dest] {1}", strNameTranslation_txt_Src, strNameTranslation_txt_Dest);
// 1. ./PROJECT_PATH/nameTranslation.txt 파일 유무 체크
// 2. 있으면 - Rename : 해당 버전명 날짜/시간 파일명에 포함
if (true == File.Exists(strNameTranslation_txt_Src))
{
File.Move(strNameTranslation_txt_Src, strNameTranslation_txt_Dest);
Debug.LogWarningFormat("[Rename] {0} -> {1}", strNameTranslation_txt_Src, strNameTranslation_txt_Dest);
}
else
{
Debug.LogWarningFormat("[File Not Exists] {0}", strNameTranslation_txt_Src);
}
}
}
'Unity3D > Plugins' 카테고리의 다른 글
[펌] AppIconChangerUnity - Change the app icon dynamically in Unity (iOS only) (0) | 2024.03.22 |
---|---|
[플러그인] GoogleMobileAds 8.6.0(with Unity2021) (0) | 2023.11.23 |
[링크] iMessageStickerUnity (0) | 2023.08.07 |
[에셋] Fast Script Reload (0) | 2023.06.13 |
[링크] 유니티 공식 지원 오브젝트 풀링(Object Pool) (0) | 2023.03.13 |