Created
July 6, 2020 13:10
-
-
Save tarukosu/32c127a3aed67642fdc04dfa36c3a8be to your computer and use it in GitHub Desktop.
アプリのパッケージ名にプロダクト名を自動設定するスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using UnityEditor; | |
using UnityEditor.Build; | |
using UnityEngine; | |
namespace ProjectSettingsUtilities | |
{ | |
[InitializeOnLoad] | |
public class PublishingSettingsUpdater : IActiveBuildTargetChanged | |
{ | |
private static readonly string SessionKey = "_ProjectSettingsUtilities_PublishingSettingsUpdater"; | |
private static readonly List<string> DefaultSettingValues | |
= new List<string> { "Template3D", "Template_3D" }; | |
private static readonly string DefaultCompanyName = "DefaultCompany"; | |
private static readonly string CompanyName = "<会社名 or ユーザー名>"; | |
static PublishingSettingsUpdater() | |
{ | |
if (!IsNewSession || Application.isPlaying) | |
{ | |
return; | |
} | |
UpdatePublishingSettings(); | |
} | |
// Unity Editor が起動してから、初回のみ true を返し、その後は false を返す | |
private static bool IsNewSession | |
{ | |
get | |
{ | |
if (SessionState.GetBool(SessionKey, false)) | |
{ | |
return false; | |
} | |
SessionState.SetBool(SessionKey, true); | |
return true; | |
} | |
} | |
private static void UpdatePublishingSettings() | |
{ | |
// Companay Name を更新 | |
if (PlayerSettings.companyName == DefaultCompanyName) | |
{ | |
PlayerSettings.companyName = CompanyName; | |
} | |
var productName = PlayerSettings.productName; | |
// UWP の Package Name を変更 | |
if (DefaultSettingValues.Contains(PlayerSettings.WSA.packageName)) | |
{ | |
PlayerSettings.WSA.packageName = productName; | |
} | |
// UWP の Application UI の Description を変更 | |
if (DefaultSettingValues.Contains(PlayerSettings.WSA.applicationDescription)) | |
{ | |
PlayerSettings.WSA.applicationDescription = productName; | |
} | |
} | |
public int callbackOrder => 0; | |
public void OnActiveBuildTargetChanged(BuildTarget previousTarget, BuildTarget newTarget) | |
{ | |
SessionState.SetBool(SessionKey, false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment