Пример #1
0
        private bool IsPointInsideControlBounds(float2 worldPoint, Entity control)
        {
            var toWorldMatrix      = TransformHelpers.ComputeWorldMatrix(this, control);
            var matrixInverted     = math.inverse(toWorldMatrix);
            var bounds             = GetControlBounds(control);
            var worldPointInverted = math.mul(matrixInverted, new float4(worldPoint.x, worldPoint.y, 0, 1));

            return(bounds.Contains(worldPointInverted.xy));
        }
Пример #2
0
        private void AlignCanvasWithCamera(UICanvas canvas, ref RectTransform rectTransform,
                                           ref Rotation localRotation)
        {
            // I can't use LocalToWorld here, cos it's one frame behind. I need a up-to-date world matrix.
            var toWorldMatrix  = TransformHelpers.ComputeWorldMatrix(this, canvas.camera);
            var cameraWorldPos = toWorldMatrix[3].xy;

            // We are assuming here that uicanvas is always a root, that's why we can assign camera's world position
            // to uicanvas' local position.
            rectTransform.anchoredPosition = cameraWorldPos;

            localRotation.Value = new quaternion(toWorldMatrix);
        }