Skip to content

Commit

Permalink
chore: Automatically import TMP support on load (development)
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Jul 17, 2024
1 parent 725278a commit 9d8b5a1
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ bin/
UserSettings/
*.app/
Build/
Assets/TextMeshPro Support*
74 changes: 74 additions & 0 deletions Assets/Demos/TextMeshPro Support/ImportSample.cs
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
11 changes: 11 additions & 0 deletions Assets/Demos/TextMeshPro Support/ImportSample.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Assets/TextMeshPro Support

This file was deleted.

8 changes: 0 additions & 8 deletions Assets/TextMeshPro Support.meta

This file was deleted.

18 changes: 18 additions & 0 deletions import-tmp-support.sh
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"
8 changes: 0 additions & 8 deletions tmp-support-stable.sh

This file was deleted.

8 changes: 0 additions & 8 deletions tmp-support-v3.2-or-v4.0.sh

This file was deleted.

0 comments on commit 9d8b5a1

Please sign in to comment.