AR虚拟按键为真实识别图上的按键,通过按键可以实现真实与虚拟之间的按键交流
(一)添加按键
点击target,打开advance,添加虚拟按键,即可在此target下添加虚拟按键
注:虚拟按键无法旋转,只能更改长宽,可以通过Name给虚拟按键添加一个标识,通过name访问到此按键
(二)按键触发
public class VirtualBtnController : MonoBehaviour,IVirtualButtonEventHandler//通过接口实现点击事件 { public VirtualButtonBehaviour[] virtualButtons; public UnityEngine.UI.Button[] structureButtons; //public UnityEngine.UI.Button[] structureButtonsCT; public void OnButtonPressed(VirtualButtonBehaviour vb) { Debug.Log("Virtual button "+vb.VirtualButtonName+" pressed"); //BC virtual button function if(vb.VirtualButtonName.Contains("BildgeShell"))//通过Name确认点击俺就 { structureButtons[0].onClick.Invoke(); } if (vb.VirtualButtonName.Contains("BottomSlop")) { structureButtons[2].onClick.Invoke(); } if (vb.VirtualButtonName.Contains("BildgeFloor")) { structureButtons[1].onClick.Invoke(); } if (vb.VirtualButtonName.Contains("Longitudianal")) { structureButtons[4].onClick.Invoke(); } //CT virtual button fuction if (vb.VirtualButtonName.Contains("DeckBeam")) { structureButtons[0].onClick.Invoke(); } if (vb.VirtualButtonName.Contains("Floor")) { structureButtons[1].onClick.Invoke(); } if (vb.VirtualButtonName.Contains("InnerShell")) { structureButtons[2].onClick.Invoke(); } if (vb.VirtualButtonName.Contains("OutShell")) { structureButtons[3].onClick.Invoke(); } if (vb.VirtualButtonName.Contains("LongiBH")) { structureButtons[4].onClick.Invoke(); } if (vb.VirtualButtonName.Contains("TransBH")) { structureButtons[5].onClick.Invoke(); } } public void OnButtonReleased(VirtualButtonBehaviour vb) { Debug.Log("Virtual button released"); } void Start () { foreach(var vb in virtualButtons) { vb.RegisterEventHandler(this); } } }