[英]Unity3D, how can I write an extension method for operators?
我試圖擴展Vector3D功能的Vector3 。 它沒有一個小於運算符,所以我試圖創建一個。 但是,當我為它編寫擴展方法時,我的IDE告訴我“Identifier expected,'this'是一個關鍵字”。
如何使用運算符編寫擴展方法? 這是我的嘗試,出乎意料地無效:
using UnityEngine;
using System.Collections;
public static class Vector3Extensions
{
public static bool operator <(this Vector3 vector3, Vector3 other)
{
if (vector3.x < other.x)
{
return true;
}
else if (vector3.x > other.x)
{
return false;
}
else if (vector3.y < other.y)
{
return true;
}
else if (vector3.y > other.y)
{
return false;
}
else if (vector3.z < other.z)
{
return true;
}
return false;
}
}
您不能使用擴展方法來重載運算符。 也許你可以添加.LessThan
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.