コード例 #1
0
        /// <summary>
        /// Process "offset" attribute of node.
        /// </summary>
        /// <param name="widget">Ui widget.</param>
        /// <param name="node">Xml node.</param>
        public static void SetOffset(RectTransform widget, XmlNode node)
        {
            var   point = Vector3.zero;
            float amount;

            var attrValue = node.GetAttribute(HashedOffset);

            if (!string.IsNullOrEmpty(attrValue))
            {
                var parts = MarkupUtils.SplitAttrValue(attrValue);
                if (parts.Length > 0 && !string.IsNullOrEmpty(parts[0]))
                {
                    if (float.TryParse(parts[0], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out amount))
                    {
                        point.x = amount;
                    }
                }
                if (parts.Length > 1 && !string.IsNullOrEmpty(parts[1]))
                {
                    if (float.TryParse(parts[1], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out amount))
                    {
                        point.y = amount;
                    }
                }
            }

            widget.localPosition = point;
        }
コード例 #2
0
        /// <summary>
        /// Process "rotation" attribute of node.
        /// </summary>
        /// <param name="widget">Ui widget.</param>
        /// <param name="node">Xml node.</param>
        public static void SetRotation(RectTransform widget, XmlNode node)
        {
            var   angles = Vector3.zero;
            float amount;

            var attrValue = node.GetAttribute(HashedRotation);

            if (!string.IsNullOrEmpty(attrValue))
            {
                var parts = MarkupUtils.SplitAttrValue(attrValue);
                if (parts.Length > 0 && !string.IsNullOrEmpty(parts[0]))
                {
                    if (float.TryParse(parts[0], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out amount))
                    {
                        if (parts.Length > 1)
                        {
                            angles.x = amount;
                        }
                        else
                        {
                            angles.z = amount;
                        }
                    }
                }
                if (parts.Length > 1 && !string.IsNullOrEmpty(parts[1]))
                {
                    if (float.TryParse(parts[1], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out amount))
                    {
                        angles.y = amount;
                    }
                }
                if (parts.Length > 2 && !string.IsNullOrEmpty(parts[2]))
                {
                    if (float.TryParse(parts[2], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out amount))
                    {
                        angles.z = amount;
                    }
                }
            }

            widget.localRotation = Quaternion.Euler(angles);
        }
コード例 #3
0
        /// <summary>
        /// Process "size" attribute of node.
        /// </summary>
        /// <param name="widget">Ui widget.</param>
        /// <param name="node">Xml node.</param>
        public static void SetSize(RectTransform widget, XmlNode node)
        {
            var    anchorMin = Vector2.zero;
            var    anchorMax = Vector2.one;
            var    offsetMin = Vector3.zero;
            var    offsetMax = Vector3.zero;
            string amountStr;
            float  amount;
            string attrValue;

            attrValue = node.GetAttribute(HashedSize);
            if (!string.IsNullOrEmpty(attrValue))
            {
                int percentIdx;
                var parts = MarkupUtils.SplitAttrValue(attrValue);
                if (parts.Length > 0 && !string.IsNullOrEmpty(parts[0]))
                {
                    amountStr  = parts[0];
                    percentIdx = amountStr.IndexOf('%');
                    if (percentIdx != -1)
                    {
                        // relative.
                        if (float.TryParse(
                                amountStr.Substring(0, percentIdx),
                                NumberStyles.Float,
                                NumberFormatInfo.InvariantInfo,
                                out amount))
                        {
                            amount     *= 0.01f * 0.5f;
                            anchorMin.x = 0.5f - amount;
                            anchorMax.x = 0.5f + amount;
                        }
                    }
                    else
                    {
                        // absolute.
                        if (float.TryParse(amountStr, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out amount))
                        {
                            amount     *= 0.5f;
                            anchorMin.x = 0.5f;
                            anchorMax.x = 0.5f;
                            offsetMin.x = -amount;
                            offsetMax.x = amount;
                        }
                    }
                }
                if (parts.Length > 1 && !string.IsNullOrEmpty(parts[1]))
                {
                    amountStr  = parts[1];
                    percentIdx = amountStr.IndexOf('%');
                    if (percentIdx != -1)
                    {
                        // relative.
                        if (float.TryParse(
                                amountStr.Substring(0, percentIdx),
                                NumberStyles.Float,
                                NumberFormatInfo.InvariantInfo,
                                out amount))
                        {
                            amount     *= 0.01f * 0.5f;
                            anchorMin.y = 0.5f - amount;
                            anchorMax.y = 0.5f + amount;
                        }
                    }
                    else
                    {
                        // absolute.
                        if (float.TryParse(amountStr, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out amount))
                        {
                            amount     *= 0.5f;
                            anchorMin.y = 0.5f;
                            anchorMax.y = 0.5f;
                            offsetMin.y = -amount;
                            offsetMax.y = amount;
                        }
                    }
                }
            }

            widget.anchorMin = anchorMin;
            widget.anchorMax = anchorMax;
            widget.offsetMin = offsetMin;
            widget.offsetMax = offsetMax;
        }