Exemplo n.º 1
0
        /// <summary>
        /// Updates rect transform.
        /// </summary>
        private void UpdateRectTransform()
        {
            if (GameObject == null)
            {
                return;
            }

            if (!PivotProperty.IsUndefined(this))
            {
                RectTransform.pivot = Pivot;
            }

            if (!RotationProperty.IsUndefined(this))
            {
                RectTransform.localRotation = Rotation;
            }

            // update rectTransform
            // horizontal alignment and positioning
            var width  = OverrideWidth ?? (Width ?? ElementSize.DefaultLayout);
            var height = OverrideHeight ?? (Height ?? ElementSize.DefaultLayout);

            float xMin       = 0f;
            float xMax       = 0f;
            float offsetMinX = 0f;
            float offsetMaxX = 0f;

            if (Alignment.HasFlag(ElementAlignment.Left))
            {
                xMin       = 0f;
                xMax       = width.Percent;
                offsetMinX = 0f;
                offsetMaxX = width.Pixels;
            }
            else if (Alignment.HasFlag(ElementAlignment.Right))
            {
                xMin       = 1f - width.Percent;
                xMax       = 1f;
                offsetMinX = -width.Pixels;
                offsetMaxX = 0f;
            }
            else
            {
                xMin       = 0.5f - width.Percent / 2f;
                xMax       = 0.5f + width.Percent / 2f;
                offsetMinX = -width.Pixels / 2f;
                offsetMaxX = width.Pixels / 2f;
            }

            // vertical alignment
            float yMin       = 0f;
            float yMax       = 0f;
            float offsetMinY = 0f;
            float offsetMaxY = 0f;

            if (Alignment.HasFlag(ElementAlignment.Top))
            {
                yMin       = 1f - height.Percent;
                yMax       = 1f;
                offsetMinY = -height.Pixels;
                offsetMaxY = 0f;
            }
            else if (Alignment.HasFlag(ElementAlignment.Bottom))
            {
                yMin       = 0f;
                yMax       = height.Percent;
                offsetMinY = 0f;
                offsetMaxY = height.Pixels;
            }
            else
            {
                yMin       = 0.5f - height.Percent / 2f;
                yMax       = 0.5f + height.Percent / 2f;
                offsetMinY = -height.Pixels / 2f;
                offsetMaxY = height.Pixels / 2f;
            }

            var margin = Margin ?? ElementMargin.Default;

            RectTransform.anchorMin = new Vector2(xMin + margin.Left.Percent, yMin + margin.Bottom.Percent);
            RectTransform.anchorMax = new Vector2(xMax - margin.Right.Percent, yMax - margin.Top.Percent);

            // positioning and margins
            var offset           = Offset?.GetActualOffset(ActualWidth, ActualHeight) ?? ElementMargin.Default;
            var offsetFromParent = OffsetFromParent?.GetActualOffset(ActualWidth, ActualHeight) ?? ElementMargin.Default;

            RectTransform.offsetMin = new Vector2(
                offsetMinX + margin.Left.Pixels + offset.Left.Pixels - offset.Right.Pixels + offsetFromParent.Left.Pixels - offsetFromParent.Right.Pixels,
                offsetMinY + margin.Bottom.Pixels - offset.Top.Pixels + offset.Bottom.Pixels - offsetFromParent.Top.Pixels + offsetFromParent.Bottom.Pixels);
            RectTransform.offsetMax = new Vector2(
                offsetMaxX - margin.Right.Pixels + offset.Left.Pixels - offset.Right.Pixels + offsetFromParent.Left.Pixels - offsetFromParent.Right.Pixels,
                offsetMaxY - margin.Top.Pixels - offset.Top.Pixels + offset.Bottom.Pixels - offsetFromParent.Top.Pixels + offsetFromParent.Bottom.Pixels);

            RectTransform.anchoredPosition = new Vector2(
                RectTransform.offsetMin.x / 2.0f + RectTransform.offsetMax.x / 2.0f,
                RectTransform.offsetMin.y / 2.0f + RectTransform.offsetMax.y / 2.0f);

            if (!PositionProperty.IsUndefined(this))
            {
                RectTransform.localPosition = Position;
            }

            if (!ScaleProperty.IsUndefined(this))
            {
                RectTransform.localScale = Scale;
            }
        }
Exemplo n.º 2
0
        public override int GetHashCode()
        {
            int result = 17;

            unchecked
            {
                if (PathFromParent != null)
                {
                    result = (result * 31) + PathFromParent.GetHashCode();
                }

                result = (result * 31) + OffsetFromParent.GetHashCode();
                result = (result * 31) + Length.GetHashCode();
                if (MimeType != null)
                {
                    result = (result * 31) + MimeType.GetHashCode();
                }

                if (Hashes != null)
                {
                    foreach (var value_0 in Hashes)
                    {
                        result = result * 31;
                        if (value_0 != null)
                        {
                            result = (result * 31) + value_0.GetHashCode();
                        }
                    }
                }

                if (Properties != null)
                {
                    // Use xor for dictionaries to be order-independent.
                    int xor_0 = 0;
                    foreach (var value_1 in Properties)
                    {
                        xor_0 ^= value_1.Key.GetHashCode();
                        if (value_1.Value != null)
                        {
                            xor_0 ^= value_1.Value.GetHashCode();
                        }
                    }

                    result = (result * 31) + xor_0;
                }

                if (Tags != null)
                {
                    foreach (var value_2 in Tags)
                    {
                        result = result * 31;
                        if (value_2 != null)
                        {
                            result = (result * 31) + value_2.GetHashCode();
                        }
                    }
                }
            }

            return(result);
        }