コード例 #1
0
        /// <summary>
        /// Instance of the AI Manager. Only one instance of the AIManager class can be on scene!
        /// </summary>
        /// <param name="onDestroy">Set true when calling on OnDisable/OnDestroy to prevent error while unloading scene or game</param>
        public static AIManager Instance(bool onDestroy = false)
        {
            if (instance == null)
            {
                if (onDestroy)
                {
                    return(null);
                }

                AIManager inScene = FindObjectOfType <AIManager>();
                if (inScene)
                {
                    instance = inScene;
                }
                else
                {
                    GameObject go        = new GameObject("AIManager");
                    AIManager  aIManager = go.AddComponent <AIManager>();
                    instance = aIManager;
                }
            }
            return(instance);
        }
コード例 #2
0
 /// <summary>
 /// Add this entity to the throwind queue
 /// </summary>
 public void Throw()
 {
     AIManager.Instance().Throw();
 }
コード例 #3
0
 /// <summary>
 /// Can this entity throw its grenade?
 /// </summary>
 public bool CanThrow()
 {
     return(AIManager.Instance().CanThrow());
 }
コード例 #4
0
 /// <summary>
 /// Can this entity use its weapon?
 /// </summary>
 public bool CanFire()
 {
     return(AIManager.Instance().CanFire(this));
 }
コード例 #5
0
        private void Update()
        {
            if (Dead)
            {
                return;
            }

            if (navMeshAgent.isOnOffMeshLink && navMeshAgent.currentOffMeshLinkData.offMeshLink && !(GetState() is AIStateClimb))
            {
                Rope rope = navMeshAgent.currentOffMeshLinkData.offMeshLink.GetComponent <Rope>();
                if (rope)
                {
                    ClimbRope(rope.CalculateClimbing(transform));
                }
            }

            if (gettingUp > 0)
            {
                gettingUp -= Time.deltaTime;
            }

            attentionPoint?.SetActive(Sleeping || RagdollEnabled);

            if (ragdoll && (RagdollEnabled || gettingUp > 0))
            {
                navMeshAgent.Warp(RagdollEnabled ? ragdoll.groundPos : transform.position);
                return;
            }

            UpdateRotation();
            if (data.currentState != null)
            {
                data.currentState.Update();
            }

            if (!(GetState() is AIStateClimb))
            {
                navMeshAgent.speed = ((GetState() is AIStateAggresion || GetState() is AIStateCover) && (AIManager.Instance().GetIndex(this) <= 1 || running)) ? runSpeed : walkSpeed;
            }

            if (punchTime > 0)
            {
                punchTime -= Time.deltaTime;
            }

            if (animationAnchor)
            {
                bool firing = punchTime <= 0 && data.currentState == aggresionState || data.currentState == coverState;
                animationAnchor.Animator.SetFloat("Forward", navMeshAgent.velocity.magnitude / runSpeed);
                animationAnchor.Animator.SetBool("IsGrounded", true);
                motionTime += Time.deltaTime / animationAnchor.Animator.GetCurrentAnimatorStateInfo(0).length;
                animationAnchor.Animator.SetFloat("LocomotionTime", motionTime);

                animationAnchor.Animator.SetBool("Crouch", weapon.Reloading());

                if (Player.Instance && sensors.visionResult.playerVisible)
                {
                    Vector3 pos = Player.Instance.GetTargetPos();
                    pos -= Vector3.up * 3.8f;
                    pos += transform.right * 10;
                    pos += transform.forward * 5f;
                    animationAnchor.SetLookAt(pos, firing ? 1 : 0);
                    animationAnchor.Animator.SetLayerWeight(1, firing ? 1 : 0);
                }
                else
                {
                    animationAnchor.SetLookAt(Vector3.up, 0);
                    animationAnchor.Animator.SetLayerWeight(1, 0);
                }
            }
        }
コード例 #6
0
        private void OnDisable()
        {
            AIManager.Instance(true)?.DisposeAI(this);

            sensors.OnHearSound -= Sensors_OnHearSound;
        }
コード例 #7
0
        private void OnEnable()
        {
            AIManager.Instance().RegisterAI(this);

            sensors.OnHearSound += Sensors_OnHearSound;
        }
コード例 #8
0
ファイル: GameUI.cs プロジェクト: alex-kulikov/outblock-unity
        private void Update()
        {
            if (pauseDelayed != pause && !pauseUpdating)
            {
                StartCoroutine(UpdatePause());
            }

            if (saveLoadIndicatorTime > 0)
            {
                saveLoadIndicatorTime -= Time.unscaledDeltaTime;
                Color color = saveLoadIndicator.color;
                color.a = saveLoadIndicatorTime;
                saveLoadIndicator.color = color;
            }

            if (lastEnemyTimeout > 0)
            {
                lastEnemyTimeout  -= Time.deltaTime;
                enemyHP.fillAmount = lastEnemy ? lastEnemy.HPRatio : 0;

                if (lastEnemyTimeout <= 0)
                {
                    lastEnemy = null;
                }
            }
            enemyHPHolder.SetActive(lastEnemyTimeout > 0);

            if (bonusFadeOutTime > 0)
            {
                bonusFadeOutTime -= Time.deltaTime;
            }
            bonusHolder.alpha = bonusFadeOutTime;

            hpSegments.gameObject.SetActive(!(pause && !pauseWindow.activeSelf));

            if (messageTime > 0)
            {
                messageTime -= Time.deltaTime;
                float alpha = Mathf.Clamp01(messageTime);
                messageText.canvasRenderer.SetAlpha(alpha);
            }

            if (pauseWindow.activeSelf)
            {
                bonusHolder.alpha = 1;
            }

            AIManager.States state = AIManager.Instance().GetAIStatus(out float cooldown);
            switch (state)
            {
            case AIManager.States.Idle:
                stealth.color     = Color.clear;
                alertSound.volume = 0;
                alarmSound.volume = 0;
                break;

            case AIManager.States.Attention:
                if (stealth.color == Color.clear)
                {
                    soundContainer.PlaySound("alert");
                }
                stealth.color     = new Color(1, 1, 1, Mathf.PingPong(Time.time * 2, 1));
                alertSound.volume = 0.06f;
                alarmSound.volume = 0;
                break;

            case AIManager.States.Aggresion:
                stealth.color     = Color.red;
                alertSound.volume = 0;
                alarmSound.volume = 0.06f;
                break;
            }

            cooldownHolder.SetActive(cooldown > 0 && cooldown < 1);
            cooldownFill.fillAmount = cooldown;
        }