在這個問題中,我提到Unity3D,但通常在c#中應用。如果我擴展一個C#接口,我可以吃一個電話嗎?
Unity3D有一個看起來像這樣的接口..
public class SomeRobot:MonoBehaviour, IPointerDownHandler
{
public void OnPointerDown(PointerEventData data)
{
Debug.Log("Gets called whenever someone touches the screen...");
}
沒有問題爲止。
我做我自己的接口..
public interface IFUHandler:IPointerDownHandler
{
void OnBlah (PointerEventData data);
}
假設我有一個後臺程序或任何能爲消費者的接口調用OnBlah。
public class SomeRobot:MonoBehaviour, IFUHandler
{
public void OnBlah(PointerEventData data)
{
Debug.Log("Gets called when blah happens...");
}
到目前爲止沒有問題。但是
public class SomeRobot:MonoBehaviour, IFUHandler
{
public void OnBlah(PointerEventData data)
{
Debug.Log("Gets called when blah happens...");
}
public void OnPointerDown(PointerEventData data)
{
Debug.Log("this DOES still get called also...");
}
事實上,OnPointerDown
仍然被調用。這是有道理的。
但....有沒有辦法讓我的界面吃掉OnPointerDown的電話?
因此,訂購IFUHandler
的消費者其實未獲得致電OnPointerDown
?
(當然得到我OnBlah
電話。)
還是我患的是 「TMIOOK」 在想什麼? (並列自己在OO節想:))
這是一個非常有趣的問題創建一個密封的抽象類。我會試驗看看這是否可能。 – Programmer
[PointerEventData](https://docs.unity3d.com/ScriptReference/EventSystems.PointerEventData.html)有[used](https://docs.unity3d.com/ScriptReference/EventSystems.AbstractEventData-used.html)成員。你可以將它設置爲「true」來阻止其他任何反應嗎? – ChrisF
嗨@ChrisF - 呃..我的意思是,在哪裏?! (另外,我想 - 在「一般C#問題」情況下不會真的有幫助......我想。) – Fattie