Пример #1
0
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            // The item may have been added at runtime in which case the look source has already been populated.
            var characterLocomotion = m_Character.GetCachedComponent <UltimateCharacterLocomotion>();

            m_LookSource = characterLocomotion.LookSource;

            m_UseAnimatorAudioStateSet.DeserializeAnimatorAudioStateSelector(m_Item, characterLocomotion);
            m_UseAnimatorAudioStateSet.Awake(m_Item.gameObject);

            m_AttributeManager = GetComponent <AttributeManager>();
            if (m_AttributeManager != null)
            {
                m_UseAttribute = m_AttributeManager.GetAttribute(m_UseAttributeName);

                if (m_UseAttribute != null)
                {
                    EventHandler.RegisterEvent(m_UseAttribute, "OnAttributeReachedDestinationValue", UseDepleted);
                }
            }
            m_CharacterUseAttributeManager = m_Character.GetCachedComponent <AttributeManager>();
            if (m_CharacterUseAttributeManager != null)
            {
                m_CharacterUseAttribute = m_CharacterUseAttributeManager.GetAttribute(m_CharacterUseAttributeName);
            }

            m_NextAllowedUseTime = Time.time;
            EventHandler.RegisterEvent <ILookSource>(m_Character, "OnCharacterAttachLookSource", OnAttachLookSource);
        }
Пример #2
0
        /// <summary>
        /// A new ILookSource object has been attached to the character.
        /// </summary>
        /// <param name="lookSource">The ILookSource object attached to the character.</param>
        private void OnAttachLookSource(ILookSource lookSource)
        {
            var firstPersonPerspective = false;

            if (lookSource != null && m_NetworkInfo.IsLocalPlayer())
            {
                var cameraController = lookSource as Camera.CameraController;
                if (cameraController != null)
                {
                    firstPersonPerspective = cameraController.ActiveViewType.FirstPersonPerspective;
                }
            }

            // The character is a first person character. Set the third person objects to the invisible shadow castor material.
            if (firstPersonPerspective)
            {
                var thirdPersonObjects = gameObject.GetComponentsInChildren <ThirdPersonObject>(true);
                for (int i = 0; i < thirdPersonObjects.Length; ++i)
                {
                    var renderers = thirdPersonObjects[i].GetComponentsInChildren <Renderer>(true);
                    for (int j = 0; j < renderers.Length; ++j)
                    {
                        var materials = renderers[j].materials;
                        for (int k = 0; k < materials.Length; ++k)
                        {
                            materials[k] = m_InvisibleMaterial;
                        }
                        renderers[j].materials = materials;
                    }
                }
            }

            Destroy(this);
        }
Пример #3
0
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        public override void Awake()
        {
            base.Awake();

            m_PlayerInput = m_GameObject.GetCachedComponent <PlayerInput>();
            var count = m_SlotID == -1 ? m_Inventory.SlotCount : 1;

            m_UsableItems             = new IUsableItem[count];
            m_WaitForUseEvent         = new bool[count];
            m_CanStopAbility          = new bool[count];
            m_WaitForUseCompleteEvent = new bool[count];
            m_UseCompleted            = new bool[count];
            m_UseEvent     = new ScheduledEventBase[count];
            m_CanStopEvent = new ScheduledEventBase[count];
            for (int i = 0; i < count; ++i)
            {
                m_WaitForUseEvent[i] = false;
                m_UseCompleted[i]    = true;
            }
            // The look source may have already been assigned if the ability was added to the character after the look source was assigned.
            m_LookSource = m_CharacterLocomotion.LookSource;
            // AIAgents will have the LocalLookSource.
            m_AIAgent = m_LookSource is LocalLookSource;

            EventHandler.RegisterEvent <ILookSource>(m_GameObject, "OnCharacterAttachLookSource", OnAttachLookSource);
            EventHandler.RegisterEvent <bool>(m_GameObject, "OnEnableGameplayInput", OnEnableGameplayInput);
            EventHandler.RegisterEvent(m_GameObject, "OnAnimatorItemUse", OnItemUse);
            EventHandler.RegisterEvent(m_GameObject, "OnAnimatorItemUseComplete", OnItemUseComplete);
#if ULTIMATE_CHARACTER_CONTROLLER_SHOOTER
            EventHandler.RegisterEvent <ItemAbility, bool>(m_GameObject, "OnCharacterItemAbilityActive", OnItemAbilityActive);
#endif
            // Register for the interested slot events.
            RegisterSlotEvents(m_SlotID);
        }
Пример #4
0
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        public override void Awake()
        {
            base.Awake();

            // The look source may have already been assigned if the ability was added to the character after the look source was assigned.
            m_LookSource = m_CharacterLocomotion.LookSource;
            EventHandler.RegisterEvent <ILookSource>(m_GameObject, "OnCharacterAttachLookSource", OnAttachLookSource);
        }
        /// <summary>
        /// Initializes the MovementType.
        /// </summary>
        /// <param name="characterLocomotion">The reference to the character locomotion component.</param>
        public virtual void Initialize(UltimateCharacterLocomotion characterLocomotion)
        {
            m_CharacterLocomotion = characterLocomotion;
            m_GameObject          = characterLocomotion.gameObject;
            m_Transform           = characterLocomotion.transform;
            m_LookSource          = m_CharacterLocomotion.LookSource;

            // The StateObject class needs to initialize itself.
            Initialize(m_GameObject);
        }
 /// <summary>
 /// A new ILookSource object has been attached to the character.
 /// </summary>
 /// <param name="lookSource">The ILookSource object attached to the character.</param>
 private void OnAttachLookSource(ILookSource lookSource)
 {
     if (lookSource == null)
     {
         m_AimAssist = null;
     }
     else
     {
         m_AimAssist = lookSource.GameObject.GetCachedComponent <AimAssist>();
     }
 }
Пример #7
0
 /// <summary>
 /// A new ILookSource object has been attached to the character.
 /// </summary>
 /// <param name="lookSource">The ILookSource object attached to the character.</param>
 private void OnAttachLookSource(ILookSource lookSource)
 {
     if (lookSource != null)
     {
         m_AttachedCamera = lookSource.GameObject.GetCachedComponent <CameraController>();
     }
     else
     {
         m_AttachedCamera = null;
     }
 }
Пример #8
0
 /// <summary>
 /// A new ILookSource object has been attached to the character.
 /// </summary>
 /// <param name="lookSource">The ILookSource object attached to the character.</param>
 private void OnAttachLookSource(ILookSource lookSource)
 {
     m_LookSource = lookSource;
     if (m_LookSource != null)
     {
         m_LookSourceTransform = m_LookSource.GameObject.transform;
     }
     else
     {
         m_LookSourceTransform = null;
     }
 }
Пример #9
0
        /// <summary>
        /// A new ILookSource object has been attached to the character.
        /// </summary>
        /// <param name="lookSource">The ILookSource object attached to the character.</param>
        protected override void OnAttachLookSource(ILookSource lookSource)
        {
            base.OnAttachLookSource(lookSource);

            if (lookSource != null)
            {
                m_Camera = lookSource.GameObject.GetCachedComponent <Camera>();
            }
            else
            {
                m_Camera = null;
            }
        }
Пример #10
0
        /// <summary>
        /// A new ILookSource object has been attached to the character.
        /// </summary>
        /// <param name="lookSource">The ILookSource object attached to the character.</param>
        protected override void OnAttachLookSource(ILookSource lookSource)
        {
            base.OnAttachLookSource(lookSource);

            if (lookSource != null)
            {
                m_Camera             = lookSource.GameObject.GetCachedComponent <UnityEngine.Camera>();
                m_InitialOrientation = false;
            }
            else
            {
                m_Camera = null;
            }
        }
        /// <summary>
        /// A new ILookSource object has been attached to the character.
        /// </summary>
        /// <param name="lookSource">The ILookSource object attached to the character.</param>
        private void OnAttachLookSource(ILookSource lookSource)
        {
            if (m_LookSource == null)
            {
                EventHandler.RegisterEvent <bool>(m_GameObject, "OnCharacterChangePerspectives", OnChangePerspectives);
            }

            m_LookSource = lookSource;

            if (m_LookSource == null)
            {
                EventHandler.UnregisterEvent <bool>(m_GameObject, "OnCharacterChangePerspectives", OnChangePerspectives);
            }

            PrepareVerticalOffsetLists();
        }
Пример #12
0
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        public override void Awake()
        {
            m_LastCastFrame = -m_CastFrameInterval;
            // The look source may have already been assigned if the ability was added to the character after the look source was assigned.
            m_LookSource = m_CharacterLocomotion.LookSource;
            if (m_LookSource != null)
            {
                m_LookSourceTransform = m_LookSource.GameObject.transform;
            }

            if ((m_ObjectDetection & ObjectDetectionMode.Trigger) != 0)
            {
                m_DetectedTriggerObjects = new GameObject[m_MaxTriggerObjectCount];
            }
            EventHandler.RegisterEvent <ILookSource>(m_GameObject, "OnCharacterAttachLookSource", OnAttachLookSource);
        }
Пример #13
0
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        public override void Awake()
        {
            base.Awake();

#if THIRD_PERSON_CONTROLLER
            m_ItemPullback = m_CharacterLocomotion.GetAbility <ThirdPersonController.Character.Abilities.Items.ItemPullback>();
#endif
            // The look source may have already been assigned if the ability was added to the character after the look source was assigned.
            m_LookSource = m_CharacterLocomotion.LookSource;

            EventHandler.RegisterEvent <ILookSource>(m_GameObject, "OnCharacterAttachLookSource", OnAttachLookSource);
            EventHandler.RegisterEvent <bool>(m_GameObject, "OnCameraWillChangePerspectives", OnChangePerspectives);
#if ULTIMATE_CHARACTER_CONTROLLER_SHOOTER || UNITY_EDITOR
            EventHandler.RegisterEvent <ItemAbility, bool>(m_GameObject, "OnCharacterItemAbilityActive", OnItemAbilityActive);
#endif
            EventHandler.RegisterEvent(m_GameObject, "OnRespawn", OnRespawn);
        }
Пример #14
0
 /// <summary>
 /// A new ILookSource object has been attached to the character.
 /// </summary>
 /// <param name="lookSource">The ILookSource object attached to the character.</param>
 private void OnAttachLookSource(ILookSource lookSource)
 {
     m_LookSource = lookSource;
 }
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            var perspectiveItems = GetComponents <PerspectiveItem>();

            for (int i = 0; i < perspectiveItems.Length; ++i)
            {
                if (perspectiveItems[i].FirstPersonItem)
                {
                    // A Visible Item may not exist.
                    var visibleItem = (perspectiveItems[i] as FirstPersonPerspectiveItem).VisibleItem;
                    m_VisibleTransform = visibleItem != null ? visibleItem.transform : m_Object.transform;
                }
            }

            // The look source is used to determine if the item is facing in the forward direction.
            m_LookSource = m_CharacterLocomotion.LookSource;

            // The item may be added at runtime while the attachment transform is located on the character.
            if (m_FirePointAttachmentLocationID != -1 || (m_ReloadableClipAttachment == null && m_ReloadableClip != null) || m_ReloadProjectileAttachmentID != -1)
            {
                var firstPersonObject = GetComponent <FirstPersonPerspectiveItem>().Object;
                if (firstPersonObject != null)
                {
                    var objectIdentifiers = firstPersonObject.GetComponentsInChildren <Objects.ObjectIdentifier>();
                    if (objectIdentifiers.Length > 0)
                    {
                        for (int i = 0; i < objectIdentifiers.Length; ++i)
                        {
                            if (objectIdentifiers[i].ID == m_FirePointAttachmentLocationID)
                            {
                                m_FirePointAttachmentLocation = objectIdentifiers[i].transform;
                            }
                            else if (objectIdentifiers[i].ID == m_ReloadableClipAttachmentID)
                            {
                                m_ReloadableClipAttachment = objectIdentifiers[i].transform;
                            }
                            else if (objectIdentifiers[i].ID == m_ReloadProjectileAttachmentID)
                            {
                                m_ReloadProjectileAttachment = objectIdentifiers[i].transform;
                            }

                            // If the references are found then the loop can end early.
                            if ((m_ReloadableClip == null || m_ReloadableClipAttachmentID == -1 || m_ReloadableClipAttachment != null) &&
                                (m_FirePointAttachmentLocationID == -1 || m_FirePointAttachmentLocation != null) &&
                                (m_ReloadProjectileAttachmentID == -1 || m_ReloadProjectileAttachment != null))
                            {
                                break;
                            }
                        }
                        // If no IDs match then log a warning.
                        if (m_FirePointAttachmentLocation == null && m_FirePointAttachmentLocationID != -1)
                        {
                            Debug.LogWarning("Warning: Unable to find the third person fire point attachment ObjectIdentifier with the ID " + m_FirePointAttachmentLocationID + " for item " + name + ".");
                        }
                        if (m_ReloadableClipAttachment == null && m_ReloadableClip != null && m_ReloadableClipAttachmentID != -1)
                        {
                            Debug.LogWarning("Warning: Unable to find the third person reload attachment ObjectIdentifier with the ID " + m_ReloadableClipAttachmentID + " for item " + name + ".");
                        }
                        if (m_ReloadProjectileAttachment == null && m_ReloadProjectileAttachmentID != -1)
                        {
                            Debug.LogWarning("Warning: Unable to find the third person reload projectile ObjectIdentifier with the ID " + m_ReloadProjectileAttachmentID + " for item " + name + ".");
                        }
                    }
                }
            }
            if (m_FirePointAttachmentLocation != null)
            {
                // If the fire point is null then the found attachment transform becomes the firepoint. If it is not null then the parent is set.
                if (m_FirePointLocation == null)
                {
                    m_FirePointLocation = m_FirePointAttachmentLocation;
                }
                else
                {
                    m_FirePointLocation.SetParentOrigin(m_FirePointAttachmentLocation);
                }
            }

            EventHandler.RegisterEvent <ILookSource>(m_Character, "OnCharacterAttachLookSource", OnAttachLookSource);
        }
 /// <summary>
 /// A new ILookSource object has been attached to the character.
 /// </summary>
 /// <param name="lookSource">The ILookSource object attached to the character.</param>
 protected virtual void OnAttachLookSource(ILookSource lookSource)
 {
     m_LookSource = lookSource;
 }
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            m_ObjectTransform = m_Object.transform;
            // The look source is used to determine if the item is facing in the forward direction.
            m_LookSource = m_CharacterLocomotion.LookSource;

            // The item may be added at runtime while the attachment transform is located on the character.
            if (m_FirePointAttachmentLocationID != -1 || (m_ReloadableClipAttachment == null && m_ReloadableClip != null) || m_ReloadProjectileAttachmentID != -1)
            {
                var character         = GetComponentInParent <UltimateCharacterLocomotion>();
                var objectIdentifiers = character.GetComponentsInChildren <Objects.ObjectIdentifier>();
                if (objectIdentifiers.Length > 0)
                {
                    for (int i = 0; i < objectIdentifiers.Length; ++i)
                    {
#if FIRST_PERSON_CONTROLLER
                        // The first person attachments should be filtered out.
                        if (objectIdentifiers[i].GetComponentInParent <FirstPersonController.Character.FirstPersonObjects>() != null)
                        {
                            continue;
                        }
#endif
                        if (objectIdentifiers[i].ID == m_FirePointAttachmentLocationID)
                        {
                            m_FirePointAttachmentLocation = objectIdentifiers[i].transform;
                        }
                        else if (objectIdentifiers[i].ID == m_ReloadableClipAttachmentID)
                        {
                            m_ReloadableClipAttachment = objectIdentifiers[i].transform;
                        }
                        else if (objectIdentifiers[i].ID == m_ReloadProjectileAttachmentID)
                        {
                            m_ReloadProjectileAttachment = objectIdentifiers[i].transform;
                        }

                        // If the references are found then the loop can end early.
                        if ((m_ReloadableClip == null || m_ReloadableClipAttachmentID == -1 || m_ReloadableClipAttachment != null) &&
                            (m_FirePointAttachmentLocationID == -1 || m_FirePointAttachmentLocation != null) &&
                            (m_ReloadProjectileAttachmentID == -1 || m_ReloadProjectileAttachment != null))
                        {
                            break;
                        }
                    }
                    // If no IDs match then log a warning.
                    if (m_FirePointAttachmentLocation == null && m_FirePointAttachmentLocationID != -1)
                    {
                        Debug.LogWarning("Warning: Unable to find the third person fire point attachment ObjectIdentifier with the ID " + m_FirePointAttachmentLocationID + " for item " + name + ".");
                    }
                    if (m_ReloadableClipAttachment == null && m_ReloadableClip != null && m_ReloadableClipAttachmentID != -1)
                    {
                        Debug.LogWarning("Warning: Unable to find the third person reload attachment ObjectIdentifier with the ID " + m_ReloadableClipAttachmentID + " for item " + name + ".");
                    }
                    if (m_ReloadProjectileAttachment == null && m_ReloadProjectileAttachmentID != -1)
                    {
                        Debug.LogWarning("Warning: Unable to find the third person reload projectile ObjectIdentifier with the ID " + m_ReloadProjectileAttachmentID + " for item " + name + ".");
                    }
                }
            }
            if (m_FirePointAttachmentLocation != null)
            {
                // If the fire point is null then the found attachment transform becomes the firepoint. If it is not null then the parent is set.
                if (m_FirePointLocation == null)
                {
                    m_FirePointLocation = m_FirePointAttachmentLocation;
                }
                else
                {
                    m_FirePointLocation.SetParentOrigin(m_FirePointAttachmentLocation);
                }
            }

            EventHandler.RegisterEvent <ILookSource>(m_Character, "OnCharacterAttachLookSource", OnAttachLookSource);
        }