/// <summary>
        /// initialize class
        /// </summary>
        /// <returns>true if succeded initialization</returns>
        public bool initialize()
        {
            if (m_initialized)
            {
                return(true);
            }
            m_Character = GetComponent <TPCharacter>();
            if (!m_Character)
            {
                Debug.LogError("cannot find component 'TPCharacter'" + " < " + this.ToString() + ">"); return(false);
            }
            m_Character.initialize();
            m_Animator = m_Character.animator;
            if (!m_Animator)
            {
                Debug.LogError("cannot find 'Animator' component" + " < " + this.ToString() + ">"); return(false);
            }

            m_LFoot = m_Animator.GetBoneTransform(HumanBodyBones.LeftFoot);
            if (!m_LFoot)
            {
                Debug.LogError("Cannot find left foot transform."); return(false);
            }
            m_RFoot = m_Animator.GetBoneTransform(HumanBodyBones.RightFoot);
            if (!m_RFoot)
            {
                Debug.LogError("Cannot find right foot transform."); return(false);
            }


            m_initialized = true;
            return(true);
        }
        private bool m_Initialized     = false;      // is compoentn initialized ?


        /// <summary>
        /// initialize component
        /// </summary>
        public void initialize()
        {
            if (m_Initialized)
            {
                return;
            }
            m_Character = GetComponent <TPCharacter>();
            if (!m_Character)
            {
                Debug.LogError("Cannot find component 'TPCharacter'! " + " < " + this.ToString() + ">"); return;
            }
            m_Character.initialize();
            m_defines = GameObject.FindObjectOfType <Predefines>();
            if (!m_defines)
            {
                Debug.LogError("Cannot find component 'Predefines'." + " < " + this.ToString() + ">"); return;
            }
            m_Initialized = true;
        }
示例#3
0
        /// <summary>
        /// initilaize component
        /// </summary>
        public void initialize()
        {
            if (m_initialized)
            {
                return;
            }

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

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

            IKHelper ls = GetComponent <IKHelper>();

            if (ls)
            {
                if (ls.enabled)
                {
                    m_IKHelper = ls;
                }
            }

            if (!m_TriggerUI)
            {
                Debug.LogError("Trigger UI not assigned! " + " < " + this.ToString() + ">");
                return;
            }
            m_TriggerUI.text = "";

            m_initialized = true;
        }
        /// <summary>
        /// initialize component
        /// </summary>
        public virtual void initialize()
        {
            if (m_Initialized)
            {
                return;
            }

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

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

            m_Initialized = true;
        }
        // initialize compoonent
        public void initialize()
        {
            if (m_Initialized)
            {
                return;
            }

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

            if (!m_Character.animator.avatar.isHuman)
            {
                Debug.LogError("Not humanoid mecanim avatar!" + " < " + this.ToString() + ">");
                return;
            }
            if (!m_Character.animator.avatar.isValid)
            {
                Debug.LogError("Invalid mecanim avatar!" + " < " + this.ToString() + ">");
                return;
            }
            m_Animator = GetComponent <Animator>(); // m_Character.animator;
            if (!m_Animator)
            {
                Debug.LogError("Cannot find 'Animator' component");
            }


            Transform larm = m_Animator.GetBoneTransform(HumanBodyBones.LeftUpperArm);

            if (!larm)
            {
                Debug.LogError("ANIMATOR ERROR ( IKHELPER )"); return;
            }
            Transform lelbow = m_Animator.GetBoneTransform(HumanBodyBones.LeftLowerArm);
            Transform lhand  = m_Animator.GetBoneTransform(HumanBodyBones.LeftHand);
            Transform lleg   = m_Animator.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
            Transform lknee  = m_Animator.GetBoneTransform(HumanBodyBones.LeftLowerLeg);
            Transform lfoot  = m_Animator.GetBoneTransform(HumanBodyBones.LeftFoot);

            float armelb  = Vector3.Distance(larm.position, lelbow.position);
            float elbhand = Vector3.Distance(lelbow.position, lhand.position);

            m_ArmReach = armelb + elbhand;

            float hipknee  = Vector3.Distance(lleg.position, lknee.position);
            float kneefoot = Vector3.Distance(lknee.position, lfoot.position);

            m_LegReach = hipknee + kneefoot;

            Transform rarmup = m_Character.animator.GetBoneTransform(HumanBodyBones.RightUpperArm);
            Transform relb   = m_Character.animator.GetBoneTransform(HumanBodyBones.RightLowerArm);
            Transform rhand  = m_Character.animator.GetBoneTransform(HumanBodyBones.RightHand);

            float diff1 = Vector3.Distance(rarmup.position, relb.position);
            float diff2 = Vector3.Distance(relb.position, rhand.position);

            m_ArmReach = diff1 + diff2;

            m_Initialized = true;
        }
        /// <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;
        }