【发布时间】:2015-11-18 11:11:01
【问题描述】:
我正在开发一款带有多点触控控制器的游戏。但我在 UI Image 多点触控方面遇到了问题
我想创建这个架构。
绿色循环将用作按钮。 (触摸结束)
Red Cycle 将用作按钮。我需要触摸移动或触摸停留事件来进行连续拍摄。 (触摸移动 | 触摸停留)
黄色框将用作触摸板(UI 图像元素)。当手指在盒子上移动时,会触发Rotate方法。
我尝试了一些方法,但都失败了。
我创建了一个名为 MultiTouchElement 的类。
var touches = Input.touches;
for (int i = 0; i < touches.Count; i++)
{
Touch touch = Input.GetTouch(i);
TouchPhase phase = touch.phase;
PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
eventDataCurrentPosition.position = touch.position;
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
var touchOnThisObject = results.Any(x => x.gameObject.name.ToLower() == this.gameObject.name.ToLower());
if (!touchOnThisObject)
return;
if (phase == TouchPhase.Began)
{
this.GetComponent<Image>().color = Color.red;
}
if (phase == TouchPhase.Ended)
{
this.GetComponent<Image>().color = Color.blue;
}
}
我的架构有教程吗?
【问题讨论】:
标签: c# unity3d multi-touch