// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) VRMADA, All rights reserved. // // -------------------------------------------------------------------------------------------------------------------- using UltimateXR.Core.Components; using UnityEngine; namespace UltimateXR.Manipulation { /// /// Component used internally by the editor. They are added to keep track of grab pose preview meshes and /// delete them when the preview is no longer needed. /// components will be hidden hanging from each /// . They could have the mesh themselves but when dealing with /// non-uniform scaling in grabbable hierarchies, the preview mesh would be distorted when hanging directly. /// Instead, each component will additionally point to a hidden /// root GameObject with a that will have the mesh data. /// Being a root GameObject will avoid non-uniform scaling problems. /// [ExecuteInEditMode] public class UxrGrabbableObjectPreviewMeshProxy : UxrComponent { #region Public Types & Data /// /// Gets the mesh filter. /// public MeshFilter MeshFilterComponent => GetCachedComponent(); /// /// Gets or sets the preview mesh component that the proxy is following. /// public UxrGrabbableObjectPreviewMesh PreviewMeshComponent { get; set; } /// /// Gets or sets the preview mesh object used by the editor (editor type UxrPreviewHandGripMesh). /// public object PreviewMesh { get; set; } #endregion #region Unity /// /// Makes sure to hide the GameObject initially during play mode when working from the editor. /// protected override void Awake() { if (Application.isPlaying) { base.Awake(); if (Application.isEditor && Application.isPlaying) { gameObject.SetActive(false); } } } #if UNITY_EDITOR /// /// Follow the source object and monitors deletion. /// private void Update() { if (PreviewMeshComponent == null) { if (Application.isPlaying) { Destroy(gameObject); } else { DestroyImmediate(gameObject); } } else { transform.SetPositionAndRotation(PreviewMeshComponent.transform.position, PreviewMeshComponent.transform.rotation); } } #endif #endregion #region Private Types & Data private MeshFilter _meshFilterComponent; #endregion } }