### C# Example: Transition Arm Model Monobehaviour Source: https://github.com/king-kloy/ar-project/blob/master/Library/PackageCache/com.unity.xr.legacyinputhelpers@2.0.2/Documentation~/ArmModels.md This C# script implements an example monobehaviour for controlling the Transition Arm Model. It uses controller input (Right Trigger) to queue different arm models ('SwingArmModel' and 'PointerArmModel') and manages the transition timing. It requires references to the TransitionArmModel and the names of the arm models to transition between. ```csharp public class ExampleTransitionArmModel : MonoBehaviour { [SerializeField] public UnityEngine.XR.LegacyInputHelpers.TransitionArmModel transitionArmModel; [SerializeField] public string swingArmModelName = "SwingArmModel"; [SerializeField] public string pointerArmModelName = "PointerArmModel"; float timeToNextButtonPress = 0.0f; int currentArmModel = 0; // Update is called once per frame void Update() { // this uses the Right Trigger on the controller. to seed the input asset with this action, please // consult the XR Input Seeding documentation if (timeToNextButtonPress <= 0.0f && Input.GetButton("XRI_Right_TriggerButton")) { if(currentArmModel == 0) { transitionArmModel.Queue(swingArmModelName); } else { transitionArmModel.Queue(pointerArmModelName); } // flip which arm we're using currentArmModel = currentArmModel == 0 ? 1 : 0; timeToNextButtonPress = 1.0f; // wait a second before allowing another arm model to be queued } else { timeToNextButtonPress -= Time.deltaTime; } } } ``` -------------------------------- ### Clone and Navigate AR Project Repository Source: https://github.com/king-kloy/ar-project/blob/master/README.md These commands clone the AR project repository from GitHub and navigate into the project directory. Ensure Git is installed and configured on your system. ```bash # Clone this repository git clone https://github.com/king-kloy/AR-project.git # Go into the repository cd AR-project ``` -------------------------------- ### Enable HLAPI Package for Testing in Unity Source: https://github.com/king-kloy/ar-project/blob/master/Library/PackageCache/com.unity.multiplayer-hlapi@1.0.2/README.md This JSON snippet shows how to configure your Unity project's manifest.json to enable testing for the HLAPI package. By adding the package to the 'testables' array, you allow the test framework to discover and run tests associated with it. ```json { "dependencies": { "com.unity.multiplayer-hlapi": "0.2.6-preview", ... more stuff... }, "testables": [ "com.unity.multiplayer-hlapi" ] } ``` -------------------------------- ### Add HLAPI Package to Unity Project Source: https://github.com/king-kloy/ar-project/blob/master/Library/PackageCache/com.unity.multiplayer-hlapi@1.0.2/README.md This snippet demonstrates how to add the Unity Multiplayer HLAPI package to your Unity project's manifest.json file. Ensure you specify a valid version. This is an alternative to using the Package Manager UI. ```json { "dependencies": { "com.unity.multiplayer-hlapi": "0.2.6-preview", "com.unity.netcode.gameobjects": "4.0.0", "com.unity.ide.visualstudio": "2.0.17", "com.unity.test-framework": "1.3.7" } } ``` -------------------------------- ### UI Panel Navigation System in Unity C# Source: https://context7.com/king-kloy/ar-project/llms.txt Manages navigation between different UI panels in a Unity application, including welcome, footwear, and backpack screens. It also includes a function to open an external URL. Panels are controlled via `SetActive` and require assignment in the Inspector. ```csharp using UnityEngine; public class PanelScript : MonoBehaviour { public Transform PanelWelcome; public Transform PanelFootwears; public Transform PanelBackpacks; // Main navigation flow for the application public void showFootwearsPanel() { PanelWelcome.gameObject.SetActive(false); PanelFootwears.gameObject.SetActive(true); PanelBackpacks.gameObject.SetActive(false); } public void showBackpacksPanel() { PanelWelcome.gameObject.SetActive(false); PanelFootwears.gameObject.SetActive(false); PanelBackpacks.gameObject.SetActive(true); } public void HomeButton() { PanelWelcome.gameObject.SetActive(true); PanelFootwears.gameObject.SetActive(false); PanelBackpacks.gameObject.SetActive(false); } public void OpenUrl() { Application.OpenURL("www.tonaton.com"); } } ``` -------------------------------- ### Animated Panel Manager in C# Source: https://context7.com/king-kloy/ar-project/llms.txt Handles animated UI panel transitions using Unity's Animator. It manages opening and closing panels, tracking the previously selected UI element, and ensuring panels are properly deactivated after closing. Requires Unity UI and EventSystems. ```csharp using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using System.Collections; public class PanelManager : MonoBehaviour { public Animator initiallyOpen; private int m_OpenParameterId; private Animator m_Open; private GameObject m_PreviouslySelected; const string k_OpenTransitionName = "Open"; const string k_ClosedStateName = "Closed"; public void OnEnable() { m_OpenParameterId = Animator.StringToHash(k_OpenTransitionName); if (initiallyOpen == null) return; OpenPanel(initiallyOpen); } public void OpenPanel(Animator anim) { if (m_Open == anim) return; anim.gameObject.SetActive(true); var newPreviouslySelected = EventSystem.current.currentSelectedGameObject; anim.transform.SetAsLastSibling(); CloseCurrent(); m_PreviouslySelected = newPreviouslySelected; m_Open = anim; m_Open.SetBool(m_OpenParameterId, true); GameObject go = FindFirstEnabledSelectable(anim.gameObject); SetSelected(go); } public void CloseCurrent() { if (m_Open == null) return; m_Open.SetBool(m_OpenParameterId, false); SetSelected(m_PreviouslySelected); StartCoroutine(DisablePanelDeleyed(m_Open)); m_Open = null; } IEnumerator DisablePanelDeleyed(Animator anim) { bool closedStateReached = false; bool wantToClose = true; while (!closedStateReached && wantToClose) { if (!anim.IsInTransition(0)) closedStateReached = anim.GetCurrentAnimatorStateInfo(0).IsName(k_ClosedStateName); wantToClose = !anim.GetBool(m_OpenParameterId); yield return new WaitForEndOfFrame(); } if (wantToClose) anim.gameObject.SetActive(false); } private void SetSelected(GameObject go) { EventSystem.current.SetSelectedGameObject(go); } static GameObject FindFirstEnabledSelectable(GameObject gameObject) { GameObject go = null; var selectables = gameObject.GetComponentsInChildren(true); foreach (var selectable in selectables) { if (selectable.IsActive() && selectable.IsInteractable()) { go = selectable.gameObject; break; } } return go; } } ``` -------------------------------- ### AR Marker Tracking with Vuforia in Unity Source: https://context7.com/king-kloy/ar-project/llms.txt Manages AR marker tracking and the visibility of virtual objects in Unity using the Vuforia SDK. It registers a trackable event handler to detect when a marker is found or lost, and enables/disables renderers, colliders, and canvases accordingly. ```csharp using UnityEngine; using Vuforia; public class DefaultTrackableEventHandler : MonoBehaviour, ITrackableEventHandler { protected TrackableBehaviour mTrackableBehaviour; protected virtual void Start() { mTrackableBehaviour = GetComponent(); if (mTrackableBehaviour) mTrackableBehaviour.RegisterTrackableEventHandler(this); } public void OnTrackableStateChanged( TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus) { if (newStatus == TrackableBehaviour.Status.DETECTED || newStatus == TrackableBehaviour.Status.TRACKED || newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED) { Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found"); OnTrackingFound(); } else if (previousStatus == TrackableBehaviour.Status.TRACKED && newStatus == TrackableBehaviour.Status.NO_POSE) { Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost"); OnTrackingLost(); } } protected virtual void OnTrackingFound() { var rendererComponents = GetComponentsInChildren(true); var colliderComponents = GetComponentsInChildren(true); var canvasComponents = GetComponentsInChildren(true); foreach (var component in rendererComponents) component.enabled = true; foreach (var component in colliderComponents) component.enabled = true; foreach (var component in canvasComponents) component.enabled = true; } protected virtual void OnTrackingLost() { var rendererComponents = GetComponentsInChildren(true); var colliderComponents = GetComponentsInChildren(true); var canvasComponents = GetComponentsInChildren(true); foreach (var component in rendererComponents) component.enabled = false; foreach (var component in colliderComponents) component.enabled = false; foreach (var component in canvasComponents) component.enabled = false; } } ``` -------------------------------- ### Footwear Item Management in Unity C# Source: https://context7.com/king-kloy/ar-project/llms.txt Controls the display and switching of different footwear models in Unity. This script activates a selected footwear GameObject, deactivates others, and hides the footwear selection panel. It requires prefabs assigned in the Inspector and is controlled via UI button callbacks. ```csharp using UnityEngine; public class FootwearScript : MonoBehaviour { public GameObject shoe; public GameObject sneaker; public GameObject slipper; public Transform PanelFootwears; // Usage: Attach to a GameObject and assign footwear prefabs in Inspector // Call these methods from UI buttons to display specific footwear in AR public void Shoe() { shoe.SetActive(true); sneaker.SetActive(false); slipper.SetActive(false); PanelFootwears.gameObject.SetActive(false); } public void Sneaker() { shoe.SetActive(false); sneaker.SetActive(true); slipper.SetActive(false); PanelFootwears.gameObject.SetActive(false); } public void Slipper() { shoe.SetActive(false); sneaker.SetActive(false); slipper.SetActive(true); PanelFootwears.gameObject.SetActive(false); } } ``` -------------------------------- ### LeanFinger Touch Input System in C# Source: https://context7.com/king-kloy/ar-project/llms.txt The LeanFinger class in C# stores touch input data for gesture recognition and manipulation within Unity. It tracks finger properties like position, age, tap count, and swipe events. This system is crucial for handling user interactions in AR applications, enabling features like rotation, scaling, and selection. ```csharp using UnityEngine; using System.Collections.Generic; namespace Lean.Touch { public class LeanFinger { public int Index; // Hardware ID of finger public float Age; // Time active in seconds public bool Set; // Currently touching screen public bool LastSet; // Previous frame touch state public bool Tap; // Just tapped public int TapCount; // Number of taps public bool Swipe; // Just swiped public float Pressure; // Touch pressure (device-dependent) public Vector2 StartScreenPosition; public Vector2 LastScreenPosition; public Vector2 ScreenPosition; public bool StartedOverGui; // Started touch over UI public List Snapshots; public bool IsActive { get { return LeanTouch.Fingers.Contains(this); } } public bool IsOverGui { get { return LeanTouch.PointOverGui(ScreenPosition); } } public bool Down { get { return Set == true && LastSet == false; } } public bool Up { get { return Set == false && LastSet == true; } } } } // Example Usage: Detecting Touch Gestures on AR Objects /* using Lean.Touch; using UnityEngine; public class ARObjectInteraction : MonoBehaviour { void Update() { // Get all active touches var fingers = LeanTouch.Fingers; // Single finger drag to rotate if (fingers.Count == 1 && !fingers[0].IsOverGui) { var finger = fingers[0]; if (finger.Set) { Vector2 delta = finger.ScreenPosition - finger.LastScreenPosition; transform.Rotate(Vector3.up, -delta.x * 0.5f, Space.World); transform.Rotate(Vector3.right, delta.y * 0.5f, Space.World); } } // Two finger pinch to scale if (fingers.Count == 2) { var fingerA = fingers[0]; var fingerB = fingers[1]; float lastDistance = Vector2.Distance(fingerA.LastScreenPosition, fingerB.LastScreenPosition); float currentDistance = Vector2.Distance(fingerA.ScreenPosition, fingerB.ScreenPosition); float scaleFactor = currentDistance / lastDistance; transform.localScale *= scaleFactor; } // Tap detection for selection foreach (var finger in fingers) { if (finger.Tap) { Debug.Log("Tapped at: " + finger.ScreenPosition); // Raycast to detect object selection } } } } */ ``` -------------------------------- ### Application Exit Manager in C# Source: https://context7.com/king-kloy/ar-project/llms.txt The ApplicationManager class in C# provides a unified way to handle application exit across different platforms, including the Unity Editor and builds. It abstracts the platform-specific quitting mechanisms. This is essential for providing a consistent user experience when closing the application. ```csharp using UnityEngine; public class ApplicationManager : MonoBehaviour { public void Quit() { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif } } // Example Usage: // 1. Create GameObject "AppManager" and add ApplicationManager component // 2. Create UI Button "Exit" or "Quit" // 3. Link button OnClick() to ApplicationManager.Quit() // 4. In Unity Editor: stops play mode // 5. In Android build: closes application // Best Practice: Add confirmation dialog before quitting /* using UnityEngine; using UnityEngine.UI; public class QuitWithConfirmation : MonoBehaviour { public GameObject confirmationDialog; public ApplicationManager appManager; public void ShowQuitDialog() { confirmationDialog.SetActive(true); } public void ConfirmQuit() { appManager.Quit(); } public void CancelQuit() { confirmationDialog.SetActive(false); } } */ ``` -------------------------------- ### C# Active State Toggle Utility Source: https://context7.com/king-kloy/ar-project/llms.txt A Unity script that provides a simple method to toggle the active state (visibility) of a GameObject. It requires no external dependencies beyond the Unity Engine. Attach this script to any GameObject to enable its visibility to be toggled programmatically. ```csharp using UnityEngine; public class ActiveStateToggler : MonoBehaviour { public void ToggleActive() { gameObject.SetActive(!gameObject.activeSelf); } } ``` -------------------------------- ### Backpack Item Management in Unity C# Source: https://context7.com/king-kloy/ar-project/llms.txt Manages the display of different backpack models in Unity. It activates one backpack GameObject while deactivating others and closes the selection panel. Attach this script to a GameObject and assign prefabs in the Inspector, then call methods via UI buttons. ```csharp using UnityEngine; public class BackpackScript : MonoBehaviour { public GameObject backpackOne; public GameObject backpackTwo; public GameObject backpackThree; public Transform PanelBackpacks; // Usage: Attach to a GameObject and assign backpack prefabs in Inspector // Call these methods from UI buttons to switch between backpack models public void BackpackOne() { backpackOne.SetActive(true); backpackTwo.SetActive(false); backpackThree.SetActive(false); PanelBackpacks.gameObject.SetActive(false); } public void BackpackTwo() { backpackOne.SetActive(false); backpackTwo.SetActive(true); backpackThree.SetActive(false); PanelBackpacks.gameObject.SetActive(false); } public void BackpackThree() { backpackOne.SetActive(false); backpackTwo.SetActive(false); backpackThree.SetActive(true); PanelBackpacks.gameObject.SetActive(false); } } ``` -------------------------------- ### C# AR Model Visibility Control Source: https://context7.com/king-kloy/ar-project/llms.txt A Unity script to manage the visibility of multiple AR models. It dynamically adds an ActiveStateToggler component to each model and provides a method to toggle the visibility of a specific model by its index. This script is useful for controlling collections of AR objects within a scene. ```csharp using UnityEngine; public class ARModelController : MonoBehaviour { public GameObject[] models; void Start() { // Add ActiveStateToggler to each model foreach (var model in models) { if (model.GetComponent() == null) { model.AddComponent(); } } } public void ToggleModel(int index) { if (index >= 0 && index < models.Length) { models[index].GetComponent().ToggleActive(); } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.