From 23847f4a2cb7caa7e964787c964e087c4bd97888 Mon Sep 17 00:00:00 2001 From: Gustavo Quiroz Date: Tue, 8 Sep 2020 19:12:01 +0200 Subject: [PATCH 1/2] feat: nested snap zone is not grabbable by default --- Runtime/Interaction/SnapZone.cs | 36 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/Runtime/Interaction/SnapZone.cs b/Runtime/Interaction/SnapZone.cs index d543789..e918d02 100644 --- a/Runtime/Interaction/SnapZone.cs +++ b/Runtime/Interaction/SnapZone.cs @@ -1,6 +1,7 @@ using System.Linq; using System.Collections.Generic; using Innoactive.Creator.BasicInteraction.Validation; +using NAudio.SoundFont; using UnityEngine; using UnityEngine.XR.Interaction.Toolkit; @@ -152,24 +153,22 @@ public Mesh PreviewMesh previewMesh = value; } } - - private Material activeMaterial; - - private List validators = new List(); + private Transform initialParent; + private Material activeMaterial; private Vector3 tmpCenterOfMass; - + private List validators = new List(); + protected override void Awake() { base.Awake(); - - validators = GetComponents().ToList(); - Collider triggerCollider = gameObject.GetComponentsInChildren().FirstOrDefault(foundCollider => foundCollider.isTrigger); - if (triggerCollider == null) + validators = GetComponents().ToList(); + + if (GetComponentsInChildren()?.Any(foundCollider => foundCollider.isTrigger) == false) { - Debug.LogErrorFormat(gameObject, "The Snap Zone '{0}' does not have any trigger collider. " - + "Make sure you have at least one collider with the property `Is Trigger` enabled.", gameObject.name); + Debug.LogError($"The Snap Zone '{name}' does not have any trigger collider. " + + "Make sure you have at least one collider with the property `Is Trigger` enabled.", gameObject); } ShowHighlightObject = ShownHighlightObject != null; @@ -180,12 +179,19 @@ protected override void Awake() { UpdateHighlightMeshFilterCache(); } + + initialParent = transform.parent; + + if (initialParent != null) + { + transform.SetParent(null); + } } protected override void OnEnable() { base.OnEnable(); - + onSelectEnter.AddListener(OnAttach); onSelectExit.AddListener(OnDetach); } @@ -218,6 +224,12 @@ private void OnDrawGizmos() protected virtual void Update() { + if (initialParent != null) + { + transform.SetParent(initialParent); + initialParent = null; + } + if (socketActive && selectTarget == null) { DrawHighlightMesh(); From 52443930b77cd26fcaef7bedf83eb80c9431b5d6 Mon Sep 17 00:00:00 2001 From: Gustavo Quiroz Date: Wed, 9 Sep 2020 08:50:20 +0200 Subject: [PATCH 2/2] chore: cleaning --- Runtime/Interaction/SnapZone.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Runtime/Interaction/SnapZone.cs b/Runtime/Interaction/SnapZone.cs index e918d02..095c7ed 100644 --- a/Runtime/Interaction/SnapZone.cs +++ b/Runtime/Interaction/SnapZone.cs @@ -1,7 +1,6 @@ using System.Linq; using System.Collections.Generic; using Innoactive.Creator.BasicInteraction.Validation; -using NAudio.SoundFont; using UnityEngine; using UnityEngine.XR.Interaction.Toolkit;