Forum Discussion
lukaszdudziak
Sep 11, 2024Brass Contributor
Detect client platform
Is there a way to detect the client type connected with the Visual Script? I want to show a simple tutorial on teleporting and interacting with objects, but it differs for PC and Quest; therefore, I ...
- Sep 20, 2024
lukaszdudziak if this is blocking you, I can share a technique we used for the Bean Bag toss activity at one point to change behavior on Quest vs PC. We wrote an editor script that at build time swapped the script asset based on the build target. Here is the script (note once michael-buschbeck-ms's solution comes online I'd prefer that over this 😉😞
using System; using System.Collections.Generic; using Unity.VisualScripting; using UnityEditor; using UnityEditor.Build; using UnityEditor.Build.Reporting; using UnityEngine; using UnityEngine.SceneManagement; namespace Microsoft.MeshApps.Toybox.Editor { public class SceneProcessor : IProcessSceneWithReport { const string packagePrefix = "Packages/com.microsoft.mesh.toolkit.toybox"; const string beanBagGraph = packagePrefix + "/Runtime/BeanBag/Scripts/BeanBagGraph.asset"; const string beanBagGraphQuest = packagePrefix + "/Runtime/BeanBag/Scripts/BeanBagGraphQuest.asset"; public int callbackOrder => 1; public void OnProcessScene(Scene scene, BuildReport report) { if (report == null) return; try { var assetToUse = AssetDatabase.LoadAssetAtPath<ScriptGraphAsset>((report.summary.platform == BuildTarget.Android) ? beanBagGraphQuest : beanBagGraph); var assetToReplace = AssetDatabase.LoadAssetAtPath<ScriptGraphAsset>((report.summary.platform == BuildTarget.Android) ? beanBagGraph : beanBagGraphQuest); foreach (var go in scene.GetRootGameObjects()) { foreach (var sm in go.GetComponentsInChildren<ScriptMachine>()) { if (sm.nest.macro == assetToReplace) { Debug.Log($"Switching from {assetToReplace.name} to {assetToUse.name} in scene {scene.name}"); sm.nest.SwitchToMacro(assetToUse); } } } } catch (Exception e) { Debug.LogError($"Error when attempting to swap graphs for quest assets: {e}"); } } } }
michael-buschbeck-ms
Microsoft
Sep 17, 2024lukaszdudziak I'm afraid we're not currently exposing any API to visual scripts that would provide that information. But it's a very reasonable request – I've made a note of it and we'll consider adding something to that end in a future release.