コード例 #1
0
        private void FixedUpdate()
        {
            if (HUDObject.activeSelf)
            {
                DeactiveTimer += Time.deltaTime;

                if (DeactiveTimer >= DeactiveSeconds)
                {
                    EmeraldComponent = null;
                    HUDObject.SetActive(false);
                    DeactiveTimer = 0;
                }
            }

            if (EmeraldComponent != null)
            {
                HUDObject.SetActive(true);
                AINameText.text        = EmeraldComponent.AIName;
                AIHealthBar.fillAmount = (float)EmeraldComponent.CurrentHealth / EmeraldComponent.StartingHealth;

                if (AIHealthBar.fillAmount <= 0)
                {
                    if (HUDObject.activeSelf)
                    {
                        EmeraldComponent = null;
                    }
                }
            }
        }
コード例 #2
0
 public override void Start()
 {
     base.Start();
     anim    = GetComponent <Animator>();
     emerald = GetComponent <EmeraldAISystem>();
     agent   = GetComponent <NavMeshAgent>();
 }
コード例 #3
0
ファイル: TameAI.cs プロジェクト: sc8di/dualism
        void Update()
        {
            Debug.DrawRay(transform.position, transform.forward * 6);
            //Draw a ray foward from our player at a distance according to the TameDistance
            if (Physics.Raycast(transform.position, transform.forward, out hit, TameDistance))
            {
                if (hit.collider.CompareTag(AITag))
                {
                    if (Input.GetKeyDown(KeyCode.F))
                    {
                        //Check to see if the object we have hit contains an Emerald AI component
                        if (hit.collider.gameObject.GetComponent <EmeraldAISystem>() != null)
                        {
                            //Get a reference to the Emerald AI object that was hit
                            EmeraldAISystem EmeraldComponent = hit.collider.gameObject.GetComponent <EmeraldAISystem>();

                            //Check to see if our hit Emerald AI's behavior is not aggressive or companion so we can tame it
                            if (EmeraldComponent.BehaviorRef != EmeraldAISystem.CurrentBehavior.Aggressive && EmeraldComponent.BehaviorRef != EmeraldAISystem.CurrentBehavior.Companion)
                            {
                                //Calls the TameAI function that allows an AI to be tamed.
                                EmeraldComponent.EmeraldEventsManagerComponent.TameAI(transform);
                                //Update the AI's UI colors to blue, as well as update the AI's name, to indicate the AI has been tamed.
                                EmeraldComponent.EmeraldEventsManagerComponent.UpdateUIHealthBarColor(new Color(0.1f, 0.1f, 1, 1));
                                EmeraldComponent.EmeraldEventsManagerComponent.UpdateUINameColor(new Color(0.1f, 0.25f, 1, 1));
                                EmeraldComponent.EmeraldEventsManagerComponent.UpdateUINameText("Tamed " + EmeraldComponent.AIName);
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
    public virtual void ProcessProjectileHit(EmeraldAISystem attacker) // Called when EmeraldAIProjectile collides with the invader
    {
        // TODO: Ver si agregar raycast para prevenir daño a traves de las paredes.

        /*RaycastHit hit;
         * if (Physics.Linecast(attacker.transform.position, transform.position, out hit))
         * {
         *  Debug.LogError("hit.transform.gameObject.layer = " + hit.transform.gameObject.layer);
         *  if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Environment"))
         *  {
         *      Debug.LogError("Soldier can't currently see this character");
         *      return;
         *  }
         * }*/

        // TODO: Añadir chance de esquivar si esta sprinteando

        float dmg = Random.Range(RemoteSettings.Instance.PLAYER_CHARACTER_BULLET_DAMAGE_MIN, RemoteSettings.Instance.PLAYER_CHARACTER_BULLET_DAMAGE_MAX) * RemoteSettings.Instance.GetLinearDamageScalingMultiplier();

        ApplyDamage(dmg, true);

        if (Health <= 0)
        {
            attacker.EmeraldDetectionComponent.SearchForTarget();
        }
    }
コード例 #5
0
        public void SendPlayerDamage(int DamageAmount, Transform Target, EmeraldAISystem EmeraldComponent, bool CriticalHit = false)
        {
            if (!m_Initialised)
            {
                Initialise();
            }

            // Store the AI
            m_AI = EmeraldComponent;

            // Apply damage
            if (m_HealthManager != null)
            {
                m_HealthManager.AddDamage(DamageAmount, CriticalHit, this);
            }

            // Kick the camera position & rotation
            if (m_HeadKicker != null)
            {
                // Get direction of attack
                var direction = transform.position - EmeraldComponent.transform.position;
                direction.y = 0;
                direction.Normalize();

                m_HeadKicker.KickPosition(direction * k_KickDistance, k_KickDuration);
                m_HeadKicker.KickRotation(Quaternion.AngleAxis(k_KickRotation, Vector3.Cross(direction, Vector3.up)), k_KickDuration);
            }
        }
コード例 #6
0
    public static void GenerateMeleeRunAttack(EmeraldAISystem EmeraldComponent)
    {
        EmeraldComponent.CurrentMeleeAttackType = EmeraldAISystem.CurrentMeleeAttackTypes.RunAttack;

        if (EmeraldComponent.MeleeRunAttacks.Count > 0)
        {
            if (EmeraldComponent.MeleeRunAttackPickType == EmeraldAISystem.MeleeRunAttackPickTypeEnum.Odds) //Pick an ability by using the odds for each ability
            {
                List <float> OddsList = new List <float>();
                for (int i = 0; i < EmeraldComponent.MeleeRunAttacks.Count; i++)
                {
                    OddsList.Add(EmeraldComponent.MeleeRunAttacks[i].AttackOdds);
                }
                int OddsIndex = (int)GenerateProbability(OddsList.ToArray());
                EmeraldComponent.MeleeRunAttacksListIndex       = OddsIndex;
                EmeraldComponent.CurrentRunAttackAnimationIndex = EmeraldComponent.MeleeRunAttacks[OddsIndex].AttackAnimaition;
            }
            else if (EmeraldComponent.MeleeRunAttackPickType == EmeraldAISystem.MeleeRunAttackPickTypeEnum.Order) //Pick an ability by going through the list in order
            {
                EmeraldComponent.MeleeRunAttacksListIndex       = EmeraldComponent.MeleeRunAttackIndex;
                EmeraldComponent.CurrentRunAttackAnimationIndex = EmeraldComponent.MeleeRunAttacks[EmeraldComponent.MeleeRunAttackIndex].AttackAnimaition;
                EmeraldComponent.MeleeRunAttackIndex++;
                if (EmeraldComponent.MeleeRunAttackIndex == EmeraldComponent.MeleeRunAttacks.Count)
                {
                    EmeraldComponent.MeleeRunAttackIndex = 0;
                }
            }
            else if (EmeraldComponent.MeleeRunAttackPickType == EmeraldAISystem.MeleeRunAttackPickTypeEnum.Random) //Pick a random ability from the list
            {
                int RandomIndex = Random.Range(0, EmeraldComponent.MeleeRunAttacks.Count);
                EmeraldComponent.MeleeRunAttacksListIndex       = RandomIndex;
                EmeraldComponent.CurrentRunAttackAnimationIndex = EmeraldComponent.MeleeRunAttacks[RandomIndex].AttackAnimaition;
            }
        }
    }
コード例 #7
0
 public static void GenerateOffensiveAbility(EmeraldAISystem EmeraldComponent)
 {
     if (EmeraldComponent.OffensiveAbilities.Count > 0)
     {
         if (EmeraldComponent.OffensiveAbilityPickType == EmeraldAISystem.OffensiveAbilityPickTypeEnum.Odds) //Pick an ability by using the odds for each ability
         {
             List <float> OddsList = new List <float>();
             for (int i = 0; i < EmeraldComponent.OffensiveAbilities.Count; i++)
             {
                 OddsList.Add(EmeraldComponent.OffensiveAbilities[i].AbilityOdds);
             }
             int OddsIndex = (int)GenerateProbability(OddsList.ToArray());
             EmeraldComponent.m_EmeraldAIAbility    = EmeraldComponent.OffensiveAbilities[OddsIndex].OffensiveAbility;
             EmeraldComponent.CurrentAnimationIndex = EmeraldComponent.OffensiveAbilities[OddsIndex].AbilityAnimaition;
         }
         else if (EmeraldComponent.OffensiveAbilityPickType == EmeraldAISystem.OffensiveAbilityPickTypeEnum.Order) //Pick an ability by going through the list in order
         {
             EmeraldComponent.m_EmeraldAIAbility    = EmeraldComponent.OffensiveAbilities[EmeraldComponent.OffensiveAbilityIndex].OffensiveAbility;
             EmeraldComponent.CurrentAnimationIndex = EmeraldComponent.OffensiveAbilities[EmeraldComponent.OffensiveAbilityIndex].AbilityAnimaition;
             EmeraldComponent.OffensiveAbilityIndex++;
             if (EmeraldComponent.OffensiveAbilityIndex == EmeraldComponent.OffensiveAbilities.Count)
             {
                 EmeraldComponent.OffensiveAbilityIndex = 0;
             }
         }
         else if (EmeraldComponent.OffensiveAbilityPickType == EmeraldAISystem.OffensiveAbilityPickTypeEnum.Random) //Pick a random ability from the list
         {
             int RandomIndex = Random.Range(0, EmeraldComponent.OffensiveAbilities.Count);
             EmeraldComponent.m_EmeraldAIAbility    = EmeraldComponent.OffensiveAbilities[RandomIndex].OffensiveAbility;
             EmeraldComponent.CurrentAnimationIndex = EmeraldComponent.OffensiveAbilities[RandomIndex].AbilityAnimaition;
         }
     }
 }
コード例 #8
0
ファイル: MoveToMousePosition.cs プロジェクト: sc8di/dualism
        void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Ray        ray;
                RaycastHit hit;
                ray = CameraComponent.ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(ray, out hit, 45))
                {
                    if (hit.collider.GetComponent <EmeraldAISystem>() != null)
                    {
                        if (hit.collider.GetComponent <EmeraldAISystem>() != null)
                        {
                            EmeraldComponent = hit.collider.GetComponent <EmeraldAISystem>();
                            ArrowObject.SetActive(true);
                        }
                    }

                    if (EmeraldComponent != null)
                    {
                        if (hit.collider.GetComponent <EmeraldAISystem>() == null)
                        {
                            EmeraldComponent.EmeraldEventsManagerComponent.SetDestinationPosition(hit.point);
                        }

                        if (hit.collider.GetComponent <EmeraldAISystem>() == null)
                        {
                            PositionObject.transform.position = hit.point;
                            PositionObject.SetActive(true);
                        }
                    }
                    else
                    {
                        ArrowObject.SetActive(false);
                        PositionObject.SetActive(false);
                    }
                }
            }

            if (EmeraldComponent != null)
            {
                ArrowObject.transform.position = EmeraldComponent.transform.position + new Vector3(0, 3.5f, 0);

                if (EmeraldComponent.CurrentHealth <= 0)
                {
                    EmeraldComponent = null;
                    ArrowObject.SetActive(false);
                    PositionObject.SetActive(false);
                }
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                EmeraldComponent = null;
                ArrowObject.SetActive(false);
                PositionObject.SetActive(false);
            }
        }
コード例 #9
0
        public void AttackTarget()
        {
            if (CurrentTarget != null)
            {
                if (Vector3.Distance(transform.position, CurrentTarget.position) <= StoppingDistanceCombat)
                {
                    Damage = Random.Range(MinDamage, MaxDamage);
                    bool CriticalHit = GenerateCritOdds();
                    if (CriticalHit)
                    {
                        Damage = Mathf.RoundToInt(Damage * CritMultiplier);
                        if (CameraShake.Instance != null)
                        {
                            CameraShake.Instance.ShakeCamera(0.32f, 0.35f);
                        }
                        PlayCriticalHitSound();
                    }
                    else
                    {
                        PlayImpactSound();
                    }

                    CombatTextSystem.Instance.CreateCombatText(Damage, CurrentTarget.position, CriticalHit, false, false);
                    EmeraldAISystem m_EmeraldComponent = CurrentTarget.GetComponent <EmeraldAISystem>();
                    m_EmeraldComponent.Damage(Damage, EmeraldAISystem.TargetType.Player, transform, 300);

                    m_EmeraldComponent.AIRenderer.material.SetFloat("_DamageFlash", 0.75f);
                    StartCoroutine(DamageFlash(m_EmeraldComponent.AIRenderer));

                    UpdateHUD();

                    if (ImpactEffect != null)
                    {
                        EmeraldAI.Utility.EmeraldAIObjectPool.SpawnEffect(ImpactEffect, CurrentTarget.position + new Vector3(0, CurrentTarget.localScale.y * 0.5f, 0), Quaternion.identity, 1);
                    }

                    if (m_EmeraldComponent.IsDead)
                    {
                        StopHUDFade();
                        FadeHUDCoroutine = StartCoroutine(FadeHUD(2, 1));

                        if (TargetIndicatorType == TargetIndicatorEnum.Shader)
                        {
                            m_EmeraldComponent = CurrentTarget.GetComponent <EmeraldAISystem>();
                            m_EmeraldComponent.AIRenderer.material.SetInt("_OutlineEnabled", 0);
                        }
                        CurrentTarget = null;
                        if (TargetIndicatorType == TargetIndicatorEnum.ObjectRing)
                        {
                            TargetIndicator.SetActive(false);
                        }
                        return;
                    }

                    PlayImpactSound();
                }
            }
        }
コード例 #10
0
 public override void Start()
 {
     base.Start();
     GameSceneManager.Instance.GameState.Aliens.Add(this);
     rb      = GetComponent <Rigidbody>();
     anim    = GetComponent <Animator>();
     emerald = GetComponent <EmeraldAISystem>();
     agent   = GetComponent <NavMeshAgent>();
 }
 private void Awake()
 {
     m_ScoreManager = GameObject.FindObjectOfType <ScoreManager>();
     m_EmeraldAI    = GetComponent <EmeraldAISystem>();
     if (m_EmeraldAI.CurrentHealth != (int)health)
     {
         Debug.LogWarning("NeoFPS health manager on " + this.gameObject.name + " has a different health value to the EmeraldAISystem. Using NeoFPS value.");
         m_EmeraldAI.CurrentHealth  = (int)health;
         m_EmeraldAI.StartingHealth = (int)health;
     }
 }
コード例 #12
0
        void DefaultDamage(int DamageAmount, Transform Target)
        {
            Health -= DamageAmount;

            if (Health <= 0)
            {
                Debug.Log("The Non-AI Target has died.");
                gameObject.layer = 0;
                gameObject.tag   = "Untagged";
                EmeraldComponent = Target.GetComponent <EmeraldAISystem>();
                EmeraldComponent.EmeraldDetectionComponent.PreviousTarget = EmeraldComponent.CurrentTarget;
                Invoke("DelaySearchForTarget", 0.75f);
            }
        }
コード例 #13
0
 //Initialize our damage over time spell
 public void Initialize(string AbilityName, int DamageAmount, float DamageIncrement, float AbilityLength, GameObject DamageOverTimeEffect, float DamageOvertimeTimeout, AudioClip DamageOverTimeSound, EmeraldAINonAIDamage NonAIDamageComponent,
                        EmeraldAIPlayerDamage PlayerDamageComponent, EmeraldAISystem TargetEmeraldComponent, EmeraldAISystem AttackerEmeraldComponent, Transform TargetTransform, EmeraldAISystem.TargetType TargetType)
 {
     m_DamageOverTimeEffect     = DamageOverTimeEffect;
     m_DamageOverTimeTimeout    = DamageOvertimeTimeout;
     m_DamageOverTimeSound      = DamageOverTimeSound;
     m_AbilityName              = AbilityName;
     m_DamageAmount             = DamageAmount;
     m_DamageIncrement          = DamageIncrement;
     m_AbilityLength            = AbilityLength;
     m_TargetEmeraldComponent   = TargetEmeraldComponent;
     m_AttackerEmeraldComponent = AttackerEmeraldComponent;
     m_TargetType            = TargetType;
     m_TargetTransform       = TargetTransform;
     m_EmeraldAIPlayerDamage = PlayerDamageComponent;
     m_NonAIDamageComponent  = NonAIDamageComponent;
 }
コード例 #14
0
ファイル: HUDHealthBar.cs プロジェクト: sc8di/dualism
        private void FixedUpdate()
        {
            if (HUDObject.activeSelf)
            {
                DeactiveTimer += Time.deltaTime;

                if (DeactiveTimer >= DeactiveSeconds)
                {
                    EmeraldComponent = null;
                    HUDObject.SetActive(false);
                    DeactiveTimer = 0;
                }
            }

            if (EmeraldComponent != null)
            {
                HUDObject.SetActive(true);
                AINameText.text        = EmeraldComponent.AIName;
                AIHealthBar.fillAmount = (float)EmeraldComponent.CurrentHealth / EmeraldComponent.StartingHealth;

                if (AIHealthBar.fillAmount <= 0)
                {
                    if (HUDObject.activeSelf)
                    {
                        EmeraldComponent = null;
                    }
                }
            }
            //Draw a ray foward from our player at a distance according to the Detect Distance
            if (Physics.Raycast(transform.position, transform.forward, out hit, DetectDistance))
            {
                if (hit.collider.CompareTag(AITag))
                {
                    //Check to see if the object we have hit contains an Emerald AI component
                    if (hit.collider.gameObject.GetComponent <EmeraldAISystem>() != null)
                    {
                        //Get a reference to the Emerald AI object that was hit
                        EmeraldComponent = hit.collider.gameObject.GetComponent <EmeraldAISystem>();
                        HUDObject.SetActive(true);
                        AINameText.text        = EmeraldComponent.AIName;
                        AIHealthBar.fillAmount = (float)EmeraldComponent.CurrentHealth / EmeraldComponent.StartingHealth;
                        DeactiveTimer          = 0;
                    }
                }
            }
        }
コード例 #15
0
        void Update()
        {
            //Draw a ray foward from our player at a distance according to the DetectDistance
            if (Physics.Raycast(transform.position, transform.forward, out hit, DetectDistance))
            {
                if (hit.collider.CompareTag(AITag))
                {
                    //Color our crosshair red to indicate a valid target
                    if (CrosshairImage != null)
                    {
                        CrosshairImage.color = Color.green;
                    }

                    if (Input.GetKeyDown(KeyCode.F))
                    {
                        //Check to see if the object we have hit contains an Emerald AI component
                        if (hit.collider.gameObject.GetComponent <EmeraldAISystem>() != null)
                        {
                            //Get a reference to the Emerald AI object that was hit
                            EmeraldAISystem EmeraldComponent = hit.collider.gameObject.GetComponent <EmeraldAISystem>();

                            //Play the AI's Emote animation with the ID of EmoteID
                            EmeraldComponent.EmeraldEventsManagerComponent.PlayEmoteAnimation(EmoteID);
                        }
                    }
                }
                else
                {
                    //Color our crosshair white because there is no target
                    if (CrosshairImage != null)
                    {
                        CrosshairImage.color = Color.white;
                    }
                }
            }
            else
            {
                //Color our crosshair white because there is no target
                if (CrosshairImage != null)
                {
                    CrosshairImage.color = Color.white;
                }
            }
        }
コード例 #16
0
        public void SendPlayerDamage(int DamageAmount, Transform Target, EmeraldAISystem EmeraldComponent, bool CriticalHit = false)
        {
            //The standard damage function that sends damage to the Emerald AI demo player
            DamagePlayerStandard(DamageAmount);

            //Creates damage text on the player's position, if enabled.
            CombatTextSystem.Instance.CreateCombatText(DamageAmount, transform.position, CriticalHit, false, true);

            //Sends damage to another function that will then send the damage to the RFPS player.
            //If you are using RFPS, you can uncomment this to allow Emerald Agents to damage your RFPS player.
            //DamageRFPS(DamageAmount, Target);

            //Sends damage to another function that will then send the damage to the RFPS player.
            //If you are using RFPS, you can uncomment this to allow Emerald Agents to damage your RFPS player.
            //DamageInvectorPlayer(DamageAmount, Target);

            //Damage UFPS Player
            //DamageUFPSPlayer(DamageAmount);
        }
コード例 #17
0
ファイル: EmeraldAINeedsSystem.cs プロジェクト: sc8di/dualism
        void Start()
        {
            m_EmeraldAISystem = GetComponent <EmeraldAISystem>();
            m_EmeraldAISystem.WanderRadius  = WanderRadius;
            m_EmeraldAISystem.WanderTypeRef = EmeraldAISystem.WanderType.Stationary;
            m_EmeraldAISystem.WaypointsList.Clear();

            if (CurrentResourcesLevel <= ResourcesLowThreshold)
            {
                Invoke("UpdateWaypoints", 0.1f);
                m_EmeraldAISystem.EmeraldEventsManagerComponent.OverrideIdleAnimation(IdleAnimationIndex);
            }
            else
            {
                m_EmeraldAISystem.EmeraldEventsManagerComponent.UpdateStartingPosition();
                m_EmeraldAISystem.WanderTypeRef = EmeraldAISystem.WanderType.Dynamic;
            }

            InvokeRepeating("UpdateNeeds", 0.1f, UpdateResourcesFrequency);
        }
コード例 #18
0
ファイル: RaycastHitAI.cs プロジェクト: sc8di/dualism
        void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Ray        ray;
                RaycastHit hit;
                ray = CameraComponent.ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(ray, out hit, 50))
                {
                    if (hit.collider.GetComponent <EmeraldAISystem>() != null)
                    {
                        //Get a reference to the EmeraldAISystem script that is hit by the raycast.
                        EmeraldAISystem EmeraldComponent = hit.collider.GetComponent <EmeraldAISystem>();

                        //Cause damage to the AI that is hit using the Emerald AI damage function.
                        //This is can be a helpfull example for users who have VR games or games where the player is the camera.
                        //In this case, the PlayerObject is a child of the camera.
                        EmeraldComponent.Damage(DamageAmount, EmeraldAISystem.TargetType.Player, PlayerObject.transform, 400);
                    }
                }
            }
        }
コード例 #19
0
 void Start()
 {
     EmeraldComponent = transform.parent.GetComponent <EmeraldAISystem>();
     m_Camera         = Camera.main;
     GlobalScale      = EmeraldComponent.transform.localScale;
 }
コード例 #20
0
        void Update()
        {
            m_AnimatorController.SetFloat("Speed", m_NavMeshAgent.velocity.magnitude / m_NavMeshAgent.speed - (0.4f), 0.05f, Time.deltaTime);

            if (CurrentTarget != null)
            {
                m_UpdateTargetPosition += Time.deltaTime;
                if (m_UpdateTargetPosition >= 1)
                {
                    m_NavMeshAgent.SetDestination(CurrentTarget.position);
                    m_UpdateTargetPosition = 0;
                }

                if (m_NavMeshAgent.remainingDistance <= m_NavMeshAgent.stoppingDistance && !m_NavMeshAgent.pathPending)
                {
                    m_NavMeshAgent.updateRotation = false;
                    float   step = RotationSpeedCombat * Time.deltaTime;
                    Vector3 m_TargetDirection = CurrentTarget.position - transform.position;
                    m_TargetDirection.y = 0;
                    Vector3 m_NewDirection = Vector3.RotateTowards(transform.forward, m_TargetDirection, step, 0.0f);
                    transform.rotation = Quaternion.LookRotation(m_NewDirection);

                    m_AttackTimer += Time.deltaTime;
                    if (m_AttackTimer >= AttackSpeed)
                    {
                        PlayAttackSound();
                        m_AnimatorController.SetTrigger("Attack");
                        m_AttackTimer = 0;
                    }
                }
                else
                {
                    m_NavMeshAgent.updateRotation = true;
                }
            }

            if (Input.GetMouseButtonDown(1) && m_AnimatorController.GetCurrentAnimatorClipInfo(0)[0].clip.name != "Attack")
            {
                m_AttackTimer = AttackSpeed;
            }

            if (Input.GetMouseButton(0))
            {
                m_UpdatePositionTimer     += Time.deltaTime;
                m_MouseUpClickEffectTimer += Time.deltaTime;

                if (m_UpdatePositionTimer >= UpdatePositionThreshold)
                {
                    if (m_AnimatorController.GetCurrentAnimatorClipInfo(0)[0].clip.name != "Attack")
                    {
                        Ray        m_Ray = PlayerCamera.ScreenPointToRay(Input.mousePosition);
                        RaycastHit m_hit;
                        if (Physics.Raycast(m_Ray, out m_hit, 1000.0f, MovementMask))
                        {
                            if (CurrentTarget == null)
                            {
                                if (!m_hit.collider.CompareTag(TargetTag))
                                {
                                    if (!m_ClickEffectUsed && DestinationEffect != null)
                                    {
                                        EmeraldAI.Utility.EmeraldAIObjectPool.SpawnEffect(DestinationEffect, m_hit.point + Vector3.up * 0.5f, Quaternion.identity, 2);
                                        m_ClickEffectUsed = true;
                                    }

                                    m_NavMeshAgent.updateRotation   = true;
                                    m_NavMeshAgent.stoppingDistance = StoppingDistanceMovement;
                                    m_LastMousePosition             = m_hit.point;

                                    if (Vector3.Distance(transform.position, m_hit.point) > StoppingDistanceMovement + 1)
                                    {
                                        m_NavMeshAgent.SetDestination(m_hit.point);
                                    }
                                }
                                else
                                {
                                    m_AnimatorController.ResetTrigger("Hit");
                                    m_NavMeshAgent.updateRotation   = false;
                                    m_NavMeshAgent.stoppingDistance = StoppingDistanceCombat;
                                    CurrentTarget = m_hit.transform;
                                    if (TargetIndicatorType == TargetIndicatorEnum.Shader)
                                    {
                                        EmeraldAISystem m_EmeraldComponent = CurrentTarget.GetComponent <EmeraldAISystem>();
                                        m_EmeraldComponent.AIRenderer.material.SetColor("_OutlineColor", TargetIndicatorColor);
                                        m_EmeraldComponent.AIRenderer.material.SetInt("_OutlineEnabled", 1);
                                        m_EmeraldComponent.AIRenderer.material.SetFloat("_OutlineWidth", 0.1f);
                                    }
                                    m_NavMeshAgent.SetDestination(m_hit.point);
                                    m_AttackTimer          = AttackSpeed;
                                    m_UpdateTargetPosition = 1f;
                                    if (TargetIndicatorType == TargetIndicatorEnum.ObjectRing)
                                    {
                                        TargetIndicator.transform.SetParent(CurrentTarget);
                                        TargetIndicator.transform.localPosition = new Vector3(0, 0.25f, 0);
                                        TargetIndicator.SetActive(true);
                                    }
                                    EmeraldComponent = CurrentTarget.GetComponent <EmeraldAISystem>();
                                    UpdateHUD();
                                    StopHUDFade();
                                }
                            }
                            else if (m_hit.collider.CompareTag(TargetTag) && m_hit.transform != CurrentTarget)
                            {
                                m_AnimatorController.ResetTrigger("Hit");
                                m_NavMeshAgent.updateRotation   = false;
                                m_NavMeshAgent.stoppingDistance = StoppingDistanceCombat;
                                if (TargetIndicatorType == TargetIndicatorEnum.Shader)
                                {
                                    EmeraldAISystem m_EmeraldComponent = CurrentTarget.GetComponent <EmeraldAISystem>();
                                    m_EmeraldComponent.AIRenderer.material.SetInt("_OutlineEnabled", 0);
                                }
                                CurrentTarget = m_hit.transform;
                                if (TargetIndicatorType == TargetIndicatorEnum.Shader)
                                {
                                    EmeraldAISystem m_EmeraldComponent = CurrentTarget.GetComponent <EmeraldAISystem>();
                                    m_EmeraldComponent.AIRenderer.material.SetColor("_OutlineColor", TargetIndicatorColor);
                                    m_EmeraldComponent.AIRenderer.material.SetInt("_OutlineEnabled", 1);
                                    m_EmeraldComponent.AIRenderer.material.SetFloat("_OutlineWidth", 0.1f);
                                }
                                m_NavMeshAgent.SetDestination(m_hit.point);
                                m_AttackTimer          = AttackSpeed;
                                m_UpdateTargetPosition = 1f;
                                if (TargetIndicatorType == TargetIndicatorEnum.ObjectRing)
                                {
                                    TargetIndicator.transform.SetParent(CurrentTarget);
                                    TargetIndicator.transform.localPosition = new Vector3(0, 0.25f, 0);
                                    TargetIndicator.SetActive(true);
                                }
                                EmeraldComponent = CurrentTarget.GetComponent <EmeraldAISystem>();
                                UpdateHUD();
                                StopHUDFade();
                            }
                            else if (!m_hit.collider.CompareTag(TargetTag) && CurrentTarget != null && Vector3.Distance(CurrentTarget.position, m_hit.point) > 3.5f)
                            {
                                if (!m_ClickEffectUsed && DestinationEffect != null)
                                {
                                    EmeraldAI.Utility.EmeraldAIObjectPool.SpawnEffect(DestinationEffect, m_hit.point + Vector3.up * 0.5f, Quaternion.identity, 2);
                                    m_ClickEffectUsed = true;
                                }

                                if (m_CanvasGroup.alpha == 1)
                                {
                                    FadeHUDCoroutine = StartCoroutine(FadeHUD(2, 1));
                                }

                                m_AnimatorController.ResetTrigger("Hit");
                                EmeraldAISystem m_EmeraldComponent = CurrentTarget.GetComponent <EmeraldAISystem>();
                                if (TargetIndicatorType == TargetIndicatorEnum.Shader)
                                {
                                    m_EmeraldComponent.AIRenderer.material.SetInt("_OutlineEnabled", 0);
                                }
                                CurrentTarget = null;
                                m_NavMeshAgent.updateRotation   = true;
                                m_NavMeshAgent.stoppingDistance = StoppingDistanceMovement;
                                m_LastMousePosition             = m_hit.point;
                                m_NavMeshAgent.SetDestination(m_hit.point);
                            }
                        }

                        m_UpdatePositionTimer = 0;
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (TargetIndicatorType == TargetIndicatorEnum.Shader && CurrentTarget != null)
                {
                    EmeraldAISystem m_EmeraldComponent = CurrentTarget.GetComponent <EmeraldAISystem>();
                    m_EmeraldComponent.AIRenderer.material.SetInt("_OutlineEnabled", 0);
                    StopHUDFade();
                    FadeHUDCoroutine = StartCoroutine(FadeHUD(2, 1));
                    m_NavMeshAgent.SetDestination(transform.position);
                    CurrentTarget = null;
                }
            }

            if (Input.GetMouseButtonUp(0))
            {
                if (DestinationEffect != null && m_MouseUpClickEffectTimer > 1)
                {
                    EmeraldAI.Utility.EmeraldAIObjectPool.SpawnEffect(DestinationEffect, m_LastMousePosition + Vector3.up * 0.5f, Quaternion.identity, 1);
                }

                m_NavMeshAgent.updateRotation = true;
                m_ClickEffectUsed             = false;
                m_MouseUpClickEffectTimer     = 0;

                if (CurrentTarget == null && TargetIndicatorType == TargetIndicatorEnum.ObjectRing)
                {
                    TargetIndicator.SetActive(false);
                }
            }

            HealthRecoveryTimer += Time.deltaTime;

            if (HealthRecoveryTimer >= 1 && PlayerHealthComponent.CurrentHealth < PlayerHealthComponent.StartingHealth)
            {
                PlayerHealthComponent.CurrentHealth += HealthRecoveryRate;
                UpdatePlayerHealthOrbUI.Instance.UpdateHealthUI();
                HealthRecoveryTimer = 0;
            }
        }
コード例 #21
0
        void AssignEmeraldAIComponents()
        {
            if (ObjectToSetup != null && ObjectToSetup.GetComponent <EmeraldAISystem>() == null && ObjectToSetup.GetComponent <Animator>() != null)
            {
                secs = 1.5f;

                ObjectToSetup.AddComponent <EmeraldAISystem>();
                ObjectToSetup.GetComponent <AudioSource>().spatialBlend = 1;
                ObjectToSetup.GetComponent <AudioSource>().dopplerLevel = 0;
                ObjectToSetup.GetComponent <AudioSource>().rolloffMode  = AudioRolloffMode.Linear;
                ObjectToSetup.GetComponent <AudioSource>().minDistance  = 1;
                ObjectToSetup.GetComponent <AudioSource>().maxDistance  = 50;

                EmeraldAISystem Emerald = ObjectToSetup.GetComponent <EmeraldAISystem>();

                Emerald.BehaviorRef   = (EmeraldAISystem.CurrentBehavior)AIBehaviorRef;
                Emerald.ConfidenceRef = (EmeraldAISystem.ConfidenceType)ConfidenceRef;
                Emerald.WanderTypeRef = (EmeraldAISystem.WanderType)WanderTypeRef;
                Emerald.WeaponTypeRef = (EmeraldAISystem.WeaponType)WeaponTypeRef;
                Emerald.DeathTypeRef  = (EmeraldAISystem.DeathType)DeathTypeRef;
                Emerald.AnimatorType  = (EmeraldAISystem.AnimatorTypeState)AnimatorType;

                if (SetupOptimizationSettingsRef == SetupOptimizationSettings.Yes)
                {
                    Emerald.DisableAIWhenNotInViewRef = EmeraldAISystem.YesOrNo.Yes;
                    if (ObjectToSetup.GetComponent <LODGroup>() != null)
                    {
                        LODGroup _LODGroup = ObjectToSetup.GetComponentInChildren <LODGroup>();

                        if (_LODGroup != null)
                        {
                            LOD[] AllLODs = _LODGroup.GetLODs();

                            if (_LODGroup.lodCount <= 4)
                            {
                                Emerald.TotalLODsRef       = (EmeraldAISystem.TotalLODsEnum)(_LODGroup.lodCount - 2);
                                Emerald.HasMultipleLODsRef = EmeraldAISystem.YesOrNo.Yes;
                            }

                            if (_LODGroup.lodCount > 1)
                            {
                                for (int i = 0; i < _LODGroup.lodCount; i++)
                                {
                                    if (i == 0)
                                    {
                                        Emerald.Renderer1 = AllLODs[0].renderers[0];
                                    }
                                    if (i == 1)
                                    {
                                        Emerald.Renderer2 = AllLODs[1].renderers[0];
                                    }
                                    if (i == 2)
                                    {
                                        Emerald.Renderer3 = AllLODs[2].renderers[0];
                                    }
                                    if (i == 3)
                                    {
                                        Emerald.Renderer4 = AllLODs[3].renderers[0];
                                    }
                                }
                            }
                            else if (_LODGroup.lodCount == 1)
                            {
                                Emerald.HasMultipleLODsRef = EmeraldAISystem.YesOrNo.No;
                            }
                        }
                        else if (_LODGroup == null)
                        {
                            Emerald.HasMultipleLODsRef = EmeraldAISystem.YesOrNo.No;
                        }
                    }

                    List <SkinnedMeshRenderer> TempSkinnedMeshes = new List <SkinnedMeshRenderer>();
                    List <float> TempSkinnedMeshBounds           = new List <float>();

                    foreach (SkinnedMeshRenderer SMR in Emerald.GetComponentsInChildren <SkinnedMeshRenderer>())
                    {
                        if (!TempSkinnedMeshes.Contains(SMR))
                        {
                            TempSkinnedMeshes.Add(SMR);
                            TempSkinnedMeshBounds.Add(SMR.bounds.size.sqrMagnitude);
                        }
                    }

                    float m_LargestBounds = TempSkinnedMeshBounds.Max();
                    Emerald.AIRenderer = TempSkinnedMeshes[TempSkinnedMeshBounds.IndexOf(m_LargestBounds)];
                }

                Emerald.gameObject.tag     = AITag;
                Emerald.gameObject.layer   = AILayer;
                Emerald.DetectionLayerMask = (1 << LayerMask.NameToLayer("Water"));

                Emerald.IdleAnimationList.Add(null);
                Emerald.AttackAnimationList.Add(null);
                Emerald.RunAttackAnimationList.Add(null);
                Emerald.HitAnimationList.Add(null);
                Emerald.CombatHitAnimationList.Add(null);
                Emerald.DeathAnimationList.Add(null);

                //4.2

                /*
                 * if (Emerald.PlayerFaction.Count == 0)
                 * {
                 *  Emerald.PlayerFaction.Add(new EmeraldAISystem.PlayerFactionClass(Emerald.PlayerTag, 0));
                 * }
                 */

                Component[] AllComponents = ObjectToSetup.GetComponents <Component>();

                for (int i = 0; i < AllComponents.Length; i++)
                {
                    UnityEditorInternal.ComponentUtility.MoveComponentUp(Emerald);
                }

                ObjectToSetup.GetComponent <BoxCollider>().size   = new Vector3(Emerald.AIRenderer.bounds.size.x / 3 / ObjectToSetup.transform.localScale.y, Emerald.AIRenderer.bounds.size.y / ObjectToSetup.transform.localScale.y, Emerald.AIRenderer.bounds.size.z / 3 / ObjectToSetup.transform.localScale.y);
                ObjectToSetup.GetComponent <BoxCollider>().center = new Vector3(ObjectToSetup.GetComponent <BoxCollider>().center.x, ObjectToSetup.GetComponent <BoxCollider>().size.y / 2, ObjectToSetup.GetComponent <BoxCollider>().center.z);

                if (!DontShowDisplayConfirmation)
                {
                    DisplayConfirmation = true;
                }

                ObjectToSetup = null;
            }
            else if (ObjectToSetup == null)
            {
                EditorUtility.DisplayDialog("Emerald AI Setup Manager - Oops!", "There is no object assigned to the AI Object slot. Please assign one and try again.", "Okay");
            }
            else if (ObjectToSetup.GetComponent <EmeraldAISystem>() != null)
            {
                EditorUtility.DisplayDialog("Emerald AI Setup Manager - Oops!", "There is already an Emerald AI component on this object. Please choose another object to apply an Emerald AI component to.", "Okay");
            }
            else if (ObjectToSetup.GetComponent <Animator>() == null)
            {
                EditorUtility.DisplayDialog("Emerald AI Setup Manager - Oops!", "There is no Animator component attached to your AI. Please assign one and try again.", "Okay");
            }
        }
コード例 #22
0
ファイル: AISchedule.cs プロジェクト: sc8di/dualism
 void Start()
 {
     m_EmeraldAISystem        = GetComponent <EmeraldAISystem>();
     m_EmeraldAIEventsManager = GetComponent <EmeraldAIEventsManager>();
     InvokeRepeating("UpdateAISchedule", 0.1f, 1);
 }
コード例 #23
0
 void Awake()
 {
     m_EmeraldAISystem = GetComponentInParent <EmeraldAISystem>();
 }