2015-05-26 146 views
0

我正在做一些异步缓存,我正在使用一个简单的Action回调让系统的其余部分知道缓存何时完成。方法或委托参数与委托参数不匹配


入口点(线导致错误):

this.StartCoroutine<Action>(SceneUtils.CacheSceneNames, PopulateButtons); 

协程方法:

public static IEnumerator CacheSceneNames(Action completedCallback) {} 

回调方法:

private void PopulateButtons() {} 

最后,该方法启动协程:

public static Coroutine StartCoroutine<T>(this MonoBehaviour extends, Func<IEnumerator, T> method, T value) {} 

至于我可以告诉所有的参数和返回类型是正确的,但是我发现了以下错误:

error CS0123: A method or delegate `CacheSceneNames(System.Action)' parameters do not match delegate `System.Func<System.Collections.IEnumerator,System.Action>(System.Collections.IEnumerator)' parameters 

任何人都可以指出我在做什么错误?这可能是一个协变问题吗?

回答

1

我想你想指定Func<T, IEnumerator> method而不是Func<IEnumerator, T> method在参数列表StartCoroutine<T>

这是Func<T, TResult>:返回类型是最后的类型参数 - 和你的CacheSceneNames需要的ActionT)的参数和返回IEnumerator

+0

10/10,谢谢你纠正我愚蠢的错误。当我被允许时将会标记为正确! – Vesuvian