Search Unity

XR Plugin System Compiler Directives

Discussion in 'AR/VR (XR) Discussion' started by Barliesque, Jun 22, 2020.

  1. Barliesque

    Barliesque

    Joined:
    Jan 12, 2014
    Posts:
    128
    Is there a scripting #define to identify whether a project is using the older built-in VR support, or the new XR plugin system? I've been searching and searching and cannot find any mention of this.
     
  2. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,932
    You can create one yourself, it's annoyingly confusing and complicated (Unity really ought to improve this - it's nothing to do with VR, it's a core Unity 2019+ feature, but just poorly explained/documented. The UI is simple enough, but the concepts are weird and need better docs).

    In the main Unity docs, there's a section on asmdefs. You need to dig around in there and find the bits about "asmdefs + packages + custom defines". This is the official way for you to detect which Unity packages are installed at code level (they are gradually removing / moving away from putting #defines in their code, they want everyone to use this new asmdef-dependent system).

    This should work with everything in the Unity PackageManager (which of course includes the AR/VR/XR systems...)
     
  3. Barliesque

    Barliesque

    Joined:
    Jan 12, 2014
    Posts:
    128
    @a436t4ataf Thanks for the tip!

    So, I found some potentially useful info (and code) here...
    https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.Compilation;
    3.  
    4. public static class AssemblyLister
    5. {
    6.  
    7.     [MenuItem("Tools/List Player Assemblies in Console")]
    8.     public static void PrintAssemblyNames()
    9.  
    10.     {
    11.         UnityEngine.Debug.Log("== Player Assemblies ==");
    12.         Assembly[] playerAssemblies =
    13.             CompilationPipeline.GetAssemblies(AssembliesType.Player);
    14.  
    15.         foreach (var assembly in playerAssemblies)
    16.         {
    17.             UnityEngine.Debug.Log(assembly.name);
    18.         }
    19.     }
    20. }
    ...which would provide me a way of making some kind of automated tool for setting up those conditional compilation defines -- something I'd have expected Unity to provide. Maybe I'm still missing something?