返回

unity3d-有没有在c#中创建自定义关键字的方法?

发布时间:2022-03-23 12:36:33 343
# c++# flask

我创建了这个简单的类,它的性能类似于if语句,但只有在其被触发时:

/// 
    /// Triggers the specified code in the execution block the first time that the paramaters return true
    /// 
    /// 
    /// 
    public When(Func validator, Action executor)
    {
        this.validator = validator;
        
        this.executor = executor;
        
        //Creates an object to start the coroutine
        GameObject dummyObj = new GameObject("_WhenClassDummyGameObjectForCoroutine");
        dummyObj.AddComponent().StartCoroutine(WhenCoRo());
        dummyObj.hideFlags = HideFlags.HideInHierarchy;
        
    }




    public IEnumerator WhenCoRo()
    {
        yield return null;
        while (true)
        {
            if (validator.Invoke())
            {
                executor.Invoke();
                yield break;
            }
            yield return null;
        }
    }

问题是,你需要以一种非常复杂的方式调用它:

When when = new When(() => b > a,
            () =>
            {
                Debug.Log("When Has Been Triggered");
            }
            );

我想做的是:

when (b > a)
{
    Debug.Log("When Has Been Triggered");
}

有人知道如何做到这一点吗?

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像