- Home /
Detect if build target is installed
I maintain an editor extension called Build Automator and I wanted to upgrade it so that it would disable any platforms that the user does not have installed; I did some searching through the docs but couldn't find anything.
I was wondering if there's any way to detect if a module is installed, or if a build target exists?
Answer by roojerry · Mar 10, 2017 at 09:50 PM
Good timing. I just recently sought after a solution for this a few days ago for a platform switcher I was working on. I don't know if I found the preferred solution (I would love to know if there is an easier way), but by using Reflection I was able to access the ModuleManager to check IsPlatformSupportLoaded.
var moduleManager = System.Type.GetType("UnityEditor.Modules.ModuleManager,UnityEditor.dll");
var isPlatformSupportLoaded = moduleManager.GetMethod("IsPlatformSupportLoaded", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
var getTargetStringFromBuildTarget = moduleManager.GetMethod("GetTargetStringFromBuildTarget", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
return (bool)isPlatformSupportLoaded.Invoke(null,new object[] {(string)getTargetStringFromBuildTarget.Invoke(null, new object[] {BuildTarget.tvOS})});
yeah... no real guarantees on what versions of Unity that works with. It's a hacky solution, at least for me, using 5.5
Is it possible to do something similar for BuildTargetGroup?
What would be the advantage of checking against BuildTargetGroup? As far as I can tell, the BuildTargetGroup enumeration differs only in that it has a more general definition of the Standalone platform. And, Standalone should always be a supported platform, right?
Either way, there doesn't look to be a straightforward call to check if a BuildTargetGroup is supported.
Intuitively one would think so, however, it seems like the Facebook targets added in 5.6 (afaik) have their own unique group but reuse the actual targets from Standalone and web gl?