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 { /// /// 显示模式 /// public DrawMode DrawMode = DrawMode.EditModeAndRunTime; /// /// 是否启用复制按钮 /// public bool IsEnableCopy = false; /// /// 是否启用粘贴 /// public bool IsEnadlePaste = false; /// /// 是否显示 /// public bool IsShow = true; } /// /// 标签 /// public class LabelAttribute : InspectorAttribute { public string Text; public LabelAttribute(string text) { Text = text; } } /// /// 下拉菜单 /// public class DropdownAttribute : InspectorAttribute { public List DisplayOptions { get; private set; } = new List(); public List Values { get; private set; } = new List(); public DropdownAttribute(IEnumerable displayOptions, IEnumerable values) { DisplayOptions.AddRange(displayOptions); Values.AddRange(values); } public DropdownAttribute() { } } /// /// 将某个类型的子类做为下拉菜单 /// 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); } } } } } /// /// 场景资源路径 /// public class SceneAttribute : InspectorAttribute { } public class MethodAttribute:Attribute { } /// /// 在字段后添加一个事件按钮 /// [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; } } /// /// 方法按钮 /// [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; } /// /// /// /// 按钮显示文字 /// 激活按钮条件名字 可是字段,属性,方法(必须有返回值且返回值为bool) /// 激活条件值 /// 参数 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; /// /// 获取选中对象的Transform值 /// /// 要获取的Transform值TranType类型 public GetTransFormValueAttribute(TranType tranType) { TranType = tranType; } } public enum TranType { None, Position, Rotation, Scale } /// /// 属性 /// [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public class PropertyAttribute:InspectorAttribute { public string Lable; public PropertyAttribute() { } public PropertyAttribute(string lable = "") { Lable = lable; } } /// /// 关联显示条件 /// public class RelevancyShowAttribute : InspectorAttribute { public string FieldName; public object ShowValue; /// /// 关联字段/属性显示条件 /// /// 关联字段名字 /// 字段值为何值时显示 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 { } }