protected void bindHelper ( GVRScriptBundle scriptBundle , GVRSceneObject rootSceneObject , int bindMask ) throws IOException , GVRScriptException { for ( GVRScriptBindingEntry entry : scriptBundle . file . binding ) { GVRAndroidResource rc ; if ( entry . volumeType == null || entry . volumeType . isEmpty ( ) ) { rc = scriptBundle . volume . openResource ( entry . script ) ; } else { GVRResourceVolume . VolumeType volumeType = GVRResourceVolume . VolumeType . fromString ( entry . volumeType ) ; if ( volumeType == null ) { throw new GVRScriptException ( String . format ( "Volume type %s is not recognized, script=%s" , entry . volumeType , entry . script ) ) ; } rc = new GVRResourceVolume ( mGvrContext , volumeType ) . openResource ( entry . script ) ; } GVRScriptFile scriptFile = ( GVRScriptFile ) loadScript ( rc , entry . language ) ; String targetName = entry . target ; if ( targetName . startsWith ( TARGET_PREFIX ) ) { TargetResolver resolver = sBuiltinTargetMap . get ( targetName ) ; IScriptable target = resolver . getTarget ( mGvrContext , targetName ) ; // Apply mask boolean toBind = false ; if ( ( bindMask & BIND_MASK_GVRSCRIPT ) != 0 && targetName . equalsIgnoreCase ( TARGET_GVRMAIN ) ) { toBind = true ; } if ( ( bindMask & BIND_MASK_GVRACTIVITY ) != 0 && targetName . equalsIgnoreCase ( TARGET_GVRAPPLICATION ) ) { toBind = true ; } if ( toBind ) { attachScriptFile ( target , scriptFile ) ; } } else { if ( ( bindMask & BIND_MASK_SCENE_OBJECTS ) != 0 ) { if ( targetName . equals ( rootSceneObject . getName ( ) ) ) { attachScriptFile ( rootSceneObject , scriptFile ) ; } // Search in children GVRSceneObject [ ] sceneObjects = rootSceneObject . getSceneObjectsByName ( targetName ) ; if ( sceneObjects != null ) { for ( GVRSceneObject sceneObject : sceneObjects ) { GVRScriptBehavior b = new GVRScriptBehavior ( sceneObject . getGVRContext ( ) ) ; b . setScriptFile ( scriptFile ) ; sceneObject . attachComponent ( b ) ; } } } } } }
Helper function to bind script bundler to various targets