-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Automatically import TMP support on load (development)
- Loading branch information
Showing
8 changed files
with
104 additions
and
25 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,4 @@ bin/ | |
UserSettings/ | ||
*.app/ | ||
Build/ | ||
Assets/TextMeshPro Support* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#if UNITY_EDITOR | ||
using System.Diagnostics; | ||
using System.Text; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using Debug = UnityEngine.Debug; | ||
|
||
internal static class ImportSample | ||
{ | ||
[MenuItem("Development/Import TMP Support V1", false, 2001)] | ||
private static void ImportTMPSupportV1() | ||
{ | ||
Run("TextMeshPro Support"); | ||
} | ||
|
||
[MenuItem("Development/Import TMP Support V2", false, 2002)] | ||
private static void ImportTMPSupportV2() | ||
{ | ||
Run("TextMeshPro Support (ugui 2.0)"); | ||
} | ||
|
||
[InitializeOnLoadMethod] | ||
private static void ImportSampleOnLoad() | ||
{ | ||
#if UNITY_2023_2_OR_NEWER | ||
ImportTMPSupportV2(); | ||
#else | ||
ImportTMPSupportV1(); | ||
#endif | ||
} | ||
|
||
private static void Run(string sample) | ||
{ | ||
var p = new Process() | ||
{ | ||
StartInfo = new ProcessStartInfo() | ||
{ | ||
Arguments = $"import-tmp-support.sh '{sample}'", | ||
CreateNoWindow = true, | ||
#if UNITY_EDITOR_WIN | ||
FileName = @"C:\Program Files (x86)\Git\bin\bash.exe", | ||
#else | ||
FileName = "/bin/bash", | ||
#endif | ||
RedirectStandardError = true, | ||
RedirectStandardOutput = true, | ||
WorkingDirectory = $"{Application.dataPath}/..", | ||
UseShellExecute = false | ||
}, | ||
EnableRaisingEvents = true | ||
}; | ||
|
||
p.Exited += (_, __) => | ||
{ | ||
var result = new StringBuilder(); | ||
var stdout = p.StandardOutput.ReadToEnd(); | ||
result.Append("stdout: "); | ||
result.Append(stdout); | ||
result.AppendLine(); | ||
result.Append("stderr: "); | ||
result.Append(p.StandardError.ReadToEnd()); | ||
Debug.Log(result); | ||
|
||
if (p.ExitCode == 0 && stdout.StartsWith("Imported: ")) | ||
{ | ||
var path = stdout.Replace("Imported: ", "").Trim(); | ||
AssetDatabase.ImportAsset(path, ImportAssetOptions.ImportRecursive); | ||
} | ||
}; | ||
|
||
p.Start(); | ||
} | ||
} | ||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash -e | ||
|
||
sample=$1 | ||
|
||
# Check the sample | ||
[ ! -d "Packages/src/Samples~/$sample~" ] && echo "Not found in samples: $sample" && exit 1 | ||
|
||
# Already imported | ||
[ -e "Assets/$sample" ] && echo "Already imported: $sample" && exit 0 | ||
|
||
# Remove the old sample | ||
find Assets -name "TextMeshPro Support*" -depth 1 -exec rm {} \; | ||
|
||
# Create a symbolic link to the sample | ||
ln -s "../Packages/src/Samples~/$sample~" Assets | ||
mv "Assets/$sample~" "Assets/$sample" | ||
|
||
echo "Imported: $sample" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.