【发布时间】:2019-10-28 13:57:00
【问题描述】:
我会回答我自己的问题
我从 Unity 资源商店购买了 InControll 资源。
我想将资产与 Unity UI 事件系统一起使用(并基本上替换独立输入模块)我如何实现这一点?
【问题讨论】:
我会回答我自己的问题
我从 Unity 资源商店购买了 InControll 资源。
我想将资产与 Unity UI 事件系统一起使用(并基本上替换独立输入模块)我如何实现这一点?
【问题讨论】:
经过一些研究和有关该主题的有用 InControl 文档可在此处找到:
http://www.gallantgames.com/pages/incontrol-new-unity-gui
添加您的 UI 元素(按钮)后,将在场景中创建一个 EventSystem 对象。
右键单击层次结构 -> InControl -> InputManager 这将创建一个输入管理器对象。
然后选择 Event System Game Object 并从中移除 Standalone Input Module 并将 InControlInputModule 添加到其中。
然后使用您的自定义脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class MyScript: MonoBehaviour {
public EventSystem eventSystem;
public GameObject selectedObject;
private bool buttonSelected = false;
void Start () {
eventSystem.SetSelectedGameObject (selectedObject);
}
void Update() {
//To get which element is selected.
print (eventSystem.currentSelectedGameObject.name);
}
private void OnDisable () {
buttonSelected = false;
}
}
您应该很高兴再次进行此操作,您可以参考提供的链接以进行更深入的植入。
【讨论】: