Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Namespace problem, trying to create package that depends on Google Cardboard SDK

Discussion in 'Package Manager' started by Rs, Oct 20, 2021.

  1. Rs

    Rs

    Joined:
    Aug 14, 2012
    Posts:
    74
    I'm trying to create a package that adds functionality to Google Cardboard SDK (aka Google VR) which is found at https://github.com/googlevr/cardboard-xr-plugin.git

    I'm doing this via 'install from disk...", it installs correctly, assembly definition files are in the Runtime folder, but I get an error. Where the code refers to Google.XR.Cardboard.Api.IsTriggerPressed (and obviously any other calls to the API) Unity complains with:

    error CS0103: The name 'Google' does not exist in the current context

    Note that the Google cardboard xr plugin is correctly installed and all this worked fine when it was in the Assets folder before I tried to convert to a Package.
    Here's the package.json (I had to change the name and display name):

    Code (CSharp):
    1. {
    2.   "name": "net.xyz.cardboardinteraction",
    3.   "displayName": "CardboardInteract",
    4.   "version": "1.0.0",
    5.   "unity": "2019.4",
    6.   "description": "Provides a directional, gaze style pointer ......",
    7.   "keywords": [
    8.     "google",
    9.     "cardboard",
    10.     "vr",
    11.     "xr",
    12.     "reality"
    13.   ],
    14.   "dependencies": {
    15.     "com.google.xr.cardboard" : "https://github.com/googlevr/cardboard-xr-plugin.git"
    16.   },
    17.   "type": "tool"
    18. }

    In dependencies I also tried

    "com.google.xr.cardboard" : "1.8.0"


    but the result is the same.

    What am I missing?
    Thanks all
     
    Last edited: Oct 20, 2021
  2. Rs

    Rs

    Joined:
    Aug 14, 2012
    Posts:
    74
    OK, I solved this by manually including Google.XR.Cardboard and Google.XR.Cardboard.Editor in the Assembly definition references in my package's Assembly definition file. This is done in the Unity inspector by selecting the package's asmdef.




    Note that if this is done with the Unity Inspector by drag and drop, the asmdef file will refer to the resources by GUID, like so:

    Code (CSharp):
    1.     "references": [
    2.         "GUID:ad91be1e774094f99afb64ef26c07397",
    3.         "GUID:2f52f0b6cfdc94464bcc067a11c8e1b6"
    4.     ],
    5.  
    Instead, for better distribution, it's better to manually set the lines to

    Code (CSharp):
    1.     "references": [
    2.         "Google.XR.Cardboard",
    3.         "Google.XR.Cardboard.Editor"
    4.     ],
    5.  
    by opening the .asmdef file with a text editor and entering the assembly definition references names.
     

    Attached Files:

    Last edited: Oct 20, 2021
  3. There is a "Use GUIDs" checkbox above the list of references in the inspector if you uncheck it, it won't reference GUIDs. It is even visible in your own screenshot. You don't have to manually edit the ASMDEF file, unless you want to.