// instantiates all ability GOs (disabled) for each hand and stores them in allAbilityGOs private void SpawnAbilityInstances() { // for both hands for (int i = 0; i < 2; i++) { HackerHand hand = (HackerHand)i; var abilityPrefabs = abilitySelectionPrefab.GetComponent <AbilitySelectionWheel>().abilityPrefabs; foreach (var prefab in abilityPrefabs) { if (HackerProgression.Instance.GetUnlockedLevel(prefab.GetComponent <AbstractAbility>().Type) < 1) { continue; } var go = Instantiate(prefab, GetHandGO(hand).transform); go.SetActive(false); var abilityScript = go.GetComponent <AbstractAbility>(); abilityScript.InitHackerPlayer(this, hand); abilityScript.ConfigureForLevel(HackerProgression.Instance.GetUnlockedLevel(abilityScript.Type)); if (abilityScript.needsMirroring && hand == HackerHand.Left) { // mirror along X axis go.transform.localScale = new Vector3(-go.transform.localScale.x, go.transform.localScale.y, go.transform.localScale.z); } allAbilityGOs[i].Add(abilityScript.Type, go); } } }
/// <summary>Call this to make the controller vibrate. Strength is between 0 and 1, duration is in seconds.</summary> public void TriggerHapticFeedback(HackerHand hand, float strength, float duration) { if (HapticFeedback != null) { HapticFeedback(hand, strength, duration); } }
private void EnableAbility(HackerHand hand, AbilityType type) { int i = (int)hand; allAbilityGOs[i][type].SetActive(true); equippedAbilities[i] = type; }
// ==== output (haptics) ==== private void Player_HapticFeedback(HackerHand hand, float strength, float duration) { if (hand != GetCurrentHand()) { return; } hapticRemainingDuration = duration; hapticStrength = strength; }
public void CloseAbilitySelectionWheel(HackerHand hand) { AbilitySelectionWheel wheel = selectionWheels[(int)hand]; if (wheel == null) { return; // already closed } Destroy(wheel.gameObject); selectionWheels[(int)hand] = null; }
private AbstractAbility GetEquippedAbilityScript(HackerHand hand) { GameObject go = GetEquippedAbilityGO(hand); if (go != null) { return(go.GetComponent <AbstractAbility>()); // may also return null if the ability has no script (yet) } else { return(null); } }
private GameObject GetEquippedAbilityGO(HackerHand hand) { GameObject go; if (allAbilityGOs[(int)hand].TryGetValue(equippedAbilities[(int)hand], out go)) { return(go); } else { return(null); } }
public void SetAbilitySelectionPosition(HackerHand hand, Vector2 position) { AbilitySelectionWheel wheel = selectionWheels[(int)hand]; if (wheel == null) { return; // not open } if (hand == HackerHand.Left) { // mirror input position.x = -position.x; } wheel.SetPreviewPosition(position); }
private void DisableEquippedAbility(HackerHand hand) { // disable old equipment int i = (int)hand; if (allAbilityGOs[i].ContainsKey(equippedAbilities[i])) { var script = GetEquippedAbilityScript(hand); if (script != null) { // make sure that we stop firing before disabling script.SetTriggerDown(false); script.SetGripDown(false); } allAbilityGOs[i][equippedAbilities[i]].SetActive(false); } }
private IEnumerator SwitchWeapon(HackerHand hand) { selectedWeaponIndex = (selectedWeaponIndex + 1) % selectionPositions.Length; var touchPos = selectionPositions[selectedWeaponIndex]; var touchPosVec = new Vector2(touchPos[0], touchPos[1]) * 0.8f; player.OpenAbilitySelectionWheel(hand); yield return(new WaitForFixedUpdate()); player.SetAbilitySelectionPosition(hand, touchPosVec); yield return(new WaitForSeconds(0.2f)); player.ConfirmAbilitySelection(hand, touchPosVec); yield return(new WaitForSeconds(0.1f)); player.CloseAbilitySelectionWheel(hand); }
private IEnumerator _ConfirmCoroutineHelper(HackerHand hand, Vector2 position) { yield return(null); // delay by one frame AbilitySelectionWheel wheel = selectionWheels[(int)hand]; if (wheel == null) { yield break; // not open } AbilityType?newAbility = wheel.ConfirmSelection(position); if (newAbility != null) { EquipAbility(hand, newAbility.Value); //CloseAbilitySelectionWheel(hand); } }
private void EquipAbility(HackerHand hand, AbilityType type) { int i = (int)hand; Debug.Assert(0 <= i && i <= 1); if (!allAbilityGOs[i].ContainsKey(type)) { Debug.LogWarning("cannot equip ability type, no prefab configured: " + type); return; } // disable old equipment DisableEquippedAbility(hand); // enable new equipment EnableAbility(hand, type); UpdateActiveUltimate(); }
// called by the concrete input handler when the grip state has changed public void SetGripDown(HackerHand hand, bool state) { if (GameData.Instance.isPaused) { return; } var abilityScript = GetEquippedAbilityScript(hand); if (abilityScript != null) { abilityScript.SetGripDown(state); } if (activeUltimate != null) { var otherScript = GetEquippedAbilityScript(hand.Next()); bool both = (abilityScript != null && otherScript != null && abilityScript.IsGripDown && otherScript.IsGripDown); activeUltimate.SetGripDown(both); } }
public void OpenAbilitySelectionWheel(HackerHand hand) { if (ultiActive) { return; } if (selectionWheels[(int)hand] != null) { return; // already open } var go = Instantiate(abilitySelectionPrefab); go.transform.SetParent(GetHandGO(hand).transform, false); selectionWheels[(int)hand] = go.GetComponent <AbilitySelectionWheel>(); if (hand == HackerHand.Left) { // mirror along X axis go.transform.localScale = new Vector3(-go.transform.localScale.x, go.transform.localScale.y, go.transform.localScale.z); } }
public GameObject GetHandGO(HackerHand hand) { return(handGameObjects[(int)hand]); //return (hand == HackerHand.Left ? leftHand : rightHand); }
public void ConfirmAbilitySelection(HackerHand hand, Vector2 position) { StartCoroutine(_ConfirmCoroutineHelper(hand, position)); }
void Update() { // switch perspectives bool?switchPerspective = Util.InputGetAxisDown("NonVR Switch Perspective"); if (switchPerspective != null) { if (switchPerspective == true) { ShowCharacterPerspective(currentPerspective.Next()); } else { ShowCharacterPerspective(currentPerspective.Previous()); } } // collect modifiers bool altHandControl = (Input.GetAxis("NonVR Modify Hand Control") > 0); bool altHandDirection = (Input.GetAxis("NonVR Modify Hand Direction") > 0); // rotate hacker camera if (!altHandControl && (currentPerspective == Perspective.Hacker || currentPerspective == Perspective.Both)) { float x = Input.GetAxis("Mouse X"); float y = Input.GetAxis("Mouse Y"); var angles = transform.localEulerAngles; angles.y += x * rotationSpeed * Time.deltaTime; angles.x -= y * rotationSpeed * Time.deltaTime; // prevent bottom-up camera if (angles.x < 200) { angles.x = Mathf.Min(angles.x, 89); // 0-90 } else { angles.x = Mathf.Max(angles.x, 271); // 270-360 } transform.localEulerAngles = angles; } // move hacker if (currentPerspective == Perspective.Hacker || currentPerspective == Perspective.Both) { float x = Input.GetAxis("Horizontal"); float y = Input.GetAxis("Vertical"); float hbs = blockSize / 2; Vector3 newPosition = transform.localPosition; newPosition += movementSpeed * transform.forward * Time.deltaTime * y; newPosition += movementSpeed * transform.right * Time.deltaTime * x; newPosition.x = Mathf.Clamp(newPosition.x, -hbs, hbs); newPosition.z = Mathf.Clamp(newPosition.z, -hbs, hbs); newPosition.y = transform.localPosition.y; transform.localPosition = newPosition; } // switch hacker hands bool?nextHand = Util.InputGetAxisDown("NonVR Switch Active Hand"); if (nextHand == true) { currentHand = HackerHand.Right; } if (nextHand == false) { currentHand = HackerHand.Left; } // move hacker hands left/right/up/down if (altHandControl && (currentPerspective == Perspective.Hacker || currentPerspective == Perspective.Both)) { float x = Input.GetAxis("Mouse X"); float y = Input.GetAxis("Mouse Y"); GameObject handGO = player.GetHandGO(currentHand); float oldDist = Vector3.Distance(handGO.transform.position, hackerCamera.transform.position); // move Vector3 newPosition = handGO.transform.position; Vector3 baseDirection = altHandDirection ? transform.forward : transform.up; newPosition += handMovementSpeed * baseDirection * Time.deltaTime * y; newPosition += handMovementSpeed * handGO.transform.right * Time.deltaTime * x; // only store, if weapon is still in sight Vector3 viewportPoint = hackerCamera.WorldToViewportPoint(newPosition); if (viewportPoint.x >= 0 && viewportPoint.x <= 1 && viewportPoint.y >= 0 && viewportPoint.y <= 1) { handGO.transform.position = newPosition; } // rotate away from camera to be able to aim handGO.transform.rotation = Quaternion.LookRotation(handGO.transform.position - hackerCamera.transform.position); handGO.transform.Rotate(-10, 0, 0); // to see shot lasers // force hand to stay in same distance if (!altHandDirection) { Vector3 direction = handGO.transform.position - hackerCamera.transform.position; Vector3 directionNorm = direction.normalized; directionNorm *= (oldDist - direction.magnitude); handGO.transform.position += directionNorm; } } // trigger input if (currentPerspective == Perspective.Hacker || currentPerspective == Perspective.Both) { Action <HackerHand, bool> setInputFunc; if (Input.GetKey(KeyCode.LeftShift)) { setInputFunc = player.SetGripDown; } else { setInputFunc = player.SetTriggerDown; } if (Input.GetButtonDown("Fire1")) { setInputFunc(HackerHand.Left, true); } if (Input.GetButtonUp("Fire1")) { setInputFunc(HackerHand.Left, false); } if (Input.GetButtonDown("Fire2")) { setInputFunc(HackerHand.Right, true); } if (Input.GetButtonUp("Fire2")) { setInputFunc(HackerHand.Right, false); } } // switch weapon if (currentPerspective == Perspective.Hacker || currentPerspective == Perspective.Both) { if (Input.GetButtonDown("Jump")) { StartCoroutine(SwitchWeapon(currentHand)); } } }
public void InitHackerPlayer(HackerPlayer script, HackerHand hand) { this.hackerPlayer = script.transform; this.hackerPlayerScript = script; this.hand = hand; }