using System; using System.Reflection; using UnityEngine; namespace Ragdoll { [AttributeUsage(AttributeTargets.Field)] public class RdResetAttribute : Attribute { public string DefaultValue { get; set; } public RdResetAttribute(string defaultValue) { DefaultValue = defaultValue; } } public static class RdResetTool { public static void ResetAttribute(object obj) { var type = obj.GetType(); foreach (var member in type.GetMembers()) { if (Attribute.GetCustomAttribute(member, typeof(RdResetAttribute)) is not RdResetAttribute attribute || member is not FieldInfo field) continue; Debug.Log("重置 " + field.Name); field.SetValue(obj, Convert.ChangeType(attribute.DefaultValue, field.FieldType)); } } } }