private void SetupCharacterIK()
        {
            CharacterIK characterIK = m_Character.GetComponent <CharacterIK>();

            if (characterIK == null)
            {
                characterIK = m_Character.AddComponent <CharacterIK>();
            }

            if (!m_CharacterIK)
            {
                DestroyImmediate(characterIK);
            }
        }
示例#2
0
        private void Awake()
        {
            //Physics.queriesHitTriggers = false;
            if (this.m_DontDestroyOnLoad)
            {
                DontDestroyOnLoad(gameObject);
            }
            this.m_ControllerEvents = GetComponentsInChildren <IControllerEventHandler>(true);
            this.m_Rigidbody        = GetComponent <Rigidbody>();
            this.m_Transform        = transform;
            this.m_Animator         = GetComponent <Animator>();
            Animator childAnimator = gameObject.GetComponentsInChildren <Animator>().Where(x => x != this.m_Animator).FirstOrDefault();

            if (childAnimator != null)
            {
                this.m_Animator.runtimeAnimatorController = childAnimator.runtimeAnimatorController;
                this.m_Animator.avatar = childAnimator.avatar;
                Destroy(childAnimator);
            }

            this.m_CapsuleCollider = GetComponent <CapsuleCollider>();
            this.m_CameraTransform = Camera.main.transform;
            this.m_CharacterIK     = GetComponent <CharacterIK>();
            this.m_ToggleState     = new Dictionary <MotionState, bool>();

            for (int i = 0; i < this.m_Motions.Count; i++)
            {
                this.m_Motions[i].Index = i;
                this.m_ToggleState.Add(this.m_Motions[i], false);
            }
            this.m_LayerStateMap  = new AnimatorStateInfo[this.m_Animator.layerCount];
            this.m_MotionStateMap = new Dictionary <int, MotionState[]>();
            for (int j = 0; j < this.m_Animator.layerCount; j++)
            {
                AnimatorStateInfo  stateInfo = this.m_Animator.GetCurrentAnimatorStateInfo(j);
                List <MotionState> states    = new List <MotionState>();
                for (int k = 0; k < this.m_Motions.Count; k++)
                {
                    if (m_Animator.HasState(j, Animator.StringToHash(this.m_Motions[k].State)))
                    {
                        this.m_Motions[k].Layer = j;
                        states.Add(this.m_Motions[k]);
                    }
                }
                this.m_MotionStateMap.Add(j, states.ToArray());
                this.m_LayerStateMap[j] = stateInfo;
            }
        }