こういう攻撃用のinterfaceを作って、各実装を作る時、
interface IAttackController {
UniTask AttackAsync();
}
class NormalAttackController : IAttackController {
public async UniTask AttackAsync()
{
...
}
}
オブジェクトによっては、攻撃したくないからEmptyAttackControllerってなる時がある。
その際に、
class EmptyAttackController : IAttackController {
public UniTask AttackAsync()
{
}
}
っという何もしないメソッドを持つクラスを作ってみた。
しかし、これだと返り値が無いよって怒られる。
public async UniTask AttackAsync()
{
}
っと書くと、今度はawaitしてないよってwarningが出る
こんなwarning↓
warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
なので、
public async UniTask AttackAsync()
{
await UniTask.Yield();
}
としてみたり、
public async UniTask AttackAsync()
{
await UniTask.Delay(0);
}
としてみたりしたけど、これだと1Frame待ってしまう。
結論
public async UniTask AttackAsync()
{
await UniTask.CompletedTask;
}
これでいけました!これなら待たないです!