/// <summary> /// Adds an input handler. /// </summary> /// <param name="type">the type of input handler</param> /// <param name="inputName">the name of the input handler</param> /// <returns><c>true</c>if the handler was added</returns> /// public bool AddMapping(InputManager.InputType type, string inputName) { IDevice device = null; // check for special devices if (inputName.Contains("-|+")) { // plus/minus device String[] parts = inputName.Split(new string[] { "-|+" }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 1) { IDevice deviceMinus = CreateDevice(type, parts[0]); IDevice devicePlus = CreateDevice(type, parts[1]); if ((devicePlus != null) && (deviceMinus != null)) { device = new Device_PlusMinus(devicePlus, deviceMinus); } } } else { // standard device device = CreateDevice(type, inputName); } if (device != null) { // success devices.Add(device); } return(device != null); }
public bool IsValidInput(int playerIndex, Note.Button but, InputManager.InputType type) { Player targetPlayer = Player[playerIndex]; if (playerIndex == AttackerIndex) { AttackSkill skill = targetPlayer.GetAttackSkill(but); // skill is not long button -> ignore long button input if (!skill.IsLongButton && (type == InputManager.InputType.KEEP || type == InputManager.InputType.UP)) { return(false); } // UP or KEEP signal came without DOWN signal -> ignore input if (LastButton != but && (type == InputManager.InputType.KEEP || type == InputManager.InputType.UP)) { return(false); } return(true); } else { // ignore long button input if (type == InputManager.InputType.KEEP || type == InputManager.InputType.UP) { return(false); } return(true); } }
private IDevice CreateDevice(InputManager.InputType type, string inputName) { IDevice device = null; // create specific device subtype switch (type) { case InputManager.InputType.UnityInput: device = new Device_UnityInput(); break; case InputManager.InputType.Keyboard: device = new Device_Keyboard(); break; #if !NO_MOCAP_INPUT case InputManager.InputType.MoCapDevice: device = new Device_MoCap(); break; #endif default: { Debug.LogWarning("Input Type " + type.ToString() + " not supported."); break; } } // try to initialise given the parameter string if (device != null) { inputName = inputName.Trim(); if (!device.Initialise(inputName)) { // failed device = null; } } return(device); }
public void HandleTrigger(InputManager.InputType inputType, float value) { if (!gameObject.activeSelf) { return; } if (client == null) { Debug.LogWarning("Client has not been set! Check the inspector."); return; } if (!client.isActiveAndEnabled) { return; } if (inputType == InputManager.InputType.FIRE) { if (fireType == FireType.FULL) { triggerPulled = value > 0; } else if (fireType == FireType.SEMI && value > 0 && !waitForShot) { SpawnBullet(); } } else if (inputType == InputManager.InputType.FIRE_2) { corsair.aiming = value > 0; } }
bool Move(Vector2 direction, InputManager.InputType type) { if (grid.GetCell((int)(location.x + direction.x), (int)(location.y + direction.y)) == homeState) { location += direction; SetLocation(location); return(true); } return(false); }
public void Update() { if (this.moving_index != -1 && !this.board_objects [this.moving_index].GetComponent <PieceController> ().isMoving()) { this.moving_index = -1; if (this.option_rotation) { this.board.GetComponent <BoardController> ().rotate(); this.is_rotating = true; } else if (this.option_ai && !this.is_ai_moving) { this.is_ai_thinking = this.jarvis.think(); this.information_ai.GetComponent <TextMesh> ().text = "AI is thinking..."; } else if (this.is_ai_moving) { this.is_ai_moving = false; } } if (this.is_rotating && !this.board.GetComponent <BoardController> ().isRotating()) { this.is_rotating = false; if (this.option_ai && !this.is_ai_moving) { this.is_ai_thinking = this.jarvis.think(); this.information_ai.GetComponent <TextMesh> ().text = "AI is thinking..."; } else if (this.is_ai_moving) { this.is_ai_moving = false; } } if (this.is_ai_thinking && !this.jarvis.isThinking()) { this.is_ai_thinking = false; this.information_ai.GetComponent <TextMesh> ().text = ""; int[] ai_decision = this.jarvis.decision(); this.is_ai_moving = true; if (this.referee.move(ai_decision[0], ai_decision[1])) { this.is_ai_moving = true; this.information.GetComponent <TextMesh>().text = ""; Board default_board = this.board_manager.get("default"); GameEvent game_event; while ((game_event = default_board.doLastEvent(ai_decision [0], ai_decision [1])) != GameEvent.NONE) { this.event_to_handler [game_event].Invoke(ai_decision [0], ai_decision [1]); } default_board.swapCurrentTeam(); } } InputManager.InputType current_input = this.input_manager.getNext(); this.input_to_handler [current_input].Invoke(); }
public void DoBattle(uint id, int time) { // assign basic variables Player attacker = (this.AttackerIndex == 0) ? Player[0] : Player[1]; Player defender = (this.AttackerIndex == 0) ? Player[1] : Player[0]; Note.Core attackData = (this.AttackerIndex == 0) ? GetData(0, id) : GetData(1, id); Note.Core defendData = (this.AttackerIndex == 0) ? GetData(1, id) : GetData(0, id); // show miss layer if (attackData.Judge < 50) { JudgeAnim[0].Play("miss", -1, 0); } if (defendData.Judge < 50) { JudgeAnim[1].Play("miss", -1, 0); } // calculate combo CurrentCombo = GetNextCombo( attackData.Button, attackData.Type, attacker.GetAttackSkill(attackData.Button) ); ComboText.text = CurrentCombo.ToString() + " Combo"; // call BattleCore BattleCore(attacker, attackData, defender, defendData, time); // post-battle logic this.LastButton = attackData.Button; this.LastType = attackData.Type; if (attacker.Hp.Value <= 0) { GameObject.Find("BeatGenerator").SetActive(false); GameObject.Find("InputManager1").SetActive(false); GameObject.Find("InputManager2").SetActive(false); attacker.Anim.speed = 0.5f; defender.Anim.speed = 0.5f; attacker.Anim.Play("lose"); StartCoroutine(EndGame((AttackerIndex == 0) ? 1 : 0)); } else if (defender.Hp.Value <= 0) { GameObject.Find("BeatGenerator").SetActive(false); GameObject.Find("InputManager1").SetActive(false); GameObject.Find("InputManager2").SetActive(false); attacker.Anim.speed = 0.5f; defender.Anim.speed = 0.5f; defender.Anim.Play("lose"); StartCoroutine(EndGame(AttackerIndex)); } }
public void HandleMovement(InputManager.InputType inputType, float value) { if (inputType == InputManager.InputType.HORIZONTAL) { horizontal = value; } else if (inputType == InputManager.InputType.VERTICAL) { vertical = value; } }
public void PressUp(int playerIndex, Note.Button but) { Player targetPlayer = Player[playerIndex]; AttackSkill skill = targetPlayer.GetAttackSkill(but); if (skill.IsLongButton && playerIndex == AttackerIndex && but == LastButton && LastType != InputManager.InputType.UP) { targetPlayer.Anim.SetTrigger("hit"); LastButton = Note.Button.NONE; LastType = InputManager.InputType.NONE; } }
/// <summary> /// Adds an input handler. /// </summary> /// <param name="type">the type of input handler</param> /// <param name="inputName">the name of the input handler</param> /// <returns><c>true</c>if the handler was added</returns> /// public bool AddMapping(InputManager.InputType type, string inputName) { IDevice device = null; // check for special devices if (inputName.Contains("-|+")) { // plus/minus device string[] parts = inputName.Split(new string[] { "-|+" }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 1) { IDevice deviceMinus = CreateDevice(type, parts[0]); IDevice devicePlus = CreateDevice(type, parts[1]); if ((devicePlus != null) && (deviceMinus != null)) { device = new Device_PlusMinus(devicePlus, deviceMinus); } } } else if (inputName.Contains("T>") || inputName.Contains("T<")) { // plus/minus device Device_Threshold.EThresholdType thresholdType = inputName.Contains("T>") ? Device_Threshold.EThresholdType.GreaterThan : Device_Threshold.EThresholdType.LessThan; string[] parts = inputName.Split(new string[] { "T>", "T<" }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 1) { IDevice deviceValue = CreateDevice(type, parts[0]); float threshold = 0.5f; float.TryParse(parts[1], out threshold); if (deviceValue != null) { device = new Device_Threshold(deviceValue, thresholdType, threshold); } } } else { // standard device device = CreateDevice(type, inputName); } if (device != null) { // success devices.Add(device); } return(device != null); }
public void PlaceBlock(InputManager.InputType inputType, float value) { if (inputType != InputManager.InputType.FIRE) { return; } if (!gameObject.activeSelf) { return; } HandlePlacement(); }
void Start() { LastButton = Note.Button.NONE; LastType = InputManager.InputType.NONE; LongButtonTime = 0; CurrentCombo = 0; AttackerIndex = 0; CancelFlip = false; Player[0].GetComponent <SpriteRenderer>().material.color = Color.red; Player[1].GetComponent <SpriteRenderer>().material.color = Color.white; DataQueue = new Queue <Note.Core>[2] { new Queue <Note.Core>(), new Queue <Note.Core>() }; }
public static Texture2D GetInputIcon(InputManager.Input input, InputManager.InputType inputType) { int iconSize = 16; Texture2D allIconsTexture = MonoXEngineGame.Instance.Content.Load <Texture2D>("Graphics/InputIcons"); Color[] colors = new Color[iconSize * iconSize]; Rectangle rect = new Rectangle(/* X */ (int)inputType * iconSize, /* Y */ (int)input * iconSize, iconSize, iconSize); allIconsTexture.GetData <Color>(0, rect, colors, 0, colors.Length); Texture2D iconTexture = new Texture2D(Global.GraphicsDevice, iconSize, iconSize); iconTexture.SetData(colors); return(iconTexture); }
// flip attacking player public void FlipAttacker() { if (CancelFlip) { CancelFlip = false; return; } // flip attacker sign & reset combo if (this.AttackerIndex == 0) { this.AttackerIndex = 1; Player[0].GetComponent <SpriteRenderer>().material.color = Color.white; Player[1].GetComponent <SpriteRenderer>().material.color = Color.red; } else { this.AttackerIndex = 0; Player[1].GetComponent <SpriteRenderer>().material.color = Color.white; Player[0].GetComponent <SpriteRenderer>().material.color = Color.red; } this.CurrentCombo = 0; this.LastButton = Note.Button.NONE; this.LastType = InputManager.InputType.NONE; // reset all triggers to avoid unwanted animation foreach (AnimatorControllerParameter param in Player[0].Anim.parameters) { Player[0].Anim.ResetTrigger(param.name); } foreach (AnimatorControllerParameter param in Player[1].Anim.parameters) { Player[1].Anim.ResetTrigger(param.name); } // force playing basic animation Player[0].Anim.Play("basic"); Player[1].Anim.Play("basic"); }
public void DoBattle(uint id, int time) { // assign basic variables Player attacker = (this.AttackerIndex == 0) ? Player[0] : Player[1]; Player defender = (this.AttackerIndex == 0) ? Player[1] : Player[0]; Note.Core attackData = (this.AttackerIndex == 0) ? GetData(0, id) : GetData(1, id); Note.Core defendData = (this.AttackerIndex == 0) ? GetData(1, id) : GetData(0, id); // show miss layer if(attackData.Judge < 50) JudgeAnim[0].Play("miss", -1, 0); if(defendData.Judge < 50) JudgeAnim[1].Play("miss", -1, 0); // calculate combo CurrentCombo = GetNextCombo( attackData.Button, attackData.Type, attacker.GetAttackSkill(attackData.Button) ); ComboText.text = CurrentCombo.ToString() + " Combo"; // call BattleCore BattleCore(attacker, attackData, defender, defendData, time); // post-battle logic this.LastButton = attackData.Button; this.LastType = attackData.Type; if(attacker.Hp.Value <= 0) { GameObject.Find("BeatGenerator").SetActive(false); GameObject.Find("InputManager1").SetActive(false); GameObject.Find("InputManager2").SetActive(false); attacker.Anim.speed = 0.5f; defender.Anim.speed = 0.5f; attacker.Anim.Play("lose"); StartCoroutine(EndGame((AttackerIndex == 0) ? 1 : 0)); } else if(defender.Hp.Value <= 0) { GameObject.Find("BeatGenerator").SetActive(false); GameObject.Find("InputManager1").SetActive(false); GameObject.Find("InputManager2").SetActive(false); attacker.Anim.speed = 0.5f; defender.Anim.speed = 0.5f; defender.Anim.Play("lose"); StartCoroutine(EndGame(AttackerIndex)); } }
// accept user input public void Press(int player, int time, Button but, InputManager.InputType type) { var manager = GameObject.Find("BattleManager").GetComponent <BattleManager>(); float judge = 1 - System.Math.Abs(time - this.Time) / (float)(BeatGenerator.BEAT_MARGIN); // if timing is bad & UP signal is received if (judge <= 0 && type == InputManager.InputType.UP) { manager.PressUp(player, but); } // if timing is good & is valid input, accept else if (judge > 0 && manager.IsValidInput(player, but, type)) { manager.GetReady(player, but, type); manager.ShowJudge(player, (uint)(judge * 50) + 50); CoreData[player].Button = but; CoreData[player].Type = type; CoreData[player].Judge = (uint)(judge * 50) + 50; } }
public void Move(InputManager.InputType input) { switch (input) { case InputManager.InputType.Left: targetX.Left = -4.1f; targetX.Right = -2.9f; break; case InputManager.InputType.Right: targetX.Left = 2.9f; targetX.Right = 4.1f; break; case InputManager.InputType.Both: targetX.Left = -4.1f; targetX.Right = 4.1f; break; case InputManager.InputType.None: targetX.Left = -0.6f; targetX.Right = 0.6f; break; } AdjustConnector(); currentX.Left = Mathf.SmoothDamp(currentX.Left, targetX.Left, ref SpeedXL, timeToMove); currentX.Right = Mathf.SmoothDamp(currentX.Right, targetX.Right, ref SpeedXR, timeToMove); }
// calculates next combo private uint GetNextCombo(Note.Button curBut, InputManager.InputType curType, AttackSkill skill) { // skill not found if (skill == null) { return(0); } // skill is long button & DOWN signal received twice else if (skill.IsLongButton && curType == InputManager.InputType.DOWN) { return(1); } // skill is long button & input is KEEP else if (skill.IsLongButton && LastButton == curBut && LastType != InputManager.InputType.UP && (curType == InputManager.InputType.KEEP || curType == InputManager.InputType.UP)) { return(2); } // new button pressed else if (curBut != Note.Button.NONE && LastButton == Note.Button.NONE) { return(1); } // button accepted -> combo increase else if (curBut != Note.Button.NONE && curBut == LastButton) { return(this.CurrentCombo % skill.TurnLength + 1); } else { return(1); } }
public void GetReady(int playerIndex, Note.Button but, InputManager.InputType type) { Player targetPlayer = Player[playerIndex]; if (playerIndex == AttackerIndex) { AttackSkill skill = targetPlayer.GetAttackSkill(but); uint combo = this.GetNextCombo(but, type, skill); // skill is not long button -> ignore long button input targetPlayer.Anim.ResetTrigger("action"); skill.PlayAnim(targetPlayer.Anim, combo, type == InputManager.InputType.UP); } else { DefendSkill skill = targetPlayer.GetDefendSkill(but); targetPlayer.Anim.ResetTrigger("action"); skill.PlayAnim(targetPlayer.Anim, 1, false); if (skill.Name == "Guard") { EffectAnim[playerIndex].Play("guardmake", -1, 0); } } }
AttackType GetAttackType(InputManager.InputType type) { switch (type) { case InputManager.InputType.DOUBLETAP: return(AttackType.QUICKATTACK); case InputManager.InputType.HOLD: return(AttackType.CHARGE); case InputManager.InputType.NONE: return(AttackType.BLOCK); case InputManager.InputType.PRESS: return(AttackType.ATTACK); case InputManager.InputType.RELEASE: return(AttackType.SPECIALATTACK); default: return(AttackType.NONE); } }
public bool Shoot(Vector3 direction, InputManager.InputType type) { if (bullets.Count >= maxBullets) { return(false); } Quaternion rotation = Quaternion.identity; if (direction == Vector3.up) { rotation = Quaternion.identity; } if (direction == Vector3.down) { rotation = Quaternion.Euler(0, 0, 180); } if (direction == Vector3.right) { rotation = Quaternion.Euler(0, 0, -90); } if (direction == Vector3.left) { rotation = Quaternion.Euler(0, 0, 90); } GameObject obj = Instantiate(bullet, transform.position, rotation); obj.GetComponent <Bullet>().home = this.homeState; obj.GetComponent <Bullet>().player = this; obj.GetComponent <Bullet>().opponent = this.opponent; obj.GetComponent <Bullet>().direction = direction; bullets.Add(obj.GetComponent <Bullet>()); return(true); }
public bool ShootLeft(InputManager.InputType type = InputManager.InputType.Down) { return(Shoot(Vector3.left, type)); }
public void PressUp(int playerIndex, Note.Button but) { Player targetPlayer = Player[playerIndex]; AttackSkill skill = targetPlayer.GetAttackSkill(but); if(skill.IsLongButton && playerIndex == AttackerIndex && but == LastButton && LastType != InputManager.InputType.UP) { targetPlayer.Anim.SetTrigger("hit"); LastButton = Note.Button.NONE; LastType = InputManager.InputType.NONE; } }
public UserControlledPlayer(GameObject gameObject, KeyCode[] directionalControls, InputManager.InputType inputType) : base(gameObject) { _directionalControls = directionalControls; this.inputType = inputType; }
public UserControlledPlayer(GameObject gameObject) : base(gameObject) { inputType = InputManager.InputType.Mouse; }
public UserControlledPlayer(GameObject gameObject, KeyCode[] directionalControls) : base(gameObject) { _directionalControls = directionalControls; inputType = InputManager.InputType.Keyboard; }
public bool MoveRight(InputManager.InputType type = InputManager.InputType.Down) { return(Move(Vector2.right, type)); }
public bool MoveLeft(InputManager.InputType type = InputManager.InputType.Down) { return(Move(Vector2.left, type)); }
public bool MoveDown(InputManager.InputType type = InputManager.InputType.Down) { return(Move(Vector2.up, type)); }
public bool MoveUp(InputManager.InputType type = InputManager.InputType.Down) { return(Move(Vector2.down, type)); }
public bool ShootRight(InputManager.InputType type = InputManager.InputType.Down) { return(Shoot(Vector3.right, type)); }
public bool ShootDown(InputManager.InputType type = InputManager.InputType.Down) { return(Shoot(Vector3.down, type)); }
void Start() { LastButton = Note.Button.NONE; LastType = InputManager.InputType.NONE; LongButtonTime = 0; CurrentCombo = 0; AttackerIndex = 0; CancelFlip = false; Player[0].GetComponent<SpriteRenderer>().material.color = Color.red; Player[1].GetComponent<SpriteRenderer>().material.color = Color.white; DataQueue = new Queue<Note.Core>[2] { new Queue<Note.Core>(), new Queue<Note.Core>() }; }
// flip attacking player public void FlipAttacker() { if(CancelFlip) { CancelFlip = false; return; } // flip attacker sign & reset combo if(this.AttackerIndex == 0) { this.AttackerIndex = 1; Player[0].GetComponent<SpriteRenderer>().material.color = Color.white; Player[1].GetComponent<SpriteRenderer>().material.color = Color.red; } else { this.AttackerIndex = 0; Player[1].GetComponent<SpriteRenderer>().material.color = Color.white; Player[0].GetComponent<SpriteRenderer>().material.color = Color.red; } this.CurrentCombo = 0; this.LastButton = Note.Button.NONE; this.LastType = InputManager.InputType.NONE; // reset all triggers to avoid unwanted animation foreach(AnimatorControllerParameter param in Player[0].Anim.parameters) { Player[0].Anim.ResetTrigger(param.name); } foreach(AnimatorControllerParameter param in Player[1].Anim.parameters) { Player[1].Anim.ResetTrigger(param.name); } // force playing basic animation Player[0].Anim.Play("basic"); Player[1].Anim.Play("basic"); }