예제 #1
0
    TWandAction[] Spell.UpdateSpell(ControllerBridge rightController, ControllerBridge leftController)
    {
        TriggerState rightTriggerState        = rightController.GetTriggerState();
        Vector2      rightTouchpadAxis        = rightController.GetTouchpadAxis();
        Vector3      rightControllerPosition  = rightController.GetPosition();
        Vector3      rightControllerDirection = rightController.GetDirection();
        Vector3      rightControllerVelocity  = rightController.GetVelocity();

        TriggerState leftTriggerState = leftController != null?leftController.GetTriggerState() : null;

        Vector2 leftTouchpadAxis = leftController != null?leftController.GetTouchpadAxis() : Vector2.zero;

        Vector3?leftControllerPosition = leftController != null?leftController.GetPosition() : null as Vector3?;

        Vector3?leftControllerDirection = leftController != null?leftController.GetDirection() : null as Vector3?;

        Vector3?leftControllerVelocity = leftController != null?leftController.GetVelocity() : null as Vector3?;

        UpdateControllerStateAndTrap(rightTriggerState, rightTouchpadAxis, rightControllerPosition, rightControllerDirection,
                                     ref rightHandTrapSource, ref rightHandPlacedTrapSource, ref rightHandState, ref rightHandThrowingStartPosition, ref rightHandThrowingStartTime,
                                     ref rightHandThrowVelocity, ref rightHandThrowPosition, ref rightHandThrowTime
                                     );
        UpdateControllerStateAndTrap(leftTriggerState, leftTouchpadAxis, leftControllerPosition, leftControllerDirection,
                                     ref leftHandTrapSource, ref leftHandPlacedTrapSource, ref leftHandState, ref leftHandThrowingStartPosition, ref leftHandThrowingStartTime,
                                     ref leftHandThrowVelocity, ref leftHandThrowPosition, ref leftHandThrowTime
                                     );

        // when both are placed, finish and reset
        if (rightHandState == ControllerAndTrapSourceState.Arrived && leftHandState == ControllerAndTrapSourceState.Arrived)
        {
            MakeTrapSolid(rightHandPlacedTrapSource);
            MakeTrapSolid(leftHandPlacedTrapSource);
            GameObject laser = CreateLaser(rightHandPlacedTrapSource.transform.position, leftHandPlacedTrapSource.transform.position);
            Object.Destroy(rightHandTrapSource);
            Object.Destroy(leftHandTrapSource);
            Object.Destroy(rightHandPlacedTrapSource, lifetime);
            Object.Destroy(leftHandPlacedTrapSource, lifetime);
            Object.Destroy(laser, lifetime);

            Init();
        }

        TWandAction[] actions = { };
        return(actions);
    }
예제 #2
0
    TWandAction[] Spell.UpdateSpell(ControllerBridge rightController, ControllerBridge leftController)
    {
        TriggerState rightTriggerState        = rightController.GetTriggerState();
        Vector2      rightTouchpadAxis        = rightController.GetTouchpadAxis();
        Vector3      rightControllerPosition  = rightController.GetPosition();
        Vector3      rightControllerDirection = rightController.GetDirection();
        Vector3      rightControllerVelocity  = rightController.GetVelocity();

        TriggerState leftTriggerState = leftController != null?leftController.GetTriggerState() : null;

        Vector2 leftTouchpadAxis = leftController != null?leftController.GetTouchpadAxis() : Vector2.zero;

        Vector3?leftControllerPosition = leftController != null?leftController.GetPosition() : null as Vector3?;

        Vector3?leftControllerDirection = leftController != null?leftController.GetDirection() : null as Vector3?;

        Vector3?leftControllerVelocity = leftController != null?leftController.GetVelocity() : null as Vector3?;

        switch (spellSelectState)
        {
        case SpellSelectState.Spawning:
            if (rightTriggerState.down)
            {
                Vector3 position = rightControllerPosition + ((rightControllerPosition - this.playerEyesTransform.position).magnitude * 30f * rightControllerDirection);
                this.lightningObject = GameObject.Instantiate(this.lightningPrefab, new Vector3(0, 0, 0), new Quaternion());

                Transform transformTemp = this.lightningObject.transform;
                this.lightningStart  = transformTemp.GetChild(0).transform;
                this.lightningMitte  = transformTemp.GetChild(1).transform;
                this.lightningTarget = transformTemp.GetChild(2).transform;

                this.lightningMitte.position   = position;
                this.middlePointParticlesystem = this.lightningObject.GetComponentInChildren <ParticleSystem> ();
                this.middlePointParticlesystem.Play();
                this.lightningObject.GetComponent <LineRenderer> ().enabled = false;

                spellSelectState = SpellSelectState.Grabbing;
            }
            break;

        case SpellSelectState.Grabbing:
            if (rightTriggerState.press)
            {
                this.lightningMitte.position = rightControllerPosition + ((rightControllerPosition - this.playerEyesTransform.position).magnitude * 30f * rightControllerDirection);
            }
            else
            {
                CancelSpell();
            }
            if (rightTriggerState.up)
            {
                CancelSpell();
                break;
            }
            if (leftTriggerState.down)
            {
                spellSelectState = SpellSelectState.Dragging;
            }
            break;

        case SpellSelectState.Dragging:
            Vector3?target = FindTarget(this.lightningMitte.position, (Vector3)leftControllerPosition - rightControllerPosition);
            if (target != null)
            {
                this.lightningTarget.position = (Vector3)target;
                this.lightningStart.position  = rightControllerPosition;
                this.lightningMitte.position  = rightControllerPosition + ((rightControllerPosition - this.playerEyesTransform.position).magnitude * 30f * rightControllerDirection);
                this.middlePointParticlesystem.Stop();
                this.lightningObject.GetComponent <LineRenderer> ().enabled = true;
            }
            else
            {
                CancelSpell();
            }
            if (rightTriggerState.up || leftTriggerState.up)
            {
                CancelSpell();
            }
            break;
        }
        TWandAction[] actions = { };
        return(actions);
    }
예제 #3
0
    TWandAction[] Spell.UpdateSpell(ControllerBridge rightController, ControllerBridge leftController)
    {
        TriggerState rightTriggerState        = rightController.GetTriggerState();
        Vector2      rightTouchpadAxis        = rightController.GetTouchpadAxis();
        Vector3      rightControllerPosition  = rightController.GetPosition();
        Vector3      rightControllerDirection = rightController.GetDirection();
        Vector3      rightControllerVelocity  = rightController.GetVelocity();

        TriggerState leftTriggerState = leftController != null?leftController.GetTriggerState() : null;

        Vector2 leftTouchpadAxis = leftController != null?leftController.GetTouchpadAxis() : Vector2.zero;

        Vector3?leftControllerPosition = leftController != null?leftController.GetPosition() : null as Vector3?;

        Vector3?leftControllerDirection = leftController != null?leftController.GetDirection() : null as Vector3?;

        Vector3?leftControllerVelocity = leftController != null?leftController.GetVelocity() : null as Vector3?;

        switch (spellSelectState)
        {
        case SpellSelectState.Aiming:
            if (rightTriggerState.down)
            {
                Vector3?target = FindTarget(rightControllerPosition, rightControllerDirection);

                if (target != null)
                {
                    this.lightningObject = GameObject.Instantiate(this.lightningPrefab, rightControllerPosition - new Vector3(-10, -10, -10), new Quaternion());
                    Transform transformTemp = this.lightningObject.transform;
                    this.lightningStart  = transformTemp.GetChild(0).transform;
                    this.lightningMitte  = transformTemp.GetChild(1).transform;
                    this.lightningTarget = transformTemp.GetChild(2).transform;

                    this.lightningStart.position  = rightControllerPosition;
                    this.lightningTarget.position = (Vector3)target;
                    this.lightningMitte.position  = (this.lightningStart.position + this.lightningTarget.position) / 2;

                    spellSelectState = SpellSelectState.Grabbing;
                }
            }
            break;

        case SpellSelectState.Grabbing:
            if (rightTriggerState.press)
            {
                Vector3?target = FindTarget(rightControllerPosition, rightControllerDirection);
                if (target != null)
                {
                    this.lightningStart.position  = rightControllerPosition;
                    this.lightningTarget.position = (Vector3)target;
                    this.lightningMitte.position  = (this.lightningStart.position + this.lightningTarget.position) / 2;
                }
                else
                {
                    CancelSpell();
                }
            }
            else
            {
                CancelSpell();
            }
            if (leftTriggerState.down)
            {
                this.bendingStartPosition = (Vector3)leftControllerPosition;
                this.middleBeforeBending  = this.lightningMitte.position;
                spellSelectState          = SpellSelectState.Bending;
            }
            break;

        case SpellSelectState.Bending:
            if (leftTriggerState.up)
            {
                spellSelectState = SpellSelectState.Grabbing;
                break;
            }
            if (rightTriggerState.press)
            {
                Vector3?target = FindTarget(rightControllerPosition, rightControllerDirection);
                if (target != null)
                {
                    this.lightningStart.position  = rightControllerPosition;
                    this.lightningTarget.position = (Vector3)target;
                    this.lightningMitte.position  = (this.lightningStart.position + this.lightningTarget.position) / 2;
                    this.middleBeforeBending      = this.lightningMitte.position;
                }
                else
                {
                    CancelSpell();
                }
            }
            else
            {
                CancelSpell();
            }
            if (leftTriggerState.down)
            {
                this.bendingStartPosition = (Vector3)leftControllerPosition;
            }
            Vector3 offset = (Vector3)(this.bendingStartPosition - leftControllerPosition) * 20;
            this.lightningMitte.position = this.middleBeforeBending + offset;
            break;

            // TODO spark effekt wenn man kein ziel getroffen hat
        }
        TWandAction[] actions = { };
        return(actions);
    }