Skip to content

Commit

Permalink
feat: nested snap zones are not grabbable by default (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Quiroz committed Sep 10, 2020
1 parent 00bf849 commit a06dc86
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions Runtime/Interaction/SnapZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,22 @@ public Mesh PreviewMesh
previewMesh = value;
}
}

private Material activeMaterial;

private List<Validator> validators = new List<Validator>();

private Transform initialParent;
private Material activeMaterial;
private Vector3 tmpCenterOfMass;

private List<Validator> validators = new List<Validator>();

protected override void Awake()
{
base.Awake();

validators = GetComponents<Validator>().ToList();

Collider triggerCollider = gameObject.GetComponentsInChildren<Collider>().FirstOrDefault(foundCollider => foundCollider.isTrigger);
if (triggerCollider == null)
validators = GetComponents<Validator>().ToList();

if (GetComponentsInChildren<Collider>()?.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;
Expand All @@ -180,12 +178,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);
}
Expand Down Expand Up @@ -218,6 +223,12 @@ private void OnDrawGizmos()

protected virtual void Update()
{
if (initialParent != null)
{
transform.SetParent(initialParent);
initialParent = null;
}

if (socketActive && selectTarget == null)
{
DrawHighlightMesh();
Expand Down

0 comments on commit a06dc86

Please sign in to comment.