使用原生 UI 选择器在 Spark AR Studio 的双语过滤器中切换语言

Use of Native UI picker to toggle between languages in bilingual filter in Spark AR Studio

我正在尝试在 Spark AR 中制作 "name place animal thing" 游戏,但我想使用原生 UI 选择器,以提供 2 种语言的游戏。 我在面部跟踪器上使用了两架飞机。第一个(主要)是 "intro screen",第二个(字母)是带有动画字母序列的字母序列,它在 x 秒后停止为随机数。 这个想法是,如果可能的话,当用户使用选择器时,将平面中的材质从英语材质切换到第二语言材质。

这是我的 Spark AR 项目的截图: https://snipboard.io/FtOS9W.jpg

到目前为止我的脚本是:

    const NativeUI = require('NativeUI');
    const Textures = require('Textures');
    const Materials = require('Materials');


Promise.all([
    Textures.findFirst('britishIcon'),
    Textures.findFirst('grIcon'),
    Materials.findFirst('GreekAlphabet'),
    Materials.findFirst('GreekMain'),
    Materials.findFirst('EnglishAlphabet'),
    Materials.findFirst('EnglishMain')

]).then(onReady);
function onReady(assets) {
    const texture0 = assets[0];
    const texture1 = assets[1];
    const picker = NativeUI.picker;
    const index = 0;
    const selection = 0;
    const configuration = {

      selectedIndex: index,

      items: [
        {image_texture: texture0},
        {image_texture: texture1}
      ]

    };

    picker.configure(configuration);
    picker.visible = true;

    picker.selectedIndex.monitor().subscribe(function(index) {
        Materials.inputs.setScalar('selection', index.newValue);
    });
}

最简单的解决办法是改变平面的材质

  1. 插入场景模块获取平面

  2. 将飞机请求添加到 Promie 代码块

  3. 根据所选语言使用 NativeUI 更改平面材质

const NativeUI = require('NativeUI');
const Textures = require('Textures');
const Materials = require('Materials');
const Scene = require('Scene')

Promise.all([
    Textures.findFirst('britishIcon'),
    Textures.findFirst('grIcon'),
    Materials.findFirst('GreekAlphabet'),
    Materials.findFirst('GreekMain'),
    Materials.findFirst('EnglishAlphabet'),
    Materials.findFirst('EnglishMain'),
    Scene.root.findFirst('Main'),
    Scene.root.findFirst('Letters')

]).then(onReady);
function onReady(assets) {
    const texture0 = assets[0];
    const texture1 = assets[1];
    const picker = NativeUI.picker;
    const index = 0;
    const selection = 0;
    const configuration = {

      selectedIndex: index,

      items: [
        {image_texture: texture0},
        {image_texture: texture1}
      ]

    };

    const mainPlane = assets[6];
    const lettersPlane = assets[7];

    picker.configure(configuration);
    picker.visible = true;

    picker.selectedIndex.monitor({fireOnInitialValue:true}).subscribe(function(index) {
        if(index.newValue == 0 /*English*/)
        {
            mainPlane.material = assets[5];
            lettersPlane.material = assets[4];
        }
        else if (index.newValue == 1 /*Greek*/)
        {
            mainPlane.material = assets[3];
            lettersPlane.material = assets[2];
        }
    });
}