Skip to content

Instantly share code, notes, and snippets.

@Kleptine
Created April 10, 2021 14:41
Show Gist options
  • Save Kleptine/eed66fc2e4e99c42a967f53f24eb24bf to your computer and use it in GitHub Desktop.
Save Kleptine/eed66fc2e4e99c42a967f53f24eb24bf to your computer and use it in GitHub Desktop.
Tools for checking FBX import/export settings in Unity.
[MenuItem("Assets/Check FBX for Issues")]
private static void CheckFBX()
{
var paths = Selection.assetGUIDs.Select(s =>
Path.GetFullPath(Path.Combine(Application.dataPath, "..", AssetDatabase.GUIDToAssetPath(s)))).ToArray();
var exe = Path.GetFullPath(Path.Combine(Application.dataPath, "..", "..", "Tools", "Hooks",
"fbx_sanitizer.exe"));
// Start the child process.
(string output, string error) = RunCommand(exe, string.Join(" ", paths));
if (output == "" && error == "")
{
output = "No issues were found. All FBX files are valid!";
}
error = error.Replace("[ERROR]", "");
string message = $"The following files were scanned: {string.Join("\n", paths)}\n" +
$"{output}\n" +
$"{error}";
EditorUtility.DisplayDialog("FBX Checker", message, "Ok");
}
private static (string stdout, string stderr) RunCommand(string executable, string arguments)
{
StringBuilder output = new StringBuilder();
StringBuilder error = new StringBuilder();
using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false))
using (Process process = new Process())
{
process.StartInfo.FileName = executable;
process.StartInfo.Arguments = arguments;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.OutputDataReceived += (sender, e) =>
{
if (e.Data == null)
{
outputWaitHandle.Set();
}
else
{
output.AppendLine(e.Data);
}
};
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data == null)
{
errorWaitHandle.Set();
}
else
{
error.AppendLine(e.Data);
}
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit(int.MaxValue);
outputWaitHandle.WaitOne(int.MaxValue);
errorWaitHandle.WaitOne(int.MaxValue);
// Process completed. Check process.ExitCode here.
return (output.ToString(), error.ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment