1.Attribute
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class DataPathAttribute : Attribute
{
public string filePath { get; set; }
public DataPathAttribute(string _filePath)
{
filePath = _filePath;
}
}
//内置聊天内容表
[DataPath("Tables/Chat")]
public class ChatTable:DataTableBase<int>
{
public string content;
}
private void ParserFromTxtFile<T>(string filePath)
{
string file = string.IsNullOrEmpty(filePath) ? ((DataPathAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(DataPathAttribute))).filePath : filePath;
}
2.Extension
//GameObject的扩展
public static class GameObjectExt
{
public static void NewMethod(this GameObject obj)
{
}
}
或者
public class Attack
{
}
//声明扩展的方法的类必须是static
//扩展的方法必须声明为static
//扩展方法必须包含关键字this作为第一个参数类型,后面跟上要扩展的类的名字
public static class ExtensionAttack
{
public static void NewMethod(this Attack attack)
{
}
}