209 lines
8.4 KiB
C#
209 lines
8.4 KiB
C#
using System.IO;
|
|
using System.Linq;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
public class ChannelBuildTool
|
|
{
|
|
public static readonly string[] SupportedChannels = { "GooglePlay", "Rustore", "Flexion", "EnjoyPay" };
|
|
|
|
private const string DefaultChannel = "GooglePlay";
|
|
private const string DefaultAndroidBundleIdentifier = "com.arkgame.ft";
|
|
private const string ExtraCfgRoot = "../ExtraPluginCfgs/Android";
|
|
private const string TysdkPlugins = "Packages/tysdk/Plugins/Android";
|
|
private const string TysdkFiles = "Packages/tysdk/Files";
|
|
private const string AssetsPlugins = "Assets/Plugins/Android";
|
|
|
|
private static readonly string[] GradleFiles =
|
|
{
|
|
"mainTemplate.gradle",
|
|
"launcherTemplate.gradle",
|
|
"settingsTemplate.gradle",
|
|
"gradleTemplate.properties",
|
|
"AndroidManifest.xml"
|
|
};
|
|
|
|
// ==================== Channel Switching ====================
|
|
|
|
private static void SwitchChannel(string channel)
|
|
{
|
|
var channelDir = channel.ToLower();
|
|
var cfgDir = Path.Combine(ExtraCfgRoot, channelDir);
|
|
if (!Directory.Exists(cfgDir))
|
|
{
|
|
Debug.LogError($"[ChannelSwitch] Channel config not found: {cfgDir}");
|
|
return;
|
|
}
|
|
|
|
Debug.Log($"[ChannelSwitch] Switching to {channel}...");
|
|
currentChannel = channel;
|
|
|
|
// 1. Sync AAR
|
|
var srcAarDir = Path.Combine(cfgDir, "Plugins/Android");
|
|
if (Directory.Exists(srcAarDir))
|
|
{
|
|
foreach (var oldAar in Directory.GetFiles(TysdkPlugins, "tuyoosdk_*.aar"))
|
|
File.Delete(oldAar);
|
|
foreach (var oldJar in Directory.GetFiles(TysdkPlugins, "tuyoosdk_*.jar"))
|
|
File.Delete(oldJar);
|
|
foreach (var aar in Directory.GetFiles(srcAarDir, "*.aar"))
|
|
{
|
|
var dest = Path.Combine(TysdkPlugins, Path.GetFileName(aar));
|
|
File.Copy(aar, dest, true);
|
|
Debug.Log($"[ChannelSwitch] AAR: {aar} → {dest}");
|
|
}
|
|
}
|
|
|
|
// 2. Clean up previous channel Java files
|
|
foreach (var oldJava in Directory.GetFiles(TysdkPlugins, "ChannelHelpers.java"))
|
|
File.Delete(oldJava);
|
|
foreach (var oldJava in Directory.GetFiles(TysdkPlugins, "ChannelEntry.java"))
|
|
File.Delete(oldJava);
|
|
foreach (var oldJava in Directory.GetFiles(TysdkPlugins, "*SDKHelper.java"))
|
|
File.Delete(oldJava);
|
|
foreach (var oldJava in Directory.GetFiles(TysdkPlugins, "*SDKService.java"))
|
|
File.Delete(oldJava);
|
|
foreach (var oldJava in Directory.GetFiles(TysdkPlugins, "*SDKAdapter.java"))
|
|
File.Delete(oldJava);
|
|
var oldConfig = Path.Combine(TysdkPlugins, "ConfigManager.java");
|
|
if (File.Exists(oldConfig)) File.Delete(oldConfig);
|
|
|
|
// 3. Sync Gradle + Manifest
|
|
foreach (var fileName in GradleFiles)
|
|
{
|
|
var src = Path.Combine(cfgDir, fileName);
|
|
if (File.Exists(src))
|
|
{
|
|
var dest = Path.Combine(AssetsPlugins, fileName);
|
|
File.Copy(src, dest, true);
|
|
Debug.Log($"[ChannelSwitch] Config: {src} → {dest}");
|
|
}
|
|
}
|
|
|
|
// 4. Sync channel Java files to tysdk package
|
|
foreach (var javaFile in Directory.GetFiles(cfgDir, "*.java"))
|
|
{
|
|
var fileName = Path.GetFileName(javaFile);
|
|
var dest = Path.Combine(TysdkPlugins, fileName);
|
|
File.Copy(javaFile, dest, true);
|
|
Debug.Log($"[ChannelSwitch] Java: {javaFile} → {dest}");
|
|
}
|
|
|
|
// 5. Sync google-services.json (fallback to GooglePlay default)
|
|
var srcGoogleServices = Path.Combine(cfgDir, "Files/google-services.json");
|
|
if (!File.Exists(srcGoogleServices))
|
|
srcGoogleServices = Path.Combine(ExtraCfgRoot, "googleplay/Files/google-services.json");
|
|
var destGoogleServices = Path.Combine(TysdkFiles, "google-services.json");
|
|
File.Copy(srcGoogleServices, destGoogleServices, true);
|
|
Debug.Log($"[ChannelSwitch] google-services.json: {srcGoogleServices} → {destGoogleServices}");
|
|
|
|
// 6. Set Bundle Identifier per channel
|
|
var bundleId = channel switch
|
|
{
|
|
"Flexion" => "com.arkgame.ft.flexion",
|
|
"EnjoyPay" => "com.arkgame.ft.ep",
|
|
_ => "com.arkgame.ft"
|
|
};
|
|
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, bundleId);
|
|
Debug.Log($"[CHANNEL-VERIFY] Bundle Identifier → {bundleId}");
|
|
|
|
// 7. Set runtime channel
|
|
tysdk.ChannelConfig.SetChannel(channel);
|
|
|
|
AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
|
|
Debug.Log($"[ChannelSwitch] Done. Channel: {channel}");
|
|
}
|
|
|
|
// ==================== Build ====================
|
|
|
|
private static void RestoreDefaultChannel()
|
|
{
|
|
Debug.Log($"[ChannelBuild] Restore default channel -> {DefaultChannel}");
|
|
SwitchChannel(DefaultChannel);
|
|
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, DefaultAndroidBundleIdentifier);
|
|
Debug.Log($"[ChannelBuild] Restore bundle identifier -> {DefaultAndroidBundleIdentifier}");
|
|
AssetDatabase.SaveAssets();
|
|
}
|
|
|
|
private static void BuildAndroidForChannel(string channel, bool debug)
|
|
{
|
|
try
|
|
{
|
|
SwitchChannel(channel);
|
|
|
|
string fileName = debug ? $"tysdkTest_{channel}_debug.apk" : $"tysdkTest_{channel}.apk";
|
|
string outPath = $"../Bin/{fileName}";
|
|
var buildOptions = debug
|
|
? BuildOptions.Development | BuildOptions.AllowDebugging | BuildOptions.WaitForPlayerConnection
|
|
: BuildOptions.None;
|
|
|
|
var buildPlayerOptions = new BuildPlayerOptions
|
|
{
|
|
scenes = EditorBuildSettings.scenes.Select(x => x.path).ToArray(),
|
|
locationPathName = outPath,
|
|
target = BuildTarget.Android,
|
|
options = buildOptions,
|
|
};
|
|
|
|
Debug.Log($"[ChannelBuild] Building {channel} → {outPath}");
|
|
var buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
|
|
|
if (buildReport?.summary.result == UnityEditor.Build.Reporting.BuildResult.Succeeded)
|
|
{
|
|
Debug.Log($"[ChannelBuild] Success: {Path.GetFullPath(outPath)}");
|
|
AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"[ChannelBuild] Failed: {buildReport?.summary}");
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
RestoreDefaultChannel();
|
|
}
|
|
}
|
|
|
|
private static string currentChannel = "";
|
|
|
|
// ==================== Menu: Switch Channel ====================
|
|
|
|
[MenuItem("Tools/Switch Channel/GooglePlay")]
|
|
public static void Switch_GooglePlay() => SwitchChannel("GooglePlay");
|
|
|
|
[MenuItem("Tools/Switch Channel/Rustore")]
|
|
public static void Switch_Rustore() => SwitchChannel("Rustore");
|
|
|
|
[MenuItem("Tools/Switch Channel/Flexion")]
|
|
public static void Switch_Flexion() => SwitchChannel("Flexion");
|
|
|
|
[MenuItem("Tools/Switch Channel/EnjoyPay")]
|
|
public static void Switch_EnjoyPay() => SwitchChannel("EnjoyPay");
|
|
|
|
// ==================== Menu: Build ====================
|
|
|
|
[MenuItem("Tools/Build Android (Channel)/GooglePlay")]
|
|
public static void Build_GooglePlay() => BuildAndroidForChannel("GooglePlay", false);
|
|
|
|
[MenuItem("Tools/Build Android (Channel)/GooglePlay Debug")]
|
|
public static void Build_GooglePlay_Debug() => BuildAndroidForChannel("GooglePlay", true);
|
|
|
|
[MenuItem("Tools/Build Android (Channel)/Rustore")]
|
|
public static void Build_Rustore() => BuildAndroidForChannel("Rustore", false);
|
|
|
|
[MenuItem("Tools/Build Android (Channel)/Rustore Debug")]
|
|
public static void Build_Rustore_Debug() => BuildAndroidForChannel("Rustore", true);
|
|
|
|
[MenuItem("Tools/Build Android (Channel)/Flexion")]
|
|
public static void Build_Flexion() => BuildAndroidForChannel("Flexion", false);
|
|
|
|
[MenuItem("Tools/Build Android (Channel)/Flexion Debug")]
|
|
public static void Build_Flexion_Debug() => BuildAndroidForChannel("Flexion", true);
|
|
|
|
[MenuItem("Tools/Build Android (Channel)/EnjoyPay")]
|
|
public static void Build_EnjoyPay() => BuildAndroidForChannel("EnjoyPay", false);
|
|
|
|
[MenuItem("Tools/Build Android (Channel)/EnjoyPay Debug")]
|
|
public static void Build_EnjoyPay_Debug() => BuildAndroidForChannel("EnjoyPay", true);
|
|
}
|