Пример #1
0
    // 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);
            }
        }
    }
Пример #2
0
 /// <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);
     }
 }
Пример #3
0
    private void EnableAbility(HackerHand hand, AbilityType type)
    {
        int i = (int)hand;

        allAbilityGOs[i][type].SetActive(true);
        equippedAbilities[i] = type;
    }
Пример #4
0
    // ==== output (haptics) ====

    private void Player_HapticFeedback(HackerHand hand, float strength, float duration)
    {
        if (hand != GetCurrentHand())
        {
            return;
        }

        hapticRemainingDuration = duration;
        hapticStrength          = strength;
    }
Пример #5
0
    public void CloseAbilitySelectionWheel(HackerHand hand)
    {
        AbilitySelectionWheel wheel = selectionWheels[(int)hand];

        if (wheel == null)
        {
            return; // already closed
        }
        Destroy(wheel.gameObject);
        selectionWheels[(int)hand] = null;
    }
Пример #6
0
    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);
        }
    }
Пример #7
0
    private GameObject GetEquippedAbilityGO(HackerHand hand)
    {
        GameObject go;

        if (allAbilityGOs[(int)hand].TryGetValue(equippedAbilities[(int)hand], out go))
        {
            return(go);
        }
        else
        {
            return(null);
        }
    }
Пример #8
0
    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);
    }
Пример #9
0
    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);
        }
    }
Пример #10
0
    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);
    }
Пример #11
0
    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);
        }
    }
Пример #12
0
    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();
    }
Пример #13
0
    // 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);
        }
    }
Пример #14
0
    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);
        }
    }
Пример #15
0
 public GameObject GetHandGO(HackerHand hand)
 {
     return(handGameObjects[(int)hand]);
     //return (hand == HackerHand.Left ? leftHand : rightHand);
 }
Пример #16
0
 public void ConfirmAbilitySelection(HackerHand hand, Vector2 position)
 {
     StartCoroutine(_ConfirmCoroutineHelper(hand, position));
 }
Пример #17
0
    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));
            }
        }
    }
Пример #18
0
 public void InitHackerPlayer(HackerPlayer script, HackerHand hand)
 {
     this.hackerPlayer       = script.transform;
     this.hackerPlayerScript = script;
     this.hand = hand;
 }