Ejemplo n.º 1
0
        void _createHealthUI()
        {
            HealthUI hui = character.GetComponent <HealthUI>();

            if (!hui)
            {
                hui = Undo.AddComponent <HealthUI>(character);
            }
        }
        /// <summary>
        /// initialize component
        /// </summary>
        public void initialize()
        {
            if (m_Initialized)
            {
                return;
            }

            m_Animator = GetComponent <Animator>();
            if (!m_Animator)
            {
                Debug.LogError("Cannot find component 'Animator'" + " < " + this.ToString() + ">"); return;
            }

            m_Audio = GetComponent <AudioManager>();
            if (!m_Audio)
            {
                Debug.LogError("Cannot find component 'AudioManager'" + " < " + this.ToString() + ">"); return;
            }

            m_Character = GetComponent <TPCharacter>();
            if (!m_Character)
            {
                Debug.LogError("Cannot find component 'TPCharacter'" + " < " + this.ToString() + ">"); return;
            }
            m_Character.initialize();
            m_Character.setIKMode(TPCharacter.IKMode.None);

            AudioManager amg = m_Character.audioManager as AudioManager;

            if (!amg)
            {
                Debug.LogError("Cannot find component 'AudioManager'" + " < " + this.ToString() + ">"); return;
            }
            m_Audio = amg;

            m_DefaultWeaponSounds = GetComponent <WeaponAudio>();
            if (!m_DefaultWeaponSounds)
            {
                Debug.LogError("Cannot find 'WeaponAudio' component <" + this.ToString() + " >"); return;
            }

            m_Stats = GetComponent <Stats>();
            if (!m_Stats)
            {
                Debug.LogError("Cannot find 'Stats' component: " + " < " + this.ToString() + ">"); return;
            }

            m_HealthUI = GetComponent <HealthUI>();

            m_Ragdoll = GetComponent <RagdollManager>();
            if (!m_Ragdoll)
            {
                Debug.LogError("Cannot find component 'RagdollManager'" + " < " + this.ToString() + ">"); return;
            }
            m_Ragdoll.initialize();
            m_Ragdoll.OnHit = () =>
            {
                m_Character.simulateRootMotion = false;
                m_Character.disableMove        = true;
                m_Character.rigidBody.velocity = Vector3.zero;

                m_Character.rigidBody.detectCollisions = false;
                m_Character.rigidBody.isKinematic      = true;
                m_Character.capsule.enabled            = false;
            };
            // allow movement when transitioning to animated
            m_Ragdoll.OnStartTransition = () =>
            {
                /*
                 *  Enable simulating root motion on transition  if
                 *  character is not in full ragdoll to
                 *  make character not freeze on place when hit.
                 *  Otherwise root motion will interfere with getting up animation.
                 */
                if (!m_Ragdoll.isFullRagdoll && !m_Ragdoll.isGettingUp)
                {
                    m_Character.simulateRootMotion         = true;
                    m_Character.rigidBody.detectCollisions = true;
                    m_Character.rigidBody.isKinematic      = false;
                    m_Character.capsule.enabled            = true;
                }
            };

            // event that will be last fired ( when full ragdoll - on get up, when hit reaction - on blend end
            m_Ragdoll.LastEvent = () =>
            {
                m_Character.simulateRootMotion = true;
                m_Character.disableMove        = false;

                m_Character.rigidBody.detectCollisions = true;
                m_Character.rigidBody.isKinematic      = false;
                m_Character.capsule.enabled            = true;
            };

            m_Ragdoll.ragdollEventTime = 4.0f;
            //m_Ragdoll.OnTimeEnd = () =>
            //{
            //    if (m_Stats.health > 0)
            //    {
            //        m_Ragdoll.blendToMecanim();
            //    }
            //    //m_Ragdoll.OnTimeEnd = null;
            //};

            GameObject playerGO = GameObject.FindGameObjectWithTag("Player");

            if (!playerGO)
            {
                Debug.LogError("Cannot find object with tag 'Player' " + " < " + this.ToString() + ">");
                return;
            }
            m_Player = playerGO.GetComponent <Player>();
            if (!m_Player)
            {
                Debug.LogError("Cannot find 'Player' script on  " + playerGO.name + " < " + this.ToString() + ">"); return;
            }

            m_path = new UnityEngine.AI.NavMeshPath();

            m_NpcState = NPCState.Idle;

            m_NPCManager = GameObject.FindObjectOfType <NPCManager>();

            m_StartPosition = transform.position;
            m_StartLookAt   = transform.forward;

#if SMOOTH_MOVEMENT
            for (int i = 0; i < avgMove.Length; i++)
            {
                avgMove[i] = Vector3.zero;
            }
#endif

            if (!attackSweepBody)
            {
                Debug.LogError("Cannot find attack sweep body used for finding obstructions." + " < " + this.ToString() + ">");
                return;
            }

            m_DamageUI = GetComponent <DebugUI>();

            m_Initialized = true;
        }