小编Tan*_* Li的帖子

Unity UI - 在光标锁定时与worldspace UI交互

当设置为时,我正在尝试使用第一人称控制器世界空间UI进行交互.Cursor.lockStateCursorLockMode.Locked

世界空间用户界面和一个角色 世界空间用户界面和一个角色

但是当光标被锁定时,光标位置设置为(-1,-1),这是从Inspector告知的.

光标位置(-1,-1) 光标位置(-1,-1)

我进行了图形光线投射EventSystem.RaycastAll,Sreen.width/2PointerEventData.EventSystem.current.RaycastAll收集屏幕中间的所有UI对象,但不会向它们发送任何事件.

我还试图ExecuteEvents.Execute<IEventSystemHandler>将事件发送到UI目标.当我向其发送'submit'事件时,这适用于按钮.显然这不是一个优雅的解决方案.我也不知道如何向滑块发送消息.

// manully send a 'submit' event to UI elements
List<RaycastResult> results = new List<RaycastResult>();
void Update() {
    if (Input.GetButtonUp("Fire1")) {
        PointerEventData data = new PointerEventData(EventSystem.current);
        data.position = new Vector2(Screen.width / 2, Screen.height / 2);
        EventSystem.current.RaycastAll(data, results);
        foreach (var result in results) {
            ExecuteEvents.ExecuteHierarchy<ISubmitHandler>(
                result.gameObject, data,
                ExecuteEvents.submitHandler
            );
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在Windows上全屏播放时,这种疯狂的尝试都有效.2333

[System.Runtime.InteropServices.DllImport("user32.dll")] …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine unity3d-editor unity3d-gui unity5

7
推荐指数
1
解决办法
1091
查看次数