扩展方法声明
namespace MyHelp
{
public static class MyClass
{
/// <summary>
/// 返回Hello World
/// </summary>
/// <param name="x"></param>
/// <returns>Hello World</returns>
public static string Print(this Transform x)
{
return "Hello World";
}
}
}
扩展方法调用
using UnityEngine;
using MyHelp;
public class Test : MonoBehaviour
{
public void _Test()
{
transform.Print();
}
}