IMGUI-记录

样式

#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace xxx
{
    public class StyleUtils
    {
        public static GUIStyle GetStyle(string stylestr)
        {
            // 使用系统自带的 "AC Button" 样式作为原型,因为 "AC Button" 本身就具有点击效果了
            GUIStyle style = new GUIStyle(stylestr);

             将样式的点击时的效果图,替换为系统自带的 "flow node 4 on" 样式
            //GUIStyle active = new GUIStyle("flow node 3 on");
            //style.active.background = active.normal.background;

             将平时按钮的效果图,替换为系统自带的 "flow node 4" 样式
            //GUIStyle normal = new GUIStyle("flow node 0");
            //style.normal.background = normal.normal.background;

            //style.onNormal.background = active.normal.background;

            // 参考 "flow node 4" 的内部参数,设置一些图片的参数。
            // 如果不设置的话,则图片会按照原 "AC Button" 的样式进行显示
            // 因为图片不一样,所以会有显示上的问题。
            style.stretchHeight = true;
            style.stretchWidth = true;
            style.border = new RectOffset(11, 11, 11, 15);
            style.margin = new RectOffset(2, 2, 0, 0);
            style.padding = new RectOffset(2, 2, 0, 0);
            style.overflow = new RectOffset(7, 7, 6, 9);

            // 进行文本方面的设置
            style.alignment = TextAnchor.MiddleCenter;
            style.fontSize = 14;
            style.richText = true;

            return style;
        }

        public static GUIStyle GetStyle(string stylestr, TextAnchor textAnchor)
        {
            // 使用系统自带的 "AC Button" 样式作为原型,因为 "AC Button" 本身就具有点击效果了
            GUIStyle style = new GUIStyle(stylestr);

             将样式的点击时的效果图,替换为系统自带的 "flow node 4 on" 样式
            //GUIStyle active = new GUIStyle("flow node 3 on");
            //style.active.background = active.normal.background;

             将平时按钮的效果图,替换为系统自带的 "flow node 4" 样式
            //GUIStyle normal = new GUIStyle("flow node 0");
            //style.normal.background = normal.normal.background;

            //style.onNormal.background = active.normal.background;

            // 参考 "flow node 4" 的内部参数,设置一些图片的参数。
            // 如果不设置的话,则图片会按照原 "AC Button" 的样式进行显示
            // 因为图片不一样,所以会有显示上的问题。
            style.stretchHeight = true;
            style.stretchWidth = true;
            style.border = new RectOffset(11, 11, 11, 15);
            style.margin = new RectOffset(2, 2, 0, 0);
            style.padding = new RectOffset(2, 2, 0, 0);
            style.overflow = new RectOffset(7, 7, 6, 9);

            // 进行文本方面的设置
            style.alignment = textAnchor;
            style.fontSize = 14;
            style.richText = true;

            return style;
        }

        public static GUIStyle GetLine()
        {
            GUIStyle style = new GUIStyle("ProfilerRightPane");

            return style;
        }
    }
}

#endif

图片资源特性

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace xxx
{
    [AttributeUsage( AttributeTargets.Field, AllowMultiple =false)]
    public class ImagePathAttribute : Attribute
    {
        private string assetPath = string.Empty;
        public string AssetPath => assetPath;

        public ImagePathAttribute(string assetPath)
        {
            this.assetPath = assetPath;
        }
    }
}


使用方法

		[ImagePath(duck_path + "duck-01.png")]
        public static Texture2D duck_go_2;

多语言特性

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace xxx
{
    [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
    public class TranslationAttribute : Attribute
    {
        private TranslationEnum m_enum;
        public TranslationEnum M_enum => m_enum;
        private string m_str;
        public string M_str => m_str;

        public TranslationAttribute(TranslationEnum @enum, string str)
        {
            m_enum = @enum;
            m_str = str;
        }
    }
}

#if UNITY_EDITOR
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;

namespace xxx
{
    public class AttributeUtils
    {
        public static void GetIconDataAttribute()
        {
            Type type = typeof(IconUtils);

            System.Reflection.FieldInfo[] fieldInfo = type.GetFields();

            foreach (var item in fieldInfo)
            {
                ImagePathAttribute attribute = (ImagePathAttribute)Attribute.GetCustomAttribute(item, typeof(ImagePathAttribute));

                if (attribute != null)
                {
                    var texture = AssetUtils.GetTexture2D(attribute.AssetPath);
                    if (texture != null)
                    {
                        item.SetValue(item, texture);
                    }
                }
            }
        }

        public static void GetTranslationAttribute(TranslationEnum language)
        {
            var type = Activator.CreateInstance<FieldLNGConfig>();// typeof(FieldLNGConfig);

            System.Reflection.FieldInfo[] fieldInfo = typeof(FieldLNGConfig).GetFields();

            foreach (var item in fieldInfo)
            {
                var attribute = (TranslationAttribute[])Attribute.GetCustomAttributes(item, type: typeof(TranslationAttribute));

                foreach (var atr in attribute)
                {
                    if(atr.M_enum == language)
                    {
                        item.SetValue(item, atr.M_str);
                    }
                }
            }
        }
    }
}

#endif


using System.Collections;
using System.Collections.Generic;
using UnityEngine;


namespace xxx
{
    public enum TranslationEnum
    {
        ChineseSimplified = 40,
        Enginlish = 10,
    }

}




使用方法

 		[Translation(TranslationEnum.Enginlish, "Voice Position")]
        [Translation(TranslationEnum.ChineseSimplified, "说话位置")]
        public static string voicePos_str = "";
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值