Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Import Text Mesh Pro Essential Resources (#824)
Browse files Browse the repository at this point in the history
* Import Text Mesh Pro Essentual Resources

Needed for correct batch mode building

* fixed path
  • Loading branch information
StephenHodgson authored Apr 26, 2021
1 parent 8ff4898 commit 68fb935
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
46 changes: 45 additions & 1 deletion Editor/Utilities/MixedRealityEditorSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.IO;
using TMPro.EditorUtilities;
using UnityEditor;
using UnityEditor.Build;
using UnityEngine;
Expand Down Expand Up @@ -43,6 +45,16 @@ public static void CheckSettings()

SessionState.SetBool(SessionKey, false);

if (!Directory.Exists($"{Application.dataPath}/TextMesh Pro"))
{
if (EditorUtility.DisplayDialog("Missing Package!",
"The project requires the Text Mesh Pro essential resources, would you like to import them now?",
"OK", "Later"))
{
ImportTMProEssentialResources();
}
}

var message = "The Mixed Reality Toolkit needs to apply the following settings to your project:\n\n";

var forceTextSerialization = EditorSettings.serializationMode == SerializationMode.ForceText;
Expand Down Expand Up @@ -104,5 +116,37 @@ void IActiveBuildTargetChanged.OnActiveBuildTargetChanged(BuildTarget previousTa
}

#endregion IActiveBuildTargetChanged Implementation

private static string settingsFilePath;
private static byte[] settingsBackup;

// Copied straight from the TMP_PackageUtilities.cs but we needed to import the assets if in batch mode.
private static void ImportTMProEssentialResources()
{
// Check if the TMP Settings asset is already present in the project.
var settings = AssetDatabase.FindAssets("t:TMP_Settings");

if (settings.Length > 0)
{
// Save assets just in case the TMP Setting were modified before import.
AssetDatabase.SaveAssets();

// Copy existing TMP Settings asset to a byte[]
settingsFilePath = AssetDatabase.GUIDToAssetPath(settings[0]);
settingsBackup = File.ReadAllBytes(settingsFilePath);

AssetDatabase.importPackageCompleted += ImportCallback;
}

AssetDatabase.ImportPackage($"{TMP_EditorUtility.packageFullPath}/Package Resources/TMP Essential Resources.unitypackage", Application.isBatchMode);
}

private static void ImportCallback(string packageName)
{
// Restore backup of TMP Settings from byte[]
File.WriteAllBytes(settingsFilePath, settingsBackup);
AssetDatabase.Refresh();
AssetDatabase.importPackageCompleted -= ImportCallback;
}
}
}
}
3 changes: 2 additions & 1 deletion Editor/XRTK.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "XRTK.Editor",
"references": [
"GUID:f3241d040533491e8a1e2714b27c3111"
"GUID:f3241d040533491e8a1e2714b27c3111",
"GUID:6546d7765b4165b40850b3667f981c26"
],
"includePlatforms": [
"Editor"
Expand Down

0 comments on commit 68fb935

Please sign in to comment.