Exemplo n.º 1
0
    // Update is called once per frame
    private void Update()
    {
        if (IsActioning)
        {
            if (!CurrentAction.IsActionActive)
            {
                IsActioning = false;
                CurrentTime = 0;
                StopAction();
                ExternalActionWhenFailed?.Invoke();
            }

            CurrentTime           += Time.deltaTime;
            ProgressBar.fillAmount = CurrentTime / TotalTime;
            ProgressBar.transform.parent.position = Camera.main.WorldToScreenPoint(ProcessBarWorldPosition.position) /*+ new Vector3(0, UIOffset)*/;

            if (CurrentTime >= TotalTime)
            {
                PlayParticleEffects(CurrentAction.GetActionableParameters().ActionSuccessParticles, CurrentAction.transform);

                CurrentTime = 0;
                StopAction();
                ActionAfterFinishing?.Invoke(gameObject);
                ExternalActionWhenSuccessful?.Invoke();
                CurrentAction.PlayFinishedActionSFX();
            }
        }
    }
Exemplo n.º 2
0
    internal void AttemptAction(Actionable pAction, MovementController pMovementController = null, Action pExternalActionWhenSuccessful = null, Action pExternalActionWhenFailed = null)
    {
        MovementController           = pMovementController;
        ExternalActionWhenSuccessful = pExternalActionWhenSuccessful;
        ExternalActionWhenFailed     = pExternalActionWhenFailed;
        ActionAfterFinishing         = pAction.OnFinishedAction;
        CurrentAction = pAction;
        var parameters = pAction.GetActionableParameters();

        if (parameters.ActionParticles != null)
        {
            ActionableParticles = Instantiate(parameters.ActionParticles, pAction.transform); //Start particles
            ActionableParticles.transform.rotation = Quaternion.LookRotation(Vector3.forward);
        }

        PlayActionSound();
        PlayAnimation();

        pAction.OnStartAction();
        var progressBar = Instantiate(ProgressBarPrefab);

        progressBar.transform.SetParent(Canvas.transform);
        ProgressBar = progressBar.transform.GetChild(0).GetComponent <Image>();
        TotalTime   = parameters.TimeToTakeAction;
        IsActioning = true;
        MovementController?.StopMovement();
    }
Exemplo n.º 3
0
 private void StopAnimation()
 {
     if (Animator != null && !string.IsNullOrEmpty(CurrentAction?.GetActionableParameters()?.AnimationParameter))
     {
         Animator.SetBool(CurrentAction.GetActionableParameters()?.AnimationParameter, false);
     }
 }