// ------------------------------------------------------------------- public void invokeInputGroupEvent(EInputGroup group, ICommand command) { AbstractCommand absCommand = (AbstractCommand)command; foreach (IUserInputListener listener in inputGroupListeners[group]) { // Pressed key if (absCommand.keyDown) { if (listener == null) { continue; } listener.OnUserInputKeyDown(group, command); } // Holding key if (absCommand.keyHold) { if (listener == null) { continue; } listener.OnUserInputKeyHold(group, command); } // Released key if (!absCommand.keyDown && !absCommand.keyHold) { if (listener == null) { continue; } listener.OnUserInputKeyUp(group, command); } } }
public void OnUserInputKeyUp(EInputGroup group, ICommand command) { if (command is MoveCommand) { movementStateHandler.addCommand(PMovementStateHandler.ECommandType.Up, command); } }
public bool unsubscribeFromInputGroup(EInputGroup group, IUserInputListener listener) { // Check if that input group is currently supported if (!inputGroupListeners.ContainsKey(group)) { return(false); } if (inputGroupListeners[group].Contains(listener)) { inputGroupListeners[group].Remove(listener); } return(true); }
// --- Input event subscription --- public bool subscribeToInputGroup(EInputGroup group, IUserInputListener listener) { // Check if that input group is currently supported if (!inputGroupListeners.ContainsKey(group)) { return(false); } // Make sure we don't add a duplicate listener if (!inputGroupListeners[group].Contains(listener)) { inputGroupListeners[group].Add(listener); } return(true); }
public void OnUserInputKeyHold(EInputGroup group, ICommand command) { /* Tulistamiseks vajalik * if (command is ShootingCommand) * { * * switch (((ShootingCommand)command).control) * { * * case EInputControls.ShootMain: * vajalik kood siia * break; * case EInputControls.ShootAlt: * vajalik kood siia * break; * } * } */ }
public void OnUserInputKeyHold(EInputGroup group, ICommand command) { if (command is MoveCommand) { movementStateHandler.addCommand(PMovementStateHandler.ECommandType.Hold, command); } /* Tulistamiseks vajalik * if (command is ShootingCommand) * { * * switch (((ShootingCommand)command).control) * { * * case EInputControls.ShootMain: * vajalik kood siia * break; * case EInputControls.ShootAlt: * vajalik kood siia * break; * } * } */ }
public void OnUserInputKeyDown(EInputGroup group, ICommand command) { if (command is ShootingCommand) { ShootingCommand shootingCommand = (ShootingCommand)command; //Parse target data Vector2 targetPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Hand[] allHands = FindObjectsOfType <Hand>(); Hand hand = allHands[allHands.Length - 1]; PlayerCharacter player = hand.GetComponentInParent <PlayerCharacter>(); Vector2 playerVelocity = player.GetComponent <Rigidbody2D>().velocity; playerVelocity.Normalize(); Vector2 handPos = new Vector2(hand.transform.position.x, hand.transform.position.y); Vector2 direction = targetPos - handPos; //Normalize the vector for the adding of force direction.Normalize(); Vector2 myPos = new Vector2( hand.transform.position.x + Mathf.Sign(direction.x) * (Mathf.Abs(direction.x) + 1) + (-.5f) * Math.Abs(playerVelocity.x), hand.transform.position.y + direction.y + playerVelocity.y ); Quaternion rotation = Quaternion.Euler(0, 0, -90 + (Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg)); switch (shootingCommand.control) { case EInputControls.ShootMain: // Instead of using the newRocket field, create a manager where you can get main and alt weapons, that have already been set up with the correct components // I.e. an empty projectile prefab, that a manager will attach a mover and an effect component to //Check for cooldown if (timeStampMain > Time.time) { return; } weaponSelectionManager.getMainWeapon().GetComponent <AbsWeaponMover>().SetStartPosition(myPos); if (weaponSelectionManager.getMainWeaponName() == "newPellet") { shootPellets(myPos, rotation, targetPos, handPos, direction); } else { weaponManager.ReuseObject(weaponSelectionManager.getMainWeapon(), myPos, rotation, direction); } //Set cooldown timeStampMain = Time.time + weaponSelectionManager.getMainWeapon().GetComponent <AbsWeaponMover>().cooldownPeriod; break; case EInputControls.ShootAlt: //Check for cooldown if (timeStampAlt > Time.time) { return; } weaponSelectionManager.getAltWeapon().GetComponent <AbsWeaponMover>().SetStartPosition(myPos); if (weaponSelectionManager.getAltWeaponName() == "newPellet") { shootPellets(myPos, rotation, targetPos, handPos, direction); } else { weaponManager.ReuseObject(weaponSelectionManager.getAltWeapon(), myPos, rotation, direction); } //Set cooldown timeStampAlt = Time.time + weaponSelectionManager.getAltWeapon().GetComponent <AbsWeaponMover>().cooldownPeriod; break; } } }
public void OnUserInputKeyUp(EInputGroup group, ICommand command) { }