Пример #1
0
        /// <summary>
        /// Creates a text panel.
        /// </summary>
        /// <param name="content">The <c>ContentArea</c> to put the text panel in.</param>
        /// <param name="name">The name of the text panel game object.</param>
        /// <param name="size">The size of the text panel.</param>
        /// <param name="config">The configuration options for the text panel.</param>
        /// <param name="text">The <c>Text</c> component on the created text panel.</param>
        /// <returns></returns>
        public static ContentArea AddTextPanel(
            this ContentArea content,
            string name,
            RelVector2 size,
            TextPanelConfig config,
            out Text text
            )
        {
            content.AddStaticPanel(name, size, out var go);
            text          = go.AddComponent <Text>();
            text.text     = config.Text;
            text.fontSize = config.Size;
            text.font     = config.Font switch
            {
                TextPanelConfig.TextFont.TrajanRegular => MenuResources.TrajanRegular,
                TextPanelConfig.TextFont.TrajanBold => MenuResources.TrajanBold,
                TextPanelConfig.TextFont.Perpetua => MenuResources.Perpetua,
                TextPanelConfig.TextFont.NotoSerifCJKSCRegular => MenuResources.NotoSerifCJKSCRegular,
                _ => MenuResources.TrajanRegular
            };
            text.supportRichText = true;
            text.alignment       = config.Anchor;

            return(content);
        }
        /// <summary>
        /// Creates an image panel.
        /// </summary>
        /// <param name="content">The <c>ContentArea</c> to put the text panel in.</param>
        /// <param name="name">The name of the image panel game object.</param>
        /// <param name="size">The size of the image panel.</param>
        /// <param name="sprite">The image to render.</param>
        /// <param name="image">The <c>Image</c> component on the created image panel.</param>
        /// <returns></returns>
        public static ContentArea AddImagePanel(
            this ContentArea content,
            string name,
            RelVector2 size,
            Sprite sprite,
            out Image image
            )
        {
            content.AddStaticPanel(name, size, out var go);
            image                = go.AddComponent <Image>();
            image.sprite         = sprite;
            image.preserveAspect = true;

            return(content);
        }