Ejemplo n.º 1
0
        /// <summary>
        /// Cache the default values.
        /// </summary>
        private void Awake()
        {
            m_GameObject = gameObject;
            m_Animator   = GetComponent <Animator>();

            m_CharacterLocomotion = gameObject.GetCachedParentComponent <UltimateCharacterLocomotion>();
#if FIRST_PERSON_CONTROLLER
            var firstPersonObjects = GetComponentInParent <FirstPersonController.Character.FirstPersonObjects>();
            m_FirstPersonAnimatorMonitor = firstPersonObjects != null;
            // If the locomotion component doesn't exist then the item is already placed under the camera.
            if (m_CharacterLocomotion == null)
            {
                m_CharacterLocomotion = firstPersonObjects.Character.GetCachedComponent <UltimateCharacterLocomotion>();
            }
#endif
            m_Character = m_CharacterLocomotion.gameObject;
            m_CharacterAnimatorMonitor = m_Character.GetCachedComponent <AnimatorMonitor>();

            if (m_CharacterAnimatorMonitor.HasItemParameters)
            {
                var slotCount = m_CharacterAnimatorMonitor.ParameterSlotCount;

                m_ItemSlotID            = new int[slotCount];
                m_ItemSlotStateIndex    = new int[slotCount];
                m_ItemSlotSubstateIndex = new int[slotCount];

                if (s_ItemSlotSubstateIndexHash == null)
                {
                    s_ItemSlotIDHash               = new int[slotCount];
                    s_ItemSlotStateIndexHash       = new int[slotCount];
                    s_ItemSlotStateIndexChangeHash = new int[slotCount];
                    s_ItemSlotSubstateIndexHash    = new int[slotCount];
                    for (int i = 0; i < slotCount; ++i)
                    {
                        s_ItemSlotIDHash[i]               = Animator.StringToHash(string.Format("Slot{0}ItemID", i));
                        s_ItemSlotStateIndexHash[i]       = Animator.StringToHash(string.Format("Slot{0}ItemStateIndex", i));
                        s_ItemSlotStateIndexChangeHash[i] = Animator.StringToHash(string.Format("Slot{0}ItemStateIndexChange", i));
                        s_ItemSlotSubstateIndexHash[i]    = Animator.StringToHash(string.Format("Slot{0}ItemSubstateIndex", i));
                    }
                }
            }
#if ULTIMATE_CHARACTER_CONTROLLER_VR && FIRST_PERSON_CONTROLLER
            var handHandler = m_CharacterAnimatorMonitor.GetComponent <IVRHandHandler>();
            m_HasVRParameters = handHandler != null && m_GameObject.GetComponent <FirstPersonController.Character.Identifiers.FirstPersonBaseObject>() != null;
            if (m_HasVRParameters)
            {
                s_HandStateIndexHash   = Animator.StringToHash("HandStateIndex");
                s_HandGripStrengthHash = Animator.StringToHash("HandGripStrength");
            }
#endif

            m_Animator.updateMode      = AnimatorUpdateMode.AnimatePhysics;
            m_Animator.applyRootMotion = false;
            enabled = m_CharacterAnimatorMonitor != null;
            if (enabled)
            {
                EventHandler.RegisterEvent <bool>(m_Character, "OnCharacterImmediateTransformChange", OnImmediateTransformChange);
                EventHandler.RegisterEvent(m_Character, "OnCharacterSnapAnimator", SnapAnimator);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Cache the default values.
        /// </summary>
        private void Awake()
        {
            m_GameObject = gameObject;
            m_Animator   = GetComponent <Animator>();

            m_CharacterLocomotion = gameObject.GetCachedParentComponent <UltimateCharacterLocomotion>();
#if FIRST_PERSON_CONTROLLER
            var firstPersonObjects = GetComponentInParent <FirstPersonController.Character.FirstPersonObjects>();
            m_FirstPersonAnimatorMonitor = firstPersonObjects != null;
            // If the locomotion component doesn't exist then the item is already placed under the camera.
            if (m_CharacterLocomotion == null)
            {
                m_CharacterLocomotion = firstPersonObjects.Character.GetCachedComponent <UltimateCharacterLocomotion>();
            }
#endif
            m_Character = m_CharacterLocomotion.gameObject;
            m_CharacterAnimatorMonitor = m_Character.GetCachedComponent <AnimatorMonitor>();

            if (m_CharacterAnimatorMonitor.HasItemParameters)
            {
                var slotCount = m_CharacterAnimatorMonitor.ParameterSlotCount;
                m_ItemParameterExists = new HashSet <int>();

                m_ItemSlotID            = new int[slotCount];
                m_ItemSlotStateIndex    = new int[slotCount];
                m_ItemSlotSubstateIndex = new int[slotCount];

                if (s_ItemSlotIDHash == null || s_ItemSlotIDHash.Length < slotCount)
                {
                    s_ItemSlotIDHash               = new int[slotCount];
                    s_ItemSlotStateIndexHash       = new int[slotCount];
                    s_ItemSlotStateIndexChangeHash = new int[slotCount];
                    s_ItemSlotSubstateIndexHash    = new int[slotCount];
                }

                for (int i = 0; i < slotCount; ++i)
                {
                    // Animators do not need to contain every slot index.
                    var slotIDHash      = Animator.StringToHash(string.Format("Slot{0}ItemID", i));
                    var parameterExists = false;
                    for (int j = 0; j < m_Animator.parameterCount; ++j)
                    {
                        if (m_Animator.GetParameter(j).nameHash == slotIDHash)
                        {
                            parameterExists = true;
                            break;
                        }
                    }

                    if (!parameterExists)
                    {
                        continue;
                    }
                    m_ItemParameterExists.Add(i);

                    // The hash variables are static and may already be populated.
                    if (s_ItemSlotIDHash[i] == 0)
                    {
                        s_ItemSlotIDHash[i]               = slotIDHash;
                        s_ItemSlotStateIndexHash[i]       = Animator.StringToHash(string.Format("Slot{0}ItemStateIndex", i));
                        s_ItemSlotStateIndexChangeHash[i] = Animator.StringToHash(string.Format("Slot{0}ItemStateIndexChange", i));
                        s_ItemSlotSubstateIndexHash[i]    = Animator.StringToHash(string.Format("Slot{0}ItemSubstateIndex", i));
                    }
                }
            }
#if ULTIMATE_CHARACTER_CONTROLLER_VR
#if FIRST_PERSON_CONTROLLER
            var handHandler = m_CharacterAnimatorMonitor.GetComponent <IVRHandHandler>();
            m_HasVRParameters = handHandler != null && m_GameObject.GetComponent <FirstPersonController.Character.Identifiers.FirstPersonBaseObject>() != null;
            if (m_HasVRParameters)
            {
                s_HandStateIndexHash   = Animator.StringToHash("HandStateIndex");
                s_HandGripStrengthHash = Animator.StringToHash("HandGripStrength");
            }
#else
            m_HasVRParameters = false;
#endif
#endif

            m_Animator.applyRootMotion = false;
            OnChangeUpdateLocation(m_CharacterLocomotion.UpdateLocation == Game.KinematicObjectManager.UpdateLocation.FixedUpdate);
            OnChangeTimeScale(m_CharacterLocomotion.TimeScale);
            enabled = m_CharacterAnimatorMonitor != null;
            if (enabled)
            {
                EventHandler.RegisterEvent <bool>(m_Character, "OnCharacterImmediateTransformChange", OnImmediateTransformChange);
                EventHandler.RegisterEvent(m_Character, "OnCharacterSnapAnimator", SnapAnimator);
                EventHandler.RegisterEvent <bool>(m_Character, "OnCharacterChangeUpdateLocation", OnChangeUpdateLocation);
                EventHandler.RegisterEvent <float>(m_Character, "OnCharacterChangeTimeScale", OnChangeTimeScale);
            }
        }