Skip to content

Commit

Permalink
Initialize package list on static constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
VMaldecoasago committed Jul 5, 2024
1 parent a2e4e31 commit 53f2403
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static ApplePlatformID()
}
}

[InitializeOnLoad]
public class ApplePlugInEnvironment : AssetPostprocessor
{
/// <summary>
Expand Down Expand Up @@ -105,6 +106,7 @@ public class ApplePlugInEnvironment : AssetPostprocessor
/// </summary>
private enum UpdateState
{
NotInitialized,
Initializing,
Updating
}
Expand All @@ -126,13 +128,25 @@ private enum UpdateState
/// State tracking for select platform
/// </summary>
private static string _trackedApplePlatform;

/// <summary>
/// Initialize C# objects. Do not create or load assets here.
/// </summary>
static ApplePlugInEnvironment()
{
// Initialize collection of packages
_appleUnityPackages = new Dictionary<string, AppleUnityPackage>();
_packageManagerListRequest = Client.List();

_updateState = UpdateState.NotInitialized;
}

/// <summary>
/// Initialize the ApplePlugInEnvironment after all assets finished processing, so we can alter our own.
/// </summary>
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload)
{
if (_updateState != UpdateState.Initializing) { return; }
if (_updateState != UpdateState.NotInitialized) { return; }

// Ensure that the necessary Apple Unity Plug-In support folders exist and let user know if any have been created.
string createFolderMessage = "[Apple Unity Plug-ins] Creating support folders:\n";
Expand Down Expand Up @@ -167,10 +181,6 @@ private static void OnPostprocessAllAssets(string[] importedAssets, string[] del
_defaultProfile = AppleBuildProfile.DefaultProfile();
_defaultProfile.ResolveBuildSteps();

// Initialize collection of packages
_appleUnityPackages = new Dictionary<string, AppleUnityPackage>();
_packageManagerListRequest = Client.List();

// Initialize state tracking
_updateState = UpdateState.Initializing;
_trackedAppleConfig = GetAppleBuildConfig();
Expand Down

0 comments on commit 53f2403

Please sign in to comment.