Skip to content

Instantly share code, notes, and snippets.

@DanMillerDev
DanMillerDev / AnchorSaveFile.cs
Created March 18, 2025 00:27
Saves and loads SerializableGuids and DateTimes to a file on the devices local storage for persistent anchors
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnityEngine;
using UnityEngine.XR.ARSubsystems;
/// <summary>
@DanMillerDev
DanMillerDev / Unity_GDC_2025_Crossplatform_MixedReality.md
Last active March 18, 2025 21:09
Collection of gist shared in Unity GDC 2025 Talk Building cross-platform mixed reality

Collection of gist shared in Unity GDC 2025 Talk Building cross-platform mixed reality

Shell script for building a Meta Quest, AndroidXR and visionOS build in Unity via CLI batchmode
build_multiplatform_xr.sh

A script to show a unique logo per platform using the preprocessor directives and AR Session Descriptor
LogoManagerPPD.cs
LogoManager.cs

A script for managing permissions across Apple Vision Pro, Meta Quest and Android XR. It references world space UI element to let the user know about missing or denied permissions.

@DanMillerDev
DanMillerDev / ShaderTypeManager.cs
Last active March 16, 2025 19:59
A script for changing the shader type of materials at runtime. In this example we're changing to use a custom occlusion shader required on AndroidXR and Meta Quest platforms for depth based occlusion.
using UnityEngine;
using System.Collections.Generic;
public class ShaderTypeManager : MonoBehaviour
{
[SerializeField]
List<Material> m_MaterialsToChange;
void OnEnable()
{
Shader targetShader;
@DanMillerDev
DanMillerDev / LogoManager.cs
Created March 14, 2025 22:55
A script for updating a logo based on platforms by checking the AR Session descriptor ID, useful when building from generic build platforms like Android and supported multiple android-based headsets like Meta Quest and Android XR
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;
public class LogoManager : MonoBehaviour
{
[SerializeField]
Sprite MetaLogo;
[SerializeField]
@DanMillerDev
DanMillerDev / AnchorRecallManager.cs
Last active March 18, 2025 20:56
A script that listens to trackable changed events for the ARAnchor manager and can recall saved anchors when an application is relaunched.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
public class AnchorRecallManager : MonoBehaviour
{
[SerializeField]
@DanMillerDev
DanMillerDev / AnchorPlacementManager.cs
Last active March 18, 2025 20:54
A script that places and manages Anchors, checking if the platform supports saved anchors and writing the ID to a file.
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARFoundation.Samples;
public class AnchorPlacementManager : MonoBehaviour
{
[SerializeField]
ARAnchorManager m_AnchorManager;
@DanMillerDev
DanMillerDev / HandJointFollow.cs
Created March 14, 2025 21:28
A script to set an objects position and rotation to a specific XR Joint based on the ID, handles usage for game object and physics rigidbodies
using System;
using UnityEngine;
using UnityEngine.XR.Hands;
using UnityEngine.XR.Management;
public class HandJointFollow : MonoBehaviour
{
[SerializeField]
XRHandJointID m_JointToTrack;
@DanMillerDev
DanMillerDev / LogoManagerPPD.cs
Created March 14, 2025 21:23
A script to show a unique logo per platform using the preprocessor directives
using UnityEngine;
using UnityEngine.UI;
public class LogoManagerPPD : MonoBehaviour
{
[SerializeField]
Sprite MetaLogo;
[SerializeField]
Sprite AndroidLogo;
@DanMillerDev
DanMillerDev / XRPermissions.cs
Created March 14, 2025 21:20
A script for managing permissions across Apple Vision Pro, Meta Quest and Android XR. It references world space UI element to let the user know about missing or denied permissions.
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using System.Collections.Generic;
using TMPro;
using UnityEngine.Android;
#if UNITY_VISIONOS
using UnityEngine.XR.VisionOS;
#endif
public class XRPermissions : MonoBehaviour
@DanMillerDev
DanMillerDev / build_multiplatform_xr.sh
Created March 12, 2025 18:30
Shell script for building a Meta Quest, AndroidXR and visionOS build in Unity via CLI batchmode
#!/bin/bash
# Set common variables for your Unity project, Replace these with your editor and project path
UNITY_PATH="/Applications/Unity/Hub/Editor/6000.1.0b8/Unity.app/Contents/MacOS/Unity"
PROJECT_PATH="/Users/dan/Documents/UnityRepos/Crossplatform_MR_GDC2025"
BUILD_OUTPUT_DIR="/Users/dan/Documents/UnityRepos/Crossplatform_MR_GDC2025/Builds"
BUILD_PROFILE_QUEST="Assets/Settings/Build Profiles/MetaQuest.asset"
BUILD_PROFILE_ANDROIDXR="Assets/Settings/Build Profiles/AndroidXR.asset"
BUILD_PROFILE_VISIONOS="Assets/Settings/Build Profiles/visionOS.asset"