예제 #1
0
 private void OnTriggerEntered(TargetTrigger trigger)
 {
     if (IsParentOfTrigger(trigger))
     {
         FinishBoard(trigger == _correctTrigger || _correctTrigger == null, trigger);
     }
 }
예제 #2
0
 // Use this for initialization
 void Start()
 {
     m_trigger = GetComponentInParent <TargetTrigger>();
     if (m_trigger)
     {
         m_trigger.ActiveChanged += OnActiveChanged;
         m_indicator              = GetComponent <Renderer>();
     }
 }
예제 #3
0
        public void Reset()
        {
            IsFinished = false;

            if (TargetTrigger != null)
            {
                TargetTrigger.Reset();
            }
        }
예제 #4
0
 private bool IsParentOfTrigger(TargetTrigger trigger)
 {
     foreach (TargetTrigger trig in _triggers)
     {
         if (trigger == trig)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #5
0
 private void OnGameplayBoardFinished(GameplayBoard board, TargetTrigger trigger, bool success)
 {
     if (success)
     {
         SFXAudioSource.PlayOneShot(CorrectAnswer);
     }
     else
     {
         SFXAudioSource.PlayOneShot(WrongAnswer);
     }
 }
예제 #6
0
 private void SwitchBoards(GameplayBoard finishedBoard, TargetTrigger trigger)
 {
     if (finishedBoard == StartingBoard)
     {
         StartingBoard.Deactivate();
         OtherBoard.Activate(trigger, true);
     }
     else
     {
         OtherBoard.Deactivate();
         StartingBoard.Activate(trigger, true);
     }
 }
예제 #7
0
    private void OnBoardFinished(GameplayBoard board, TargetTrigger trigger, bool success)
    {
        SwitchBoards(board, trigger);

        if (success)
        {
            _currentScore++;
            _scoreDisplayer.DisplayScore(_currentScore);

            CheckWin();
        }
        else
        {
            Finish(false);
        }
    }
예제 #8
0
    public void OnTriggerEnter(Collider other)
    {
        PigBehaviour  pig    = other.GetComponent <PigBehaviour>();
        TargetTrigger target = other.GetComponent <TargetTrigger>();

        if (pig != null)
        {
            pig.Stun();
        }

        if (target != null)
        {
            target.Explode();
        }

        if (other.rigidbody != null)
        {
            Vector3 direction = (other.transform.position - transform.position);
            direction.z = 0f;
            direction   = direction.normalized;

            other.rigidbody.AddForce(direction * explosionForce, ForceMode.VelocityChange);
        }
    }
예제 #9
0
 internal void OnTargetTrigger(IEntity sender)
 {
     TargetTrigger?.Invoke(sender);
 }
예제 #10
0
    private IEnumerator RestartCoroutine(TargetTrigger previousTrigger, bool instant)
    {
        List <TargetTrigger> triggersToSet    = new List <TargetTrigger>(_triggers).Shuffle();
        List <Sprite>        availableSprites = new List <Sprite>(_targetSprites).Shuffle();
        List <Color>         availableColors  = new List <Color>(_targetColors).Shuffle();


        if (previousTrigger == null)
        {
            previousTrigger = _triggers[0];
            previousTrigger.SetSprite(availableSprites[0]);
            previousTrigger.SetColor(availableColors[0]);
        }

        _player.SetSprite(previousTrigger.Sprite, previousTrigger.Color);

        _correctTrigger = triggersToSet[0];
        _correctTrigger.CorrectAnswerMarker.SetActive(true);
        triggersToSet.RemoveAt(0);

        if (UnityEngine.Random.Range(0f, 1f) < 0.5f)
        {
            Sprite previousSprite = GetSameSpriteFromPool(availableSprites, previousTrigger.Sprite);
            availableSprites.Remove(previousSprite);

            Color correctColor = GetSameColorFromPool(availableColors, previousTrigger.Color);
            _correctTrigger.SetColor(correctColor);
            availableColors.Remove(correctColor);

            _correctTrigger.SetSprite(availableSprites[0]);
            availableSprites.RemoveAt(0);
        }
        else
        {
            Color previousColor = GetSameColorFromPool(availableColors, previousTrigger.Color);
            availableColors.Remove(previousColor);

            Sprite correctSprite = GetSameSpriteFromPool(availableSprites, previousTrigger.Sprite);
            _correctTrigger.SetSprite(correctSprite);
            availableSprites.Remove(correctSprite);

            _correctTrigger.SetColor(availableColors[0]);
            availableColors.RemoveAt(0);
        }


        for (int i = triggersToSet.Count - 1; i >= 0; i--)
        {
            triggersToSet[i].SetColor(availableColors[i]);
            triggersToSet[i].SetSprite(availableSprites[i]);
            triggersToSet[i].CorrectAnswerMarker.SetActive(false);
            availableColors.RemoveAt(i);
            availableSprites.RemoveAt(i);
        }

        ShowGameplayParent(true);

        if (!instant)
        {
            _animator.SetTrigger("show");
            yield return(new WaitForSeconds(1f));
        }

        _player.ResetSpeed();
        _player.transform.position = _playerSpawnPoint.position;
        _player.Release();
        DisplayText("", true);
    }
예제 #11
0
 public void Restart(TargetTrigger previousTrigger, bool instant)
 {
     StartCoroutine(RestartCoroutine(previousTrigger, instant));
 }
예제 #12
0
 private void FinishBoard(bool success, TargetTrigger trigger)
 {
     BoardFinished?.Invoke(this, trigger, success);
 }
예제 #13
0
 public void Activate(TargetTrigger previousTrigger, bool instant)
 {
     Restart(previousTrigger, instant);
     gameObject.SetActive(true);
 }
예제 #14
0
    private void Start()
    {
        // Getting cache variables
        _navMeshAgent     = GetComponent <NavMeshAgent>();
        _animator         = GetComponent <Animator>();
        _mouthAudioSource = GetComponent <AudioSource>();
        _targetTrigger    = GetComponentInChildren <TargetTrigger>();
        AIDecapitation[] parts = GetComponentsInChildren <AIDecapitation>();
        foreach (AIDecapitation part in parts)
        {
            _parts.Add(part);
        }

        HandleAnimatorController();

        // Getting the skinned mesh renderers for the metamorphosis
        if (_metamorphosisMaterial != null)
        {
            SkinnedMeshRenderer[] skinnedMeshRenderers = GetComponentsInChildren <SkinnedMeshRenderer>();
            foreach (SkinnedMeshRenderer meshRenderer in skinnedMeshRenderers)
            {
                _skinnedMeshRenderers.Add(meshRenderer);
            }
        }

        // We always have the rotation of the navmesh deactivated!
        // In fact, we either rotate with the root motion rotation of the turn around animation
        // Or we rotate it manually through code.
        // In sum, the navmesh is only useful for calculating the path: steertingTarget :)
        if (_navMeshAgent != null)
        {
            _navMeshAgent.updateRotation = false;
        }

        if (_targetTrigger != null)
        {
            _targetTrigger.RegisterTargetTrigger(this);
        }

        // Storing states
        AIStateIdle stateIdle = GetComponent <AIStateIdle>();

        if (stateIdle != null)
        {
            _statesDictionary.Add(AIStateType.Idle, stateIdle);
            _statesDictionary[AIStateType.Idle].RegisterState(this);
        }

        AIStatePatrol statePatrol = GetComponent <AIStatePatrol>();

        if (statePatrol != null)
        {
            _statesDictionary.Add(AIStateType.Patrol, statePatrol);
            _statesDictionary[AIStateType.Patrol].RegisterState(this);
        }

        AIStatePursuit statePursuit = GetComponent <AIStatePursuit>();

        if (statePursuit != null)
        {
            _statesDictionary.Add(AIStateType.Pursuit, statePursuit);
            _statesDictionary[AIStateType.Pursuit].RegisterState(this);
        }

        AIStateAttack stateAttack = GetComponent <AIStateAttack>();

        if (stateAttack != null)
        {
            _statesDictionary.Add(AIStateType.Attacking, stateAttack);
            _statesDictionary[AIStateType.Attacking].RegisterState(this);
        }

        AIStateAlert stateAlert = GetComponent <AIStateAlert>();

        if (stateAlert != null)
        {
            _statesDictionary.Add(AIStateType.Alert, stateAlert);
            _statesDictionary[AIStateType.Alert].RegisterState(this);
        }

        if (_statesDictionary.ContainsKey(AIStateType.Idle) && _statesDictionary[AIStateType.Idle] != null)
        {
            ChangeState(AIStateType.Idle);
        }

        // Get all body parts snapshot
        Transform[] bodyParts = transform.GetComponentsInChildren <Transform>();
        foreach (Transform bodyPart in bodyParts)
        {
            BodyPartSnapShot bodyPartSnapshot = new BodyPartSnapShot();
            bodyPartSnapshot.transform = bodyPart;
            _bodyPartsSnapshots.Add(bodyPartSnapshot);
        }

        // At the beginning, we should always be able to scream
        _screamTimer = _screamDelay;

        // Getting the navmesh agent initial speed for damageBehavior (in case we aren't using root rotation)
        if (_navMeshAgent != null)
        {
            _initialSpeed = _navMeshAgent.speed;
        }

        _initialVehicleStoppingDistance = _vehicleStoppingDistance;
    }
예제 #15
0
 public bool TryToStartup()
 {
     return(TargetTrigger.TryToStartUp());
 }