123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- using UnityEngine;
- namespace TModule
- {
- public enum DrawMode
- {
- EditModeAndRunTime,
- OnlyEditMode,
- OnlyRuntime
- }
- [Conditional("UNITY_EDITOR")]
- [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
- public class InspectorAttribute : UnityEngine.PropertyAttribute
- {
- /// <summary>
- /// 显示模式
- /// </summary>
- public DrawMode DrawMode = DrawMode.EditModeAndRunTime;
- /// <summary>
- /// 是否启用复制按钮
- /// </summary>
- public bool IsEnableCopy = false;
- /// <summary>
- /// 是否启用粘贴
- /// </summary>
- public bool IsEnadlePaste = false;
- /// <summary>
- /// 是否显示
- /// </summary>
- public bool IsShow = true;
- }
- /// <summary>
- /// 标签
- /// </summary>
- public class LabelAttribute : InspectorAttribute
- {
- public string Text;
- public LabelAttribute(string text)
- {
- Text = text;
- }
- }
- /// <summary>
- /// 下拉菜单
- /// </summary>
- public class DropdownAttribute : InspectorAttribute
- {
- public List<string> DisplayOptions { get; private set; } = new List<string>();
- public List<object> Values { get; private set; } = new List<object>();
- public DropdownAttribute(IEnumerable<string> displayOptions, IEnumerable<object> values)
- {
- DisplayOptions.AddRange(displayOptions);
- Values.AddRange(values);
- }
- public DropdownAttribute() { }
- }
- /// <summary>
- /// 将某个类型的子类做为下拉菜单
- /// </summary>
- public class TypeDropdownAttribute : DropdownAttribute
- {
- public Type ValueType;
- public TypeDropdownAttribute(Type valueType)
- {
- Values.Add("None");
- DisplayOptions.Add("None");
- foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
- {
- foreach (var type in assembly.GetTypes())
- {
- if (type.IsSubclassOf(valueType) || (type.BaseType != null && type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == valueType))//判断type是否是其派生类
- if (type.IsClass && !type.IsAbstract && type.Name != valueType.Name)
- {
- Values.Add(type.FullName);
- DisplayOptions.Add(type.FullName);
- }
- }
- }
-
- }
- }
- /// <summary>
- /// 场景资源路径
- /// </summary>
- public class SceneAttribute : InspectorAttribute
- {
- }
- public class MethodAttribute:Attribute
- {
- }
- /// <summary>
- /// 在字段后添加一个事件按钮
- /// </summary>
- [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true, Inherited = true)]
- public class EventButtonAttribute : InspectorAttribute
- {
- public string Lable;
- public string Style;
- public string ActionName;
- public string Tip;
- public Texture Texture;
- public Type TypeValue;
- public EventButtonAttribute(string lable, string style, string actionName, Type type)
- {
- Lable = lable;
- Style = style;
- ActionName = actionName;
- TypeValue = type;
- }
- public EventButtonAttribute(string lable, string tip, Texture texture, string actionName, Type type)
- {
- Lable = lable;
- Tip = tip;
- Texture = texture;
- ActionName = actionName;
- TypeValue = type;
- }
- }
- /// <summary>
- /// 方法按钮
- /// </summary>
- [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
- public class ButtonAttribute : MethodAttribute
- {
- public string Name;
- public string CriteriaName;
- public bool CriteriaVaule;
- public object[] Parameter;
- public ButtonAttribute(params object[] parameter)
- {
- Parameter = parameter;
- }
- public ButtonAttribute(string buttonName, params object[] parameter)
- {
- Name = buttonName;
- Parameter = parameter;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="buttonName">按钮显示文字</param>
- /// <param name="criteraName">激活按钮条件名字 可是字段,属性,方法(必须有返回值且返回值为bool)</param>
- /// <param name="criteriaValue">激活条件值</param>
- /// <param name="parameter">参数</param>
- public ButtonAttribute(string buttonName, string criteraName, bool criteriaValue = true, params object[] parameter)
- {
- Name = buttonName;
- CriteriaName = criteraName;
- CriteriaVaule = criteriaValue;
- Parameter = parameter;
- }
- }
- [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
- public class GetTransFormValueAttribute : InspectorAttribute
- {
- public TranType TranType;
- /// <summary>
- /// 获取选中对象的Transform值
- /// </summary>
- /// <param name="tranType">要获取的Transform值TranType类型</param>
- public GetTransFormValueAttribute(TranType tranType)
- {
- TranType = tranType;
- }
- }
- public enum TranType
- {
- None,
- Position,
- Rotation,
- Scale
- }
- /// <summary>
- /// 属性
- /// </summary>
- [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
- public class PropertyAttribute:InspectorAttribute
- {
- public string Lable;
- public PropertyAttribute()
- {
-
- }
- public PropertyAttribute(string lable = "")
- {
- Lable = lable;
- }
- }
- /// <summary>
- /// 关联显示条件
- /// </summary>
- public class RelevancyShowAttribute : InspectorAttribute
- {
- public string FieldName;
- public object ShowValue;
- /// <summary>
- /// 关联字段/属性显示条件
- /// </summary>
- /// <param name="fieldName">关联字段名字</param>
- /// <param name="showValue">字段值为何值时显示</param>
- public RelevancyShowAttribute(string fieldName, object showValue)
- {
- FieldName = fieldName;
- ShowValue = showValue;
- }
- }
- public class OnlyReadAttribute : InspectorAttribute
- {
- }
- public class BegingFoldAttribute:InspectorAttribute
- {
- public string Label;
- public BegingFoldAttribute(string label)
- {
- Label = label;
- }
- }
- public class EndFoldAttribute : InspectorAttribute
- {
- }
- }
|