/// <summary> /// 更新時に呼び出されます。 /// </summary> protected virtual void Update() { if (InputEx.GetKeyDownCombination(KeyCode.LeftControl, KeyCode.Return)) { Debug.Log("KEY COMBINATION!"); } }
// Update is called once per frame void Update() { // 如果按下了攻击键(默认是鼠标左键) if (InputEx.GetButtonDown("Fire1")) { // 播放动画,播放音效 anim.SetTrigger("Shoot"); GetComponent <AudioSource>().Play(); if (playerCtrl.facingRight) { // 角色向右时,向右边发射子弹 // 实例化一个子弹 Rigidbody2D bulletInstance = Instantiate(rocket, transform.position, Quaternion.Euler(new Vector3(0, 0, 0))) as Rigidbody2D; // 直接为刚体设置速度 bulletInstance.velocity = new Vector2(speed, 0); } else { // 角色向左时,向右边发射子弹 // 实例化一个子弹 Rigidbody2D bulletInstance = Instantiate(rocket, transform.position, Quaternion.Euler(new Vector3(0, 0, 180f))) as Rigidbody2D; // 直接为刚体设置速度 bulletInstance.velocity = new Vector2(-speed, 0); } } }
void Update() { // 如果按下炸弹的按钮,且没有已经安置的炸弹,且还有未被安置的炸弹 if (InputEx.GetButtonDown("Fire2") && !bombLaid && bombCount > 0) { // 减少炸弹数量 bombCount--; // 设置已经安放炸弹 bombLaid = true; // 播放音效 AudioSource.PlayClipAtPoint(bombsAway, transform.position); // 实例化一个炸弹到玩家所在位置 Instantiate(bomb, transform.position, transform.rotation); } // 如果炸弹数量大于0,则显示炸弹标志 if (bombCount > 0) { bombHUD.enabled = true; bombNum.enabled = true; bombNum.text = "x" + bombCount; } else { bombHUD.enabled = false; bombNum.enabled = false; } }
IEnumerator CoWaitClick() { isWait = true; clickTime = 0f; while (true) { yield return(null); clickTime += Time.deltaTime; if (Input.GetMouseButtonDown(0)) { var clickable = GetClickables(InputEx.GetMouseWorld()).FindAll(x => x.isDouble).PeekMax(x => x.priority); if (clickable == null) { break; } OnDoubleClickAction?.Invoke(clickable); break; } if (clickTime > doubleInterval) { var clickable = GetClickables(InputEx.GetMouseWorld()).FindAll(x => x.isOnce).PeekMax(x => x.priority); if (clickable == null) { break; } OnOnceClickAction?.Invoke(clickable); break; } } isWait = false; }
private void Update() { if (isLoadingEnd && InputEx.IsAnyKeyPressedThisFrame()) { OnAnyKeyPress(); } }
IEnumerator CoWaitDrag(Vector3 initPos) { isReady = false; while (true) { if (Input.GetMouseButtonUp(0)) { break; } var mousePos = InputEx.GetMouseWorld(); float distance = Vector3.Distance(initPos, mousePos); if (distance > Global.DRAG_DISTANCE) { //드래그 완료 Direction dir = BoardUtil.GetDirection(initPos, mousePos); Block changeBlock = BlockManager.instance.GetNeighbor(selectBlock, dir); if (changeBlock == null) { break; } //블록 스왑 yield return(StartCoroutine(BlockManager.instance.CoSwapBlock(selectBlock, changeBlock))); var selectInfos = MatchManager.instance.Check(selectBlock); var targetInfos = MatchManager.instance.Check(changeBlock); curMatchInfos = MatchUtil.Distinct(selectInfos.Union(targetInfos).ToList()); //스왑 실패 (Undo) if (curMatchInfos.Count == 0) { Debug.Log("Swap Fail"); yield return(StartCoroutine(BlockManager.instance.CoUndoSwap())); break; } //중력 적용 후 맵 생성 (추가 Match가 없을때까지 반복) while (true) { if (curMatchInfos.Count == 0) { break; } BlockManager.instance.DestoryBlocks(MatchUtil.GetCoordsAll(curMatchInfos)); yield return(StartCoroutine(BlockManager.instance.CoApplyGravityAndGenerateMap())); curMatchInfos = MatchManager.instance.CheckAll(); } break; } yield return(null); } if (BlockManager.instance.totalTopCount == 0) { Debug.Log("Win!"); } //초기화 selectBlock = null; isReady = true; }
private void Update() { if (InputEx.IsAnyKeyPressedThisFrame()) { enabled = false; MenuManager.HideTopMenu(); } }
private void Start() { _activeMappings = InputEx.IsControllerConnected() ? controllerMappings : kbMappings; if (_activeMappings.CreateControlBindings().TryGetValue(action, out var binding)) { _binding = binding; } UpdateText(); }
// Update is called once per frame void Update() { // 通过2D射线检测角色与辅助检测对象之间是否存在Ground层中的物体 grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground")); // Debug.DrawLine (transform.position, groundCheck.position, Color.red, 1f); // 如果玩家按下了跳跃键,并且检测到地面,则进入跳跃状态 if (InputEx.GetButtonDown("Jump") && grounded) { jump = true; } }
public void OnPointerDown(PointerEventData data) { pressPosition = myRb.position; timeWhenPressed = Time.time; isPressed = true; draggingTouchIndex = data.pointerId; #if (UNITY_EDITOR || MOUSEINPUT) pressOffsetFromCenter = (Input.mousePosition - this.transform.position); #else pressOffsetFromCenter = (Vector3)InputEx.GetTouchById(draggingTouchIndex).Value.position - this.transform.position; #endif }
private void Update() { if (InputEx.IsControllerConnected()) { mouse.SetActive(false); controller.SetActive(true); } else { mouse.SetActive(true); controller.SetActive(false); } }
private void dtVentaActual_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { int col = dtVentaActual.CurrentCell.ColumnIndex, row = dtVentaActual.CurrentCell.RowIndex; object val = dtVentaActual.CurrentCell.Value; if (dtVentaActual.CurrentCell.ColumnIndex == CANTIDAD) { InputEx inp = new InputEx("Cantidad", "Ingresa la cantidad a añadir del producto seleccionado", ValidatingType.uDouble, val.ToString(), 0, Convert.ToDouble(GetCell(row, EXISTENCIA))); if (inp.ShowDialog() == DialogResult.OK && inp.Value != "0") { dtVentaActual.CurrentCell.Value = inp.Value; CalcRowDat(row); CalcularTotal(); } } }
protected virtual void Update() { if (isPressed && DragTouchEnded()) { PointerUp(); } if (DetectPointerDown()) { PointerDown(); } if (isPressed) { if (Time.time - timeWhenPressed > buttonDisable_Delay) { disableButtonOnDrag.IfNotNull(b => b.interactable = false); } if ((myRb.position - pressPosition).magnitude > minDragDistanceToDisableButton) { disableButtonOnDrag.IfNotNull(b => b.interactable = false); } if (Time.time - timeWhenPressed > dragDelay) { #if (UNITY_EDITOR || MOUSEINPUT) Vector3 position = (Vector3)Input.mousePosition; myRb.MovePosition(position - pressOffsetFromCenter); #else if (InputEx.GetTouchById(draggingTouchIndex).HasValue) { Vector3 position = (Vector3)InputEx.GetTouchById(draggingTouchIndex).Value.position; myRb.MovePosition(position - pressOffsetFromCenter); } #endif } } if (prevPosition.Count >= prevPositionsBuffer) { prevPosition.RemoveAt(0); } prevPosition.Add(this.transform.position); if (useDrag) { myRb.velocity *= releaseDrag; } }
void FixedUpdate() { // 获取水平输入 float h = InputEx.GetAxis("Horizontal"); // 设置动画的速度为水平方向的输入值 anim.SetFloat("Speed", Mathf.Abs(h)); // 如果对象在x轴上的当前方向刚体力小于最大速度,则为对象施加刚体力 if (h * GetComponent <Rigidbody2D>().velocity.x < maxSpeed) { // 给玩家添加刚体力,力的大小为水平方向乘以moveForce, 这里通过h的使用,不需要判断力的方向了 GetComponent <Rigidbody2D>().AddForce(Vector2.right * h * moveForce); } // 如果对象在x轴上的当前方向刚体力大于最大速度 if (Mathf.Abs(GetComponent <Rigidbody2D>().velocity.x) > maxSpeed) { // 使用新的向量来设置速度,通过Mathf.Sign来获取角色的方向乘以最大速度来确定x轴上的速度,保持原方向 GetComponent <Rigidbody2D>().velocity = new Vector2(Mathf.Sign(GetComponent <Rigidbody2D>().velocity.x) * maxSpeed, GetComponent <Rigidbody2D>().velocity.y); } // 判断角色是否需要转身 if (h > 0 && !facingRight) { Flip(); } else if (h < 0 && facingRight) { Flip(); } // 角色跳跃处理 if (jump) { // 播放跳跃动画 anim.SetTrigger("Jump"); // 随机播放一个音效 int i = Random.Range(0, jumpClips.Length); AudioSource.PlayClipAtPoint(jumpClips [i], transform.position); // 为角色跳跃增加向上的刚体力 GetComponent <Rigidbody2D> ().AddForce(new Vector2(0f, jumpFore)); // 重置jump为false,以免为角色不断的增加向上刚体力 jump = false; } }
private void Update() { if (timePassed < timeToShowAnyKeyText) { timePassed += Time.deltaTime; if (timePassed >= timeToShowAnyKeyText) { LeanTweenEx.ChangeAlpha(anyKeyText, 1.0f, 0.2f) .setOnComplete(() => { anyKeyTextAlphaLerp.enabled = anyKeyTextSizeLerp.enabled = true; }); } } if (timePassed >= timeToCanSkip && InputEx.IsAnyKeyPressedThisFrame()) { OnAnyKeyPress(); } }
public void PointerDown() { pressPosition = myRb.position; timeWhenPressed = Time.time; isPressed = true; #if (UNITY_EDITOR || MOUSEINPUT) pressOffsetFromCenter = (Input.mousePosition - this.transform.position); #else pressOffsetFromCenter = (Vector3)InputEx.GetTouchById(draggingTouchIndex).Value.position - this.transform.position; #endif if (makeKinematicWhileDragging) { rbToBodyType.Clear(); foreach (Rigidbody2D rb in this.GetComponentsInChildren <Rigidbody2D>()) { rbToBodyType.Add(rb, rb.bodyType); rb.bodyType = RigidbodyType2D.Kinematic; } } }
private void Update() { bool updateNeeded = false; var mappings = InputEx.IsControllerConnected() ? controllerMappings : kbMappings; if (_activeMappings.CreateControlBindings().TryGetValue(action, out var binding)) { updateNeeded = _binding.HasValue && !Equals(_binding.Value, binding); _binding = binding; } if (mappings != _activeMappings) { _activeMappings = mappings; updateNeeded = true; } if (updateNeeded) { UpdateText(); } }
private void bnBuscarProducto_Click(object sender, EventArgs e) { frmBuscarProducto fBuscarProd = new frmBuscarProducto(false, true); if (fBuscarProd.ShowDialog() == DialogResult.OK) { int cant = Convert.ToInt32(fBuscarProd.Drow[19]); if (cant > 0) { InputEx inp = new InputEx("Cantidad", "Ingresa la cantidad a añadir del producto seleccionado", ValidatingType.uDouble, "1", 0, cant); if (inp.ShowDialog() == DialogResult.OK && inp.Value != "0") { txVentasCodigoBarras.Text = inp.Value + "*" + fBuscarProd.Drow[8].ToString(); AgregarProducto(); } } else { MessageBoxEx.Show("No hay unidades suficientes.", "Error de selección"); bnBuscarProducto.PerformClick(); } } }
void Update() { // bind button events BackButton.onClick.AddListener(backClicked); // ==================================== // You can log input here for debuging... // ==================================== // All button and key input //string keyLabel = InputEx.LogKeys(); //if (keyLabel != null) //{ // InputText.text = keyLabel; // return; //} // All GamePad input string buttonLabel = InputEx.LogButtons(); string analogLabel = InputEx.LogAnalogs(); if (buttonLabel != null) { InputText.text = buttonLabel; } else if (analogLabel != null) { InputText.text = analogLabel; } // Example Input use case examples //if (InputEx.GetButton(ButtonTypes.Start, ControllerPlayers.Any));// do soething... //if (InputEx.GetButtonDown(ButtonTypes.Start, ControllerPlayers.Any));// do soething... //if (InputEx.GetButtonUp(ButtonTypes.Start, ControllerPlayers.Any));// do soething... //if (InputEx.GetAxis(AnalogTypes.AxisLeftX, ControllerPlayers.Any) >= .1f);// do soething... }
private void Update() { if (!isReady) { return; } if (selectBlock != null) { return; } if (Input.GetMouseButtonDown(0)) { var mousePos = InputEx.GetMouseWorld(); RaycastHit2D hitBlock = Physics2D.Raycast(mousePos, Vector2.zero); if (hitBlock.collider != null && hitBlock.collider.gameObject.GetComponent <Block>() != null) { selectBlock = hitBlock.collider.gameObject.GetComponent <Block>(); StartCoroutine(CoWaitDrag(selectBlock.transform.position)); } } }