override protected DisplayObject HitTest() { if (_disabled) return null; if (this.cachedTransform.localScale.x == 0 || this.cachedTransform.localScale.y == 0) return null; Vector2 localPoint = new Vector2(); Vector3 savedWorldPoint = HitTestContext.worldPoint; Vector3 savedDirection = HitTestContext.direction; if (hitArea != null) { if (!hitArea.HitTest(this, ref localPoint)) { HitTestContext.worldPoint = savedWorldPoint; HitTestContext.direction = savedDirection; return null; } } else { localPoint = GetHitTestLocalPoint(); if (_clipRect != null && !((Rect)_clipRect).Contains(localPoint)) { HitTestContext.worldPoint = savedWorldPoint; HitTestContext.direction = savedDirection; return null; } } if (_mask != null && _mask.InternalHitTestMask() == null) return null; DisplayObject target = null; if (touchChildren) { int count = _children.Count; for (int i = count - 1; i >= 0; --i) // front to back! { DisplayObject child = _children[i]; if (child == _mask) continue; target = child.InternalHitTest(); if (target != null) break; } } if (target == null && opaque && (hitArea != null || _contentRect.Contains(localPoint))) target = this; HitTestContext.worldPoint = savedWorldPoint; HitTestContext.direction = savedDirection; return target; }
override protected DisplayObject HitTest() { if (_disabled) { return(null); } if (this.cachedTransform.localScale.x == 0 || this.cachedTransform.localScale.y == 0) { return(null); } Vector3 savedWorldPoint = HitTestContext.worldPoint; Vector3 savedDirection = HitTestContext.direction; Camera savedCamera = HitTestContext.camera; if (this.renderMode == RenderMode.WorldSpace) { HitTestContext.camera = GetRenderCamera(); Vector3 screenPoint = HitTestContext.camera.WorldToScreenPoint(this.cachedTransform.position); //only for query z value screenPoint.x = HitTestContext.screenPoint.x; screenPoint.y = HitTestContext.screenPoint.y; //获得本地z轴在世界坐标的方向 HitTestContext.worldPoint = HitTestContext.camera.ScreenToWorldPoint(screenPoint); Ray ray = HitTestContext.camera.ScreenPointToRay(screenPoint); HitTestContext.direction = Vector3.zero - ray.direction; } Vector2 localPoint = WorldToLocal(HitTestContext.worldPoint, HitTestContext.direction); if (hitArea != null) { if (!hitArea.HitTest(_contentRect, localPoint)) { HitTestContext.worldPoint = savedWorldPoint; HitTestContext.direction = savedDirection; HitTestContext.camera = savedCamera; return(null); } if (hitArea is MeshColliderHitTest) { localPoint = ((MeshColliderHitTest)hitArea).lastHit; } } else { if (_clipRect != null && !((Rect)_clipRect).Contains(localPoint)) { HitTestContext.worldPoint = savedWorldPoint; HitTestContext.direction = savedDirection; HitTestContext.camera = savedCamera; return(null); } } if (_mask != null) { DisplayObject tmp = _mask.InternalHitTestMask(); if (!reversedMask && tmp == null || reversedMask && tmp != null) { HitTestContext.worldPoint = savedWorldPoint; HitTestContext.direction = savedDirection; HitTestContext.camera = savedCamera; return(null); } } DisplayObject target = null; if (touchChildren) { int count = _children.Count; for (int i = count - 1; i >= 0; --i) // front to back! { DisplayObject child = _children[i]; if (child == _mask || child._touchDisabled) { continue; } target = child.InternalHitTest(); if (target != null) { break; } } } if (target == null && opaque && (hitArea != null || _contentRect.Contains(localPoint))) { target = this; } HitTestContext.worldPoint = savedWorldPoint; HitTestContext.direction = savedDirection; HitTestContext.camera = savedCamera; return(target); }
DisplayObject HitTest_Container() { Vector2 localPoint = WorldToLocal(HitTestContext.worldPoint, HitTestContext.direction); if (hitArea != null) { if (!hitArea.HitTest(_contentRect, localPoint)) { return(null); } if (hitArea is MeshColliderHitTest) { localPoint = ((MeshColliderHitTest)hitArea).lastHit; } } else { if (_clipRect != null && !((Rect)_clipRect).Contains(localPoint)) { return(null); } } if (_mask != null && _mask.parent == this) { DisplayObject tmp = _mask.InternalHitTestMask(); if (!reversedMask && tmp == null || reversedMask && tmp != null) { return(null); } } DisplayObject target = null; if (touchChildren) { int count = _children.Count; for (int i = count - 1; i >= 0; --i) // front to back! { DisplayObject child = _children[i]; if (child == _mask || child._touchDisabled) { continue; } target = child.InternalHitTest(); if (target != null) { break; } } } if (target == null && opaque && (hitArea != null || _contentRect.Contains(localPoint))) { target = this; } return(target); }
override protected DisplayObject HitTest() { if (_disabled) { return(null); } Vector2 localPoint = new Vector2(); Vector3 savedWorldPoint = HitTestContext.worldPoint; Vector3 savedDirection = HitTestContext.direction; if (hitArea != null) { if (!hitArea.HitTest(this, ref localPoint)) { HitTestContext.worldPoint = savedWorldPoint; HitTestContext.direction = savedDirection; return(null); } } else { localPoint = GetHitTestLocalPoint(); if (_clipRect != null && !((Rect)_clipRect).Contains(localPoint)) { HitTestContext.worldPoint = savedWorldPoint; HitTestContext.direction = savedDirection; return(null); } } if (_mask != null && _mask.InternalHitTestMask() == null) { return(null); } DisplayObject target = null; if (touchChildren) { int count = _children.Count; for (int i = count - 1; i >= 0; --i) // front to back! { DisplayObject child = _children[i]; if (child == _mask) { continue; } target = child.InternalHitTest(); if (target != null) { break; } } } if (target == null && opaque && _contentRect.Contains(localPoint)) { target = this; } HitTestContext.worldPoint = savedWorldPoint; HitTestContext.direction = savedDirection; return(target); }
override protected DisplayObject HitTest() { if (_scale.X == 0 || _scale.Y == 0) { return(null); } Vector2 savedScreenPoint = HitTestContext.screenPoint; Vector2 localPoint = GlobalToLocal(HitTestContext.screenPoint); if (hitArea != null) { if (!hitArea.HitTest(_contentRect, localPoint)) { return(null); } } else { if (_clipRect != null && !((Rectangle)_clipRect).Contains(localPoint.X, localPoint.Y)) { return(null); } } if (_mask != null && _mask.parent == this) { DisplayObject tmp = _mask.InternalHitTestMask(); if (!reversedMask && tmp == null || reversedMask && tmp != null) { return(null); } } DisplayObject target = null; if (touchChildren) { int count = _children.Count; for (int i = count - 1; i >= 0; --i) // front to back! { DisplayObject child = _children[i]; if (child == _mask || child._touchDisabled) { continue; } target = child.InternalHitTest(); if (target != null) { break; } } } if (target == null && opaque && (hitArea != null || _contentRect.Contains(localPoint.X, localPoint.Y))) { target = this; } HitTestContext.screenPoint = savedScreenPoint; return(target); }