FairyGUI.Container.GetHitTestLocalPoint C# (CSharp) Method

GetHitTestLocalPoint() public method

public GetHitTestLocalPoint ( ) : Vector2
return Vector2
        public Vector2 GetHitTestLocalPoint()
        {
            if (this.renderMode == RenderMode.WorldSpace)
            {
                Camera camera = GetRenderCamera();

                Vector3 screenPoint = camera.WorldToScreenPoint(this.cachedTransform.position); //only for query z value
                screenPoint.x = HitTestContext.screenPoint.x;
                screenPoint.y = HitTestContext.screenPoint.y;

                //获得本地z轴在世界坐标的方向
                HitTestContext.worldPoint = camera.ScreenToWorldPoint(screenPoint);
                Ray ray = camera.ScreenPointToRay(screenPoint);
                HitTestContext.direction = Vector3.zero - ray.direction;
            }

            return WorldToLocal(HitTestContext.worldPoint, HitTestContext.direction);
        }

Usage Example

Example #1
0
        public bool HitTest(Container container, ref Vector2 localPoint)
        {
            localPoint = container.GetHitTestLocalPoint();

            int x = Mathf.FloorToInt((localPoint.x / scaleX - offsetX) * _data.scale);
            int y = Mathf.FloorToInt((localPoint.y / scaleY - offsetY) * _data.scale);

            if (x < 0 || y < 0 || x >= _data.pixelWidth)
            {
                return(false);
            }

            int pos  = y * _data.pixelWidth + x;
            int pos2 = pos / 8;
            int pos3 = pos % 8;

            if (pos2 >= 0 && pos2 < _data.pixelsLength)
            {
                return(((_data.pixels[_data.pixelsOffset + pos2] >> pos3) & 0x1) > 0);
            }
            else
            {
                return(false);
            }
        }
All Usage Examples Of FairyGUI.Container::GetHitTestLocalPoint