Exemplo n.º 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);
        }
        /// <summary>
        /// Creates a sized static panel with no other properties.
        /// </summary>
        /// <param name="content">The <c>ContentArea</c> to put the panel in.</param>
        /// <param name="name">The name of the panel game object.</param>
        /// <param name="size">The size of the panel.</param>
        /// <param name="obj">The newly created panel.</param>
        /// <returns></returns>
        public static ContentArea AddStaticPanel(
            this ContentArea content,
            string name,
            RelVector2 size,
            out GameObject obj
            )
        {
            var go = new GameObject(name);

            GameObject.DontDestroyOnLoad(go);
            go.transform.SetParent(content.ContentObject.transform, false);
            // RectTransform
            var rt = go.AddComponent <RectTransform>();

            size.GetBaseTransformData().Apply(rt);
            content.Layout.ModifyNext(rt);
            // CanvasRenderer
            go.AddComponent <CanvasRenderer>();

            obj = go;
            return(content);
        }
 /// <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>
 /// <returns></returns>
 public static ContentArea AddTextPanel(
     this ContentArea content,
     string name,
     RelVector2 size,
     TextPanelConfig config
     ) => content.AddTextPanel(name, size, config, out _);
 /// <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="image">The image to render.</param>
 /// <returns></returns>
 public static ContentArea AddImagePanel(
     this ContentArea content,
     string name,
     RelVector2 size,
     Sprite image
     ) => content.AddImagePanel(name, size, image, out _);