예제 #1
0
 /// <summary>
 /// Finds an UltimateCharacterLocomotion and its Inventory and ItemCollection by GameObject name.
 /// If the name is blank, finds the GameObject tagged 'Player'.
 /// </summary>
 public static bool FindCharacterWithInventory(string characterName, out UltimateCharacterLocomotion character, out InventoryBase inventory, out ItemCollection itemCollection)
 {
     inventory      = null;
     itemCollection = null;
     character      = FindCharacter(characterName);
     if (character != null)
     {
         inventory      = character.GetComponent <InventoryBase>();
         itemCollection = UCCUtility.FindItemCollection(character.gameObject);
         if (inventory == null)
         {
             if (DialogueDebug.logWarnings)
             {
                 Debug.LogWarning("Dialogue System: Character '" + character.name + "' doesn't have an Inventory.", character);
             }
         }
         else if (itemCollection == null)
         {
             if (DialogueDebug.logWarnings)
             {
                 Debug.LogWarning("Dialogue System: Character '" + character.name + "' doesn't have access to an Item Set Manager or Item Collection.", character);
             }
         }
     }
     return(character != null && inventory != null && itemCollection != null);
 }
예제 #2
0
        /// <summary>
        /// Attaches the handler to the specified character.
        /// </summary>
        /// <param name="character">The character to attach the handler to.</param>
        private void OnAttachCharacter(GameObject character)
        {
            enabled = character != null;

            if (m_Character != null)
            {
                EventHandler.UnregisterEvent <Vector3, Vector3, GameObject>(m_Character, "OnDeath", OnDeath);
                EventHandler.UnregisterEvent(m_Character, "OnRespawn", OnRespawn);
                EventHandler.UnregisterEvent <bool>(m_Character, "OnEnableGameplayInput", OnEnableGameplayInput);
                EventHandler.UnregisterEvent <bool>(m_Character, "OnCharacterActivate", OnActivate);
            }

            m_Character = character;

            if (character != null)
            {
                EventHandler.RegisterEvent <Vector3, Vector3, GameObject>(character, "OnDeath", OnDeath);
                EventHandler.RegisterEvent(character, "OnRespawn", OnRespawn);
                EventHandler.RegisterEvent <bool>(character, "OnEnableGameplayInput", OnEnableGameplayInput);
                EventHandler.RegisterEvent <bool>(character, "OnCharacterActivate", OnActivate);
                m_AllowGameplayInput  = true;
                m_PlayerInput         = character.GetCachedComponent <PlayerInput>();
                m_CharacterLocomotion = character.GetCachedComponent <UltimateCharacterLocomotion>();
                m_LastRotateTime      = Time.realtimeSinceStartup;
                enabled = character.activeInHierarchy;
            }
        }
예제 #3
0
        /// <summary>
        /// Retrieves the use ability.
        /// </summary>
        public override void OnStart()
        {
            var target = GetDefaultGameObject(m_TargetGameObject.Value);

            if (target != m_PrevTarget)
            {
                m_CharacterLocomotion = target.GetCachedComponent <UltimateCharacterLocomotion>();
                // Find the specified ability.
                var abilities = m_CharacterLocomotion.GetAbilities <Opsive.UltimateCharacterController.Character.Abilities.Items.Reload>();
                // The slot ID and action ID must match.
                for (int i = 0; i < abilities.Length; ++i)
                {
                    if (abilities[i].SlotID == m_SlotID.Value && abilities[i].ActionID == m_ActionID.Value)
                    {
                        m_ReloadAbility = abilities[i];
                        break;
                    }
                }
                if (m_ReloadAbility == null)
                {
                    Debug.LogWarning("Error: Unable to find a Reload ability with slot " + m_SlotID.Value + " and action " + m_ActionID.Value);
                    return;
                }
                m_PrevTarget = target;
            }
        }
예제 #4
0
        /// <summary>
        /// Removes the specified ability from the ability array.
        /// </summary>
        /// <param name="characterLocomotion">The character to remove the ability from.</param>
        /// <param name="ability">The ability to remove.</param>
        public static void RemoveAbility(UltimateCharacterLocomotion characterLocomotion, Ability ability)
        {
            if (ability == null)
            {
                return;
            }

            if (typeof(ItemAbility).IsAssignableFrom(ability.GetType()))
            {
                RemoveItemAbility(characterLocomotion, ability);
                return;
            }

            var abilities = new Ability[characterLocomotion.Abilities.Length - 1];
            var index     = 0;

            for (int i = 0; i < characterLocomotion.Abilities.Length; ++i)
            {
                if (characterLocomotion.Abilities[i] != ability)
                {
                    abilities[index] = characterLocomotion.Abilities[i];
                    index++;
                }
            }

            characterLocomotion.Abilities = abilities;
            SerializeAbilities(characterLocomotion);
        }
예제 #5
0
        /// <summary>
        /// Initializes the default values.
        /// </summary>
        private void Awake()
        {
            m_Character           = FindObjectOfType <DemoManager>().Character;
            m_CharacterLocomotion = m_Character.GetComponent <UltimateCharacterLocomotion>();
            m_CharacterHealth     = m_Character.GetComponent <CharacterHealth>();

            EventHandler.RegisterEvent <bool>(m_Character, "OnCharacterChangePerspectives", OnChangePerspectives);

            // The character may start out with the First Person Combat / Third Person Adventure Movement Type.
            if (m_CharacterLocomotion.FirstPersonMovementTypeFullName.Contains("FreeLook"))
            {
                m_ActiveFirstPersonIndex = 1;
            }
            if (m_CharacterLocomotion.ThirdPersonMovementTypeFullName.Contains("Combat"))
            {
                m_ActiveThirdPersonIndex = 1;
            }
            else if (m_CharacterLocomotion.ThirdPersonMovementTypeFullName.Contains("RPG"))
            {
                m_ActiveThirdPersonIndex = 2;
            }

            if (m_CharacterLocomotion.FirstPersonPerspective)
            {
                StateManager.SetState(m_Character, m_FirstPersonMovementStates[m_ActiveFirstPersonIndex], true);
            }
            else
            {
                StateManager.SetState(m_Character, m_ThirdPersonMovementStates[m_ActiveThirdPersonIndex], true);
            }
        }
예제 #6
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.
            m_CharacterLocomotion = m_Character.GetCachedComponent <UltimateCharacterLocomotion>();
            m_LookSource          = m_CharacterLocomotion.LookSource;

            m_UseAnimatorAudioStateSet.DeserializeAnimatorAudioStateSelector(m_Item, m_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);
        }
예제 #7
0
        public override void OnStart()
        {
            var target = GetDefaultGameObject(m_TargetGameObject.Value);

            if (target != m_PrevTarget)
            {
                m_CharacterLocomotion = target.GetCachedComponent <UltimateCharacterLocomotion>();
                // Find the specified ability.
                var abilities = m_CharacterLocomotion.GetAbilities <ItemSetAbilityBase>();
                // The category ID must match.
                for (int i = 0; i < abilities.Length; ++i)
                {
                    if (abilities[i].ItemSetCategoryID == m_CategoryID.Value)
                    {
                        m_ItemSetAbility = abilities[i];
                        break;
                    }
                }
                if (m_ItemSetAbility == null)
                {
                    Debug.LogWarning("Error: Unable to find an ItemSet ability with category ID " + m_CategoryID.Value + ".");
                    return;
                }
                m_PrevTarget = target;
            }
        }
 /// <summary>
 /// Initializes the destructible properties.
 /// </summary>
 /// <param name="damageAmount">The amount of damage to apply to the hit object.</param>
 /// <param name="impactForce">The amount of force to apply to the hit object.</param>
 /// <param name="impactForceFrames">The number of frames to add the force to.</param>
 /// <param name="impactLayers">The layers that the projectile can impact with.</param>
 /// <param name="impactStateName">The name of the state to activate upon impact.</param>
 /// <param name="impactStateDisableTimer">The number of seconds until the impact state is disabled.</param>
 /// <param name="surfaceImpact">A reference to the Surface Impact triggered when the object hits an object.</param>
 public void InitializeDestructibleProperties(float damageAmount, float impactForce, int impactForceFrames, LayerMask impactLayers, string impactStateName, float impactStateDisableTimer, SurfaceImpact surfaceImpact)
 {
     m_Destroyed               = false;
     m_DamageAmount            = damageAmount;
     m_ImpactForce             = impactForce;
     m_ImpactForceFrames       = impactForceFrames;
     m_ImpactLayers            = impactLayers;
     m_ImpactStateName         = impactStateName;
     m_ImpactStateDisableTimer = impactStateDisableTimer;
     // The SurfaceImpact may be set directly on the destructible prefab.
     if (m_SurfaceImpact == null)
     {
         m_SurfaceImpact = surfaceImpact;
     }
     if (m_TrailRenderer != null)
     {
         m_TrailRenderer.Clear();
         m_TrailRenderer.enabled = true;
     }
     if (m_ParticleSystem != null)
     {
         m_ParticleSystem.Play();
     }
     if (m_Collider != null)
     {
         m_Collider.enabled = false;
     }
     // The object may be reused and was previously stuck to a character.
     if (m_StickyCharacterLocomotion != null)
     {
         m_StickyCharacterLocomotion.RemoveSubCollider(m_Collider);
         m_StickyCharacterLocomotion = null;
     }
 }
예제 #9
0
        /// <summary>
        /// The other collider has entered the trigger.
        /// </summary>
        /// <param name="other">The collider which entered the trigger.</param>
        private void OnTriggerEnter(Collider other)
        {
            if (!MathUtility.InLayerMask(other.gameObject.layer, m_LayerMask))
            {
                return;
            }

            var characterLocomotion = other.gameObject.GetCachedParentComponent <UltimateCharacterLocomotion>();

            if (characterLocomotion == null || characterLocomotion.TimeScale != 1)
            {
                return;
            }

            m_CharacterLocomotion = characterLocomotion;
            m_Active = true;
            m_Time   = 0;
            UpdateTimeScale(true);

            // Hide the children until the time has been reset.
            for (int i = 0; i < m_Children.Length; ++i)
            {
                m_Children[i].SetActive(false);
            }

            // Optionally play an audio clip.
            if (m_AudioClip != null)
            {
                m_AudioSource.clip = m_AudioClip;
                m_AudioSource.Play();
            }
        }
예제 #10
0
        /// <summary>
        /// Initializes the CastAction.
        /// </summary>
        /// <param name="character">The character GameObject.</param>
        /// <param name="magicItem">The MagicItem that the CastAction belongs to.</param>
        /// <param name="index">The index of the CastAction.</param>
        public override void Initialize(GameObject character, MagicItem magicItem, int index)
        {
            base.Initialize(character, magicItem, index);

            m_CharacterTransform  = character.transform;
            m_CharacterLocomotion = character.GetCachedComponent <UltimateCharacterLocomotion>();
        }
        /// <summary>
        /// The character has entered from the zone.
        /// </summary>
        /// <param name="characterLocomotion">The character that entered the zone.</param>
        protected override void CharacterEnter(UltimateCharacterLocomotion characterLocomotion)
        {
            // The other collider is the main character.
            m_Character = characterLocomotion.gameObject;
            m_CameraController = UnityEngineUtility.FindCamera(m_Character).GetComponent<CameraController>();

            // The character must have the primary item in order for it to be equipped.
            var inventory = m_Character.GetCachedComponent<InventoryBase>();
            for (int i = 0; i < m_ItemTypes.Length; ++i) {
                if (m_ItemTypes[i] == null) {
                    continue;
                }
                inventory.PickupItemType(m_ItemTypes[i], 1, 0, false, false);
            }

            // Ensure the primary weapon is equipped.
            var equipUnequipAbilities = characterLocomotion.GetAbilities<EquipUnequip>();
            for (int i = 0; i < equipUnequipAbilities.Length; ++i) {
                if (equipUnequipAbilities[i].ItemSetCategoryIndex == m_CategoryIndex) {
                    equipUnequipAbilities[i].StartEquipUnequip(m_ItemSetIndex, true);
                    break;
                }
            }

            // Setup the character for the zone.
            StateManager.SetState(m_Character, "FirstPersonSpringZone", true);
            EventHandler.ExecuteEvent(m_Character, "OnShowUI", false);

            // First person perspective is required...
            m_CameraController.SetPerspective(true);
            // With the combat movement type.
            m_MovementTypeSwitcher.UpdateMovementType(true, (int)MovementTypesZone.MovementType.FirstPersonCombat);
        }
예제 #12
0
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            m_TrajectoryObject    = GetComponent <TrajectoryObject>();
            m_CharacterLocomotion = m_Character.GetCachedComponent <UltimateCharacterLocomotion>();
            m_CharacterTransform  = m_CharacterLocomotion.transform;
#if ULTIMATE_CHARACTER_CONTROLLER_VR
            m_VRThrowableItem = GetComponent <IVRThrowableItem>();
#endif

            if (m_ThrownObject != null && m_TrajectoryObject != null)
            {
                // The object has to be instantiated for GetComponent to work.
                var instantiatedThrownObject = ObjectPool.Instantiate(m_ThrownObject);
                var trajectoryCollider       = instantiatedThrownObject.GetComponent <Collider>();
                if (trajectoryCollider != null)
                {
                    // Only sphere and capsules are supported.
                    if (trajectoryCollider is SphereCollider)
                    {
                        var trajectorySphereCollider = trajectoryCollider as SphereCollider;
                        var sphereCollider           = m_GameObject.AddComponent <SphereCollider>();
                        sphereCollider.center  = trajectorySphereCollider.center;
                        sphereCollider.radius  = trajectorySphereCollider.radius;
                        sphereCollider.enabled = false;
                    }
                    else if (trajectoryCollider is CapsuleCollider)
                    {
                        var trajectoryCapsuleCollider = trajectoryCollider as CapsuleCollider;
                        var capsuleCollider           = m_GameObject.AddComponent <CapsuleCollider>();
                        capsuleCollider.center    = trajectoryCapsuleCollider.center;
                        capsuleCollider.radius    = trajectoryCapsuleCollider.radius;
                        capsuleCollider.height    = trajectoryCapsuleCollider.height;
                        capsuleCollider.direction = trajectoryCapsuleCollider.direction;
                        capsuleCollider.enabled   = false;
                    }
                    else
                    {
                        Debug.LogError($"Error: The collider of type {trajectoryCollider.GetType()} is not supported on the trajectory object " + m_ThrownObject.name);
                    }
                    m_GameObject.layer = LayerManager.SubCharacter;
                }
                ObjectPool.Destroy(instantiatedThrownObject);
            }
            m_ThrowableItemPerpectiveProperties = m_ActivePerspectiveProperties as IThrowableItemPerspectiveProperties;

            if (m_ShowTrajectoryOnAim && m_TrajectoryObject == null)
            {
                Debug.LogError($"Error: A TrajectoryObject must be added to the {m_GameObject.name} GameObject in order for the trajectory to be shown.");
            }

            if (m_ThrownObject == null)
            {
                Debug.LogError($"Error: A ThrownObject must be assigned to the {m_GameObject.name} GameObject.");
            }

            EventHandler.RegisterEvent <bool, bool>(m_Character, "OnAimAbilityStart", OnAim);
            EventHandler.RegisterEvent(m_Character, "OnAnimatorReequipThrowableItem", ReequipThrowableItem);
        }
예제 #13
0
        /// <summary>
        /// Attaches the monitor to the specified character.
        /// </summary>
        /// <param name="character">The character to attach the monitor to.</param>
        protected override void OnAttachCharacter(GameObject character)
        {
            if (m_Character != null)
            {
                EventHandler.UnregisterEvent <float, Vector3, Vector3, GameObject, Collider>(m_Character, "OnHealthDamage", OnDamage);
                EventHandler.UnregisterEvent(m_Character, "OnRespawn", OnRespawn);
                m_Camera = null;
            }

            base.OnAttachCharacter(character);

            if (m_Character == null)
            {
                return;
            }

            // A camera must exist.
            m_Camera = Shared.Camera.CameraUtility.FindCamera(m_Character);
            if (m_Camera == null)
            {
                Debug.LogError("Error: The Damage Indicator Monitor must have a camera attached to the character.");
                return;
            }

            m_CharacterTransform  = m_Character.transform;
            m_CharacterLocomotion = m_Character.GetCachedComponent <UltimateCharacterLocomotion>();
            gameObject.SetActive(CanShowUI());

            EventHandler.RegisterEvent <float, Vector3, Vector3, GameObject, Collider>(m_Character, "OnHealthDamage", OnDamage);
            EventHandler.RegisterEvent(m_Character, "OnRespawn", OnRespawn);
        }
예제 #14
0
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            m_CharacterTransform    = m_Character.transform;
            m_CharacterLocomotion   = m_Character.GetCachedComponent <UltimateCharacterLocomotion>();
            m_CharacterLayerManager = m_Character.GetCachedComponent <CharacterLayerManager>();

            m_MagicItemPerspectiveProperties = m_ActivePerspectiveProperties as IMagicItemPerspectiveProperties;

            DeserializeBeginActions(false);
            DeserializeCastActions(false);
            DeserializeImpactActions(false);
            DeserializeEndActions(false);

            if (m_CastActions != null)
            {
                m_CastActionUsed   = new bool[m_CastActions.Length];
                m_CastActionCasted = new bool[m_CastActions.Length];
            }
            if (m_SurfaceIndicator != null)
            {
                m_SurfaceIndicator.gameObject.SetActive(false);
            }
#if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
            // The local surface indicator should not show for remote players.
            if (m_NetworkInfo != null && !m_NetworkInfo.IsLocalPlayer())
            {
                m_SurfaceIndicator = null;
            }
#endif
        }
예제 #15
0
        /// <summary>
        /// A weapon has been fired and the smoke needs to show.
        /// </summary>
        /// <param name="item">The item that the muzzle flash is attached to.</param>
        /// <param name="itemActionID">The ID which corresponds to the ItemAction that spawned the smoke.</param>
        /// <param name="characterLocomotion">The character that the smoke is attached to.</param>
        public void Show(Item item, int itemActionID, UltimateCharacterLocomotion characterLocomotion)
        {
#if FIRST_PERSON_CONTROLLER && THIRD_PERSON_CONTROLLER
            m_Character = characterLocomotion.gameObject;
            EventHandler.RegisterEvent <bool>(m_Character, "OnCharacterChangePerspectives", OnChangePerspectives);

            m_Item             = item;
            m_ItemActionID     = itemActionID;
            m_GameObject.layer = characterLocomotion.FirstPersonPerspective ? LayerManager.Overlay : m_StartLayer;

            // Disable the object after the particles are done playing.
            float maxLifeTime = 0;
            for (int i = 0; i < m_Particles.Length; ++i)
            {
                m_Particles[i].Play();
                var lifeTime = 0f;
                if ((lifeTime = m_Particles[i].main.startLifetime.Evaluate(0)) > maxLifeTime)
                {
                    maxLifeTime = lifeTime;
                }
            }

            Scheduler.Schedule(maxLifeTime, DestroySelf);
#endif
        }
예제 #16
0
        /// <summary>
        /// Sets the originator of the TrajectoryObject.
        /// </summary>
        /// <param name="originator">The originator that should be set.</param>
        /// <param name="defaultNormalizedGravity">The default gravity direction.</param>
        protected void SetOriginator(GameObject originator, Vector3 defaultNormalizedGravity)
        {
            if (m_Originator == originator)
            {
                return;
            }

            if (originator != null)
            {
                m_Originator                    = originator;
                m_OriginatorTransform           = m_Originator.transform;
                m_OriginatorCharacterLocomotion = m_Originator.GetCachedComponent <UltimateCharacterLocomotion>();
                if (m_OriginatorCharacterLocomotion != null)
                {
                    m_NormalizedGravity = m_OriginatorCharacterLocomotion.GravityDirection;
                    m_TimeScale         = m_OriginatorCharacterLocomotion.TimeScale;
                    EventHandler.RegisterEvent <float>(m_Originator, "OnCharacterChangeTimeScale", OnChangeTimeScale);
                }
                else
                {
                    m_NormalizedGravity = defaultNormalizedGravity;
                    m_TimeScale         = 1;
                }
            }
            else
            {
                m_NormalizedGravity   = defaultNormalizedGravity;
                m_TimeScale           = 1;
                m_OriginatorTransform = null;
            }
        }
예제 #17
0
 /// <summary>
 /// Initializes the selector.
 /// </summary>
 /// <param name="gameObject">The GameObject that the state belongs to.</param>
 /// <param name="characterLocomotion">The character that the state bleongs to.</param>
 /// <param name="item">The item that the state belongs to.</param>
 /// <param name="states">The states which are being selected.</param>
 public virtual void Initialize(GameObject gameObject, UltimateCharacterLocomotion characterLocomotion, Item item, AnimatorAudioStateSet.AnimatorAudioState[] states)
 {
     m_Item                = item;
     m_Character           = characterLocomotion.gameObject;
     m_CharacterLocomotion = characterLocomotion;
     m_States              = states;
 }
예제 #18
0
        /// <summary>
        /// Adds the item ability with the specified type.
        /// </summary>
        /// <param name="characterLocomotion">The character to add the ability to.</param>
        /// <param name="abilityType">The type of ability to add.</param>
        /// <returns>The added ability.</returns>
        public static ItemAbility AddItemAbility(UltimateCharacterLocomotion characterLocomotion, Type abilityType, int index)
        {
            var itemAbilities = characterLocomotion.GetSerializedItemAbilities();

            if (itemAbilities == null)
            {
                itemAbilities = new ItemAbility[1];
            }
            else
            {
                Array.Resize(ref itemAbilities, itemAbilities.Length + 1);
            }
            var itemAbility = Activator.CreateInstance(abilityType) as ItemAbility;

            // Assign the default values specified by any added attribtes.
            SetAbilityDefaultValues(itemAbility);

            for (int i = itemAbilities.Length - 1; i > index; --i)
            {
                itemAbilities[i] = itemAbilities[i - 1];
            }
            itemAbilities[itemAbilities.Length - 1] = itemAbility;
            characterLocomotion.ItemAbilities       = itemAbilities;
            SerializeItemAbilities(characterLocomotion);
            return(itemAbility);
        }
예제 #19
0
        /// <summary>
        /// Retrieves the specified ability.
        /// </summary>
        public override void OnStart()
        {
            var target = GetDefaultGameObject(m_TargetGameObject.Value);

            if (target != m_PrevTarget)
            {
                m_CharacterLocomotion = target.GetCachedComponent <UltimateCharacterLocomotion>();
                // Find the specified ability.
                var abilities = m_CharacterLocomotion.GetAbilities(TaskUtility.GetTypeWithinAssembly(m_AbilityType.Value));
                if (abilities.Length > 1)
                {
                    // If there are multiple abilities found then the priority index should be used, otherwise set the ability to the first value.
                    if (m_PriorityIndex.Value != -1)
                    {
                        for (int i = 0; i < abilities.Length; ++i)
                        {
                            if (abilities[i].Index == m_PriorityIndex.Value)
                            {
                                m_Ability = abilities[i];
                                break;
                            }
                        }
                    }
                    else
                    {
                        m_Ability = abilities[0];
                    }
                }
                else if (abilities.Length == 1)
                {
                    m_Ability = abilities[0];
                }
                m_PrevTarget = target;
            }
        }
예제 #20
0
        /// <summary>
        /// Adds the item ability with the specified type.
        /// </summary>
        /// <param name="characterLocomotion">The character to add the ability to.</param>
        /// <param name="abilityType">The type of ability to add.</param>
        /// <returns>The added ability.</returns>
        public static ItemAbility AddItemAbility(UltimateCharacterLocomotion characterLocomotion, Type abilityType)
        {
            var itemAbilities = characterLocomotion.GetSerializedItemAbilities();
            var index         = itemAbilities == null ? 0 : itemAbilities.Length;

            return(AddItemAbility(characterLocomotion, abilityType, index));
        }
예제 #21
0
        /// <summary>
        /// Initializes the selector.
        /// </summary>
        /// <param name="gameObject">The GameObject that the state belongs to.</param>
        /// <param name="characterLocomotion">The character that the state bleongs to.</param>
        /// <param name="item">The item that the state belongs to.</param>
        /// <param name="states">The states which are being selected.</param>
        public override void Initialize(GameObject gameObject, UltimateCharacterLocomotion characterLocomotion, Item item, AnimatorAudioStateSet.AnimatorAudioState[] states)
        {
            base.Initialize(gameObject, characterLocomotion, item, states);

            // Call next state so the index will be initialized to a random value.
            NextState();
        }
예제 #22
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);
            }
        }
예제 #23
0
 /// <summary>
 /// The character has exited from the zone.
 /// </summary>
 /// <param name="characterLocomotion">The character that exited the zone.</param>
 protected override void CharacterExit(UltimateCharacterLocomotion characterLocomotion)
 {
     if (m_MovementTypeSwitcherEnabled)
     {
         m_MovementTypeSwitcher.enabled = true;
     }
 }
예제 #24
0
        /// <summary>
        /// Registeres for any interested events.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            m_GameObject          = gameObject;
            m_CharacterLocomotion = m_GameObject.GetCachedComponent <UltimateCharacterLocomotion>();

            // The third person objects will be hidden with the invisible shadow caster while in first person view.
            var characterRenderers = m_GameObject.GetComponentsInChildren <Renderer>(true);

            if (characterRenderers != null)
            {
                for (int i = 0; i < characterRenderers.Length; ++i)
                {
                    var characterRenderer = characterRenderers[i];
                    if (m_RegisteredRenderers.Contains(characterRenderer))
                    {
                        continue;
                    }

                    CacheRendererMaterials(characterRenderer);
                }
            }

            EventHandler.RegisterEvent <bool>(m_GameObject, "OnCameraChangePerspectives", OnChangePerspectives);
            EventHandler.RegisterEvent <Item>(m_GameObject, "OnInventoryAddItem", OnAddItem);
            EventHandler.RegisterEvent <Vector3, Vector3, GameObject>(m_GameObject, "OnDeath", OnDeath);
            EventHandler.RegisterEvent(m_GameObject, "OnWillRespawn", OnWillRespawn);
        }
예제 #25
0
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            m_GameObject            = gameObject;
            m_Transform             = transform;
            m_CharacterLocomotion   = m_GameObject.GetCachedComponent <UltimateCharacterLocomotion>();
            m_CharacterLayerManager = m_GameObject.GetCachedComponent <CharacterLayerManager>();
#if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
            m_NetworkInfo = m_GameObject.GetCachedComponent <INetworkInfo>();
#endif

            if (m_Feet == null)
            {
                InitializeHumanoidFeet(false);
            }

            if (m_Feet != null && m_Feet.Length != 0)
            {
                for (int i = 0; i < m_Feet.Length; ++i)
                {
                    if (m_Feet[i].Object == null)
                    {
                        continue;
                    }

                    // The FeetGrouping list should be at least the size of the current group index.
                    while (m_Feet[i].Group >= m_FeetGrouping.Count)
                    {
                        m_FeetGrouping.Add(new List <Transform>());
                    }
                    m_FeetGrouping[m_Feet[i].Group].Add(m_Feet[i].Object);
                    // The Transform should only be added to the set if the footprint is flipped. If the Transform is not in the set then the footprint is not flipped.
                    if (m_Feet[i].FlippedFootprint)
                    {
                        m_FlippedFootprints.Add(m_Feet[i].Object);
                    }
                }
            }
            else
            {
                m_FeetGrouping.Add(new List <Transform>());
                m_FeetGrouping[0].Add(m_Transform);
            }

            if (m_FootstepMode == FootstepPlacementMode.Trigger || m_FootstepMode == FootstepPlacementMode.CameraBob || m_FootstepMode == FootstepPlacementMode.None)
            {
                // The component doesn't need to be enabled if using a trigger - the FootstepTrigger component will detect the footstep. The CameraBob will enable the component
                // when the look source is attached.
                enabled = false;
            }
            else if (m_Feet != null)
            {
                PrepareVerticalOffsetLists();
            }

            EventHandler.RegisterEvent <ILookSource>(m_GameObject, "OnCharacterAttachLookSource", OnAttachLookSource);
            EventHandler.RegisterEvent <bool>(m_GameObject, "OnCharacterMoving", OnMoving);
        }
예제 #26
0
 /// <summary>
 /// The character has entered from the zone.
 /// </summary>
 /// <param name="characterLocomotion">The character that entered the zone.</param>
 protected override void CharacterEnter(UltimateCharacterLocomotion characterLocomotion)
 {
     for (int i = 0; i < m_ActiveItemSets.Length; ++i)
     {
         m_ActiveItemSets[i] = m_EquipUnequipAbilities[i].ActiveItemSetIndex;
     }
     ChangeMagicItem(0); // Start with the first item.
 }
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            m_CharacterLocomotion = m_GameObject.GetCachedComponent <UltimateCharacterLocomotion>();

            EventHandler.RegisterEvent <float>(m_GameObject, "OnCharacterLand", OnCharacterLand);
        }
예제 #28
0
        /// <summary>
        /// The character has entered from the zone.
        /// </summary>
        /// <param name="characterLocomotion">The character that entered the zone.</param>
        protected override void CharacterEnter(UltimateCharacterLocomotion characterLocomotion)
        {
            UpdateMovementType();

            // The buttons will change the movement types.
            m_MovementTypeSwitcherEnabled  = m_MovementTypeSwitcher.enabled;
            m_MovementTypeSwitcher.enabled = false;
        }
예제 #29
0
        /// <summary>
        /// Initializes the CastAction.
        /// </summary>
        /// <param name="character">The character GameObject.</param>
        /// <param name="magicItem">The MagicItem that the CastAction belongs to.</param>
        /// <param name="index">The index of the CastAction.</param>
        public override void Initialize(GameObject character, MagicItem magicItem, int index)
        {
            base.Initialize(character, magicItem, index);

            m_Transform           = character.transform;
            m_CharacterLocomotion = character.GetCachedComponent <UltimateCharacterLocomotion>();
            m_MaterialColorID     = Shader.PropertyToID(m_MaterialColorName);
        }
예제 #30
0
        /// <summary>
        /// Attaches the monitor to the specified character.
        /// </summary>
        /// <param name="character">The character to attach the monitor to.</param>
        protected override void OnAttachCharacter(GameObject character)
        {
            if (m_Character != null)
            {
                EventHandler.UnregisterEvent <Item, int>(m_Character, "OnAbilityWillEquipItem", OnEquipItem);
                EventHandler.UnregisterEvent <Item, bool>(m_Character, "OnItemUpdateDominantItem", OnUpdateDominantItem);
                EventHandler.UnregisterEvent <Item, int>(m_Character, "OnAbilityUnequipItemComplete", OnUnequipItem);
                EventHandler.UnregisterEvent <Item, int>(m_Character, "OnInventoryRemoveItem", OnUnequipItem);
                EventHandler.UnregisterEvent <bool, bool>(m_Character, "OnAddCrosshairsSpread", OnAddCrosshairsSpread);
                EventHandler.UnregisterEvent <bool, bool>(m_Character, "OnAimAbilityStart", OnAim);
                EventHandler.UnregisterEvent <Vector3, Vector3, GameObject>(m_Character, "OnDeath", OnDeath);
                EventHandler.UnregisterEvent(m_Character, "OnRespawn", OnRespawn);
                ResetMonitor();
            }

            base.OnAttachCharacter(character);

            if (m_Character == null)
            {
                return;
            }

            m_Camera           = Shared.Camera.CameraUtility.FindCamera(m_Character);
            m_CameraController = m_Camera.gameObject.GetCachedComponent <CameraController>();
            m_CameraController.SetCrosshairs(transform);

            m_AimAssist             = m_Camera.GetComponent <AimAssist>();
            m_CharacterTransform    = m_Character.transform;
            m_CharacterLayerManager = m_Character.GetCachedComponent <CharacterLayerManager>();
            m_CharacterLocomotion   = m_Character.GetCachedComponent <UltimateCharacterLocomotion>();
            m_PlayerInput           = m_Character.GetCachedComponent <Shared.Input.PlayerInput>();
            m_EnableImage           = false;
            gameObject.SetActive(CanShowUI());

            EventHandler.RegisterEvent <Item, int>(m_Character, "OnAbilityWillEquipItem", OnEquipItem);
            EventHandler.RegisterEvent <Item, bool>(m_Character, "OnItemUpdateDominantItem", OnUpdateDominantItem);
            EventHandler.RegisterEvent <Item, int>(m_Character, "OnAbilityUnequipItemComplete", OnUnequipItem);
            EventHandler.RegisterEvent <Item, int>(m_Character, "OnInventoryRemoveItem", OnUnequipItem);
            EventHandler.RegisterEvent <bool, bool>(m_Character, "OnAddCrosshairsSpread", OnAddCrosshairsSpread);
            EventHandler.RegisterEvent <bool, bool>(m_Character, "OnAimAbilityStart", OnAim);
            EventHandler.RegisterEvent <Vector3, Vector3, GameObject>(m_Character, "OnDeath", OnDeath);
            EventHandler.RegisterEvent(m_Character, "OnRespawn", OnRespawn);

            // An item may already be equipped.
            var inventory = m_Character.GetCachedComponent <Inventory.InventoryBase>();

            if (inventory != null)
            {
                for (int i = 0; i < inventory.SlotCount; ++i)
                {
                    var item = inventory.GetActiveItem(i);
                    if (item != null)
                    {
                        OnEquipItem(item, i);
                    }
                }
            }
        }