private void OnTriggerEnter(Collider other) { if (other.CompareTag("WindowAnchor")) { // We may have OnTriggerEnter from the other anchor if (!gripped || attached) { return; } WindowAnchor otherAnchor = other.gameObject.GetComponent <WindowAnchor>(); if (otherAnchor.attached) { return; } AnchorTypes otherAnchorType = otherAnchor.anchorType; switch (anchorType) { case AnchorTypes.Left: if (otherAnchorType != AnchorTypes.Right) { return; } break; case AnchorTypes.Right: if (otherAnchorType != AnchorTypes.Left) { return; } break; case AnchorTypes.Bottom: if (otherAnchorType != AnchorTypes.Top) { return; } break; case AnchorTypes.Top: if (otherAnchorType != AnchorTypes.Bottom) { return; } break; } SetTarget(other.transform); StartCoroutine(AnimAnchors()); } }
private void Update() { gripped = Selection.AuxiliarySelection == window.gameObject; // Window hidden if (window.localScale == Vector3.zero) { SetTarget(null); } // Window visible else { if (gripped != previouslyGripped) { ShowAllAnchors(gripped); } // Attach when release grip if (null != target && !gripped && !attached) { WindowAnchor targetAnchor = target.GetComponent <WindowAnchor>(); if (!targetAnchor.attached && !IsWindowAttached()) { attached = true; targetAnchor.otherAttached = true; anchoredObject.SetActive(true); } } // Move window with attached one if (attached) { if (!gripped) { SnapToAnchor(); } else { SetTarget(null); } } } previouslyGripped = gripped; }