using System.Collections; using System.Collections.Generic; using UnityEngine; using Valve.VR; using Valve.VR.InteractionSystem; using Valve.VR.InteractionSystem.Sample; public class ToggleVisibility : MonoBehaviour { public SteamVR_Action_Boolean FixController = SteamVR_Input.GetAction("CMController", "FixController"); Interactable InteractableScript; InputHandling UnderlyingController; LockToPoint LockToPoint; CheckVisible CheckVisible; List Meshs = new List(); // Start is called before the first frame update void Start() { InteractableScript = GetComponent(); UnderlyingController = GetComponent(); InteractableScript.onAttachedToHand += AttachedToHand; InteractableScript.onDetachedFromHand += DetachedToHand; LockToPoint = GetComponent(); CheckVisible = GetComponentInChildren(); // Get Meshes that will be hidden on PickUp Meshs.AddRange(GetComponents()); Meshs.AddRange(GetComponentsInChildren()); } // Update is called once per frame void Update() { if (InteractableScript.attachedToHand && FixController.GetStateDown(InteractableScript.attachedToHand.handType)) { LockToPoint.snapToDynamic.position = InteractableScript.attachedToHand.transform.position; LockToPoint.snapToDynamic.rotation = InteractableScript.attachedToHand.transform.rotation; CheckVisible.enabled = false; LockToPoint.SnapDynamic = true; } } private void AttachedToHand(Hand hand) { CheckVisible.enabled = true; LockToPoint.SnapDynamic = false; Meshs.ForEach(x => x.enabled = false); if (UnderlyingController != null) ControllerButtonHints.ShowButtonHint(hand, UnderlyingController.AvalibleButtons()); } private void DetachedToHand(Hand hand) { Meshs.ForEach(x => x.enabled = true); if (UnderlyingController != null) ControllerButtonHints.HideButtonHint(hand, UnderlyingController.AvalibleButtons()); } }