//开始触摸 private void OnTouchBegin(EventContext evenContext) { if (touchID == -1)//第一次触摸 { InputEvent inputEvent = (InputEvent)evenContext.data; touchID = inputEvent.touchId; if (tweener != null) { tweener.Kill();//终止上一个动效 tweener = null; } Vector2 localPos = GRoot.inst.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y)); float posX = localPos.x; float posY = localPos.y; joystickButton.selected = true; lastStageX = posX; lastStageY = posY; startStageX = posX; startStageY = posY; joystickCenter.visible = true; joystickCenter.SetXY(posX - joystickCenter.width / 2, posY - joystickCenter.height / 2); joystickButton.SetXY(posX - joystickButton.width / 2, posY - joystickButton.height / 2); evenContext.CaptureTouch(); } }
private void OnTouchBegin(EventContext context) { if (touchID == -1) { InputEvent inputEvent = (InputEvent)context.data; touchID = inputEvent.touchId; if (tweener != null) { tweener.Kill(); tweener = null; } Vector2 localPos = GRoot.inst.GlobalToLocal(inputEvent.position); startPos = localPos; SetCenterPosXY(center, localPos); center.visible = false; SetCenterPosXY(thumb, localPos); thumb.visible = true; Vector2 dir = new Vector2(startPos.x - initPos.x, startPos.y - initPos.y); float radian = Mathf.Atan2(dir.y, dir.x); float degree = radian * 180 / Mathf.PI; thumb.rotation = degree + 90; context.CaptureTouch(); // Debug.Log("===============>TouchBegin"+degree); } }
private void OnPlayFinish() { if (m_GTweener != null) { m_GTweener.Kill(); m_GTweener = null; } OnGameOver(m_UI.m_Sword.rotation >= -110 && m_UI.m_Sword.rotation <= -85); }
private void OnTouchBegin(EventContext context) { if (touchId == -1) //First touch { InputEvent evt = (InputEvent)context.data; touchId = evt.touchId; if (_tweener != null) { _tweener.Kill(); _tweener = null; } Vector2 pt = GRoot.inst.GlobalToLocal(new Vector2(evt.x, evt.y)); float bx = pt.x; float by = pt.y; if (bx < 0) { bx = 0; } else if (bx > _touchArea.width) { bx = _touchArea.width; } if (by > GRoot.inst.height) { by = GRoot.inst.height; } else if (by < _touchArea.y) { by = _touchArea.y; } _lastStageX = bx; _lastStageY = by; _startStageX = _InitX; _startStageY = _InitY; _center.visible = true; //_center.SetXY(bx - _center.width / 2, by - _center.height / 2); _joystick_button.SetXY(bx - _joystick_button.width / 2, by - _joystick_button.height / 2); float deltaX = bx - _InitX; float deltaY = by - _InitY; float degrees = Mathf.Atan2(deltaY, deltaX) * 180 / Mathf.PI; _thumb.rotation = degrees + 90; _thumb.visible = true; _joystick_button.visible = true; context.CaptureTouch(); handleInput(bx, by); } }
//开始触摸 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(); } }