//开始触摸 private void OnTouchBegin(EventContext context) { if (touchID == -1)//第一次触摸 { InputEvent inputEvent = (InputEvent)context.data; touchID = inputEvent.touchId; if (tweener != null) { tweener.Kill();//杀死上一个动画 tweener = null; } //将世界坐标转化为FGUI坐标 Vector2 localPos = GRoot.inst.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y)); float posX = localPos.x; float posY = localPos.y; //注意此处为单选按钮,需要设置单选属性 选中设为true joystickButton.selected = true; lastStageX = posX; lastStageY = posY; startStageX = posX; startStageY = posY; //设置新的摇杆按钮与中心位置 center.visible = true; center.SetXY(posX - center.width / 2, posY - center.height / 2); joystickButton.SetXY(posX - joystickButton.width / 2, posY - joystickButton.height / 2); float deltaX = posX - initX; float deltay = posY - initY; //计算旋转角度 float degrees = Mathf.Atan2(deltay, deltaX) * 180 / Mathf.PI; thumb.rotation = degrees + 90; //上下文获取触摸状态 context.CaptureTouch(); } }
void __touchBegin(EventContext context) { GTween.Kill(this, true); _draggingCorner = (Corner)((GObject)context.sender).data; if (_draggingCorner == Corner.TL || _draggingCorner == Corner.BL) { if (_coverStatus == CoverStatus.ShowingBack) { _coverTurningOp = CoverTurningOp.HideBack; } else if (_objectNewIndice[0] == -1) { if (_frontCover != null && _coverStatus != CoverStatus.ShowingFront) { _coverTurningOp = CoverTurningOp.ShowFront; } else { _draggingCorner = Corner.INVALID; } } else { _turningTarget = _objectNewIndice[0] - 2; if (_turningTarget < 0) { _turningTarget = 0; } } } else { if (_coverStatus == CoverStatus.ShowingFront) { _coverTurningOp = CoverTurningOp.HideFront; } else if (_objectNewIndice[1] == -1) { if (_backCover != null && _coverStatus != CoverStatus.ShowingBack) { _coverTurningOp = CoverTurningOp.ShowBack; } else { _draggingCorner = Corner.INVALID; } } else { _turningTarget = _objectNewIndice[1] + 1; } } if (_draggingCorner != Corner.INVALID) { _touchDownTime = Time.unscaledTime; UpdateDragPosition(context.inputEvent.position); RenderPages(); PlayTurnEffect(); context.CaptureTouch(); } }