/// <summary> /// Stops reloading the item in the specified slot. /// </summary> /// <param name="slotID">The ID of the slot to stop reloading the item at.</param> public void StopItemReload(int slotID) { if (m_ReloadableItems[slotID] == null) { return; } m_ReloadableItems[slotID].ItemReloadComplete(false, false); m_ReloadableItems[slotID] = null; m_Reloaded[slotID] = false; SchedulerBase.Cancel(m_ReloadEvents[slotID]); m_ReloadEvents[slotID] = null; m_CharacterLocomotion.UpdateItemAbilityAnimatorParameters(); // The ability won't be active if CanStartAbility filled in the ReloadableItem but the ability hasn't started yet. if (!IsActive) { return; } // The ability should stop if no more items can be reloaded. var canStop = true; for (int i = 0; i < m_ReloadableItems.Length; ++i) { if (m_ReloadableItems[i] != null) { canStop = false; } } if (canStop) { StopAbility(true); } }
/// <summary> /// The animator has finished playing the reload animation. /// </summary> /// <param name="slotID">The slot that is reloading the item.</param> private void ReloadItemComplete(int slotID) { var reloadableItem = m_ReloadableItems[slotID]; if (reloadableItem == null) { return; } m_ReloadableItems[slotID].ItemReloadComplete(true, false); m_ReloadableItems[slotID] = null; if (m_ReloadEvents[slotID] != null) { SchedulerBase.Cancel(m_ReloadEvents[slotID]); m_ReloadEvents[slotID] = null; } // Don't stop the ability unless all slots have been reloaded. var stopAbility = true; for (int i = 0; i < m_ReloadableItems.Length; ++i) { if (m_ReloadableItems[i] != null) { stopAbility = false; break; } } if (stopAbility) { StopAbility(); } }
/// <summary> /// Internal method which activates the state and then deactivates the state after the specified amount of time. /// </summary> /// <param name="stateGameObject">The GameObject to set the state on.</param> /// <param name="stateName">The name of the state to activate and then deactivate.</param> /// <param name="time">The amount of time that should elapse before the state is disabled.</param> private void DeactivateStateTimerInternal(GameObject stateGameObject, string stateName, float time) { if (m_DisableStateTimerMap == null) { m_DisableStateTimerMap = new Dictionary <GameObject, Dictionary <string, ScheduledEventBase> >(); } if (m_DisableStateTimerMap.TryGetValue(stateGameObject, out var stateNameEventMap)) { if (stateNameEventMap.TryGetValue(stateName, out var disableEvent)) { // The state name exists. This means that the timer is currently active and should first been cancelled. SchedulerBase.Cancel(disableEvent); disableEvent = SchedulerBase.Schedule(time, DeactivateState, stateGameObject, stateName); } else { // The state name hasn't been added yet. Add it to the map. disableEvent = SchedulerBase.Schedule(time, DeactivateState, stateGameObject, stateName); stateNameEventMap.Add(stateName, disableEvent); } } else { // Neither the GameObject nor the state has been activated. Create the maps. stateNameEventMap = new Dictionary <string, ScheduledEventBase>(); var disableEvent = SchedulerBase.Schedule(time, DeactivateState, stateGameObject, stateName); stateNameEventMap.Add(stateName, disableEvent); m_DisableStateTimerMap.Add(stateGameObject, stateNameEventMap); } }
/// <summary> /// The ThrowableItem has been reequipped. /// </summary> private void ReequipThrowableItem() { if (!m_Reequipping) { return; } SchedulerBase.Cancel(m_ReequipEventBase); m_ReequipEventBase = null; m_Reequipping = false; m_Reequipped = true; m_ReequipFrame = Time.frameCount; // The item shouldn't be reequipped if it is out of ammo. if (m_Inventory != null && m_Inventory.GetItemIdentifierAmount(m_Item.ItemIdentifier) == 0) { return; } if (!m_DisableVisibleObject) { EnableObjectMeshRenderers(true); #if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER if (m_NetworkInfo != null && m_NetworkInfo.IsLocalPlayer()) { m_NetworkCharacter.EnableThrowableObjectMeshRenderers(this); } #endif } }
/// <summary> /// The ability has stopped running. /// </summary> /// <param name="force">Was the ability force stopped?</param> protected override void AbilityStopped(bool force) { base.AbilityStopped(force); m_MoveTowardsLocation = null; if (force) { m_OnArriveAbility = null; } if (m_ForceStartEvent != null) { SchedulerBase.Cancel(m_ForceStartEvent); m_ForceStartEvent = null; } if (m_DisableGameplayInput) { EventHandler.ExecuteEvent(m_GameObject, "OnEnableGameplayInput", true); } if (m_PathfindingMovement != null && m_PathfindingMovement.IsActive) { m_PathfindingMovement.StopAbility(true); } // Reset the force independet look parameter set within StartAbility. EventHandler.ExecuteEvent(m_GameObject, "OnCharacterForceIndependentLook", false); // Start the OnArriveAbility after MoveTowards has stopped to prevent MoveTowards from affecting the arrive ability. if (m_OnArriveAbility != null) { m_CharacterLocomotion.TryStartAbility(m_OnArriveAbility, true, true); m_OnArriveAbility = null; } }
/// <summary> /// Stops the cast. /// </summary> public override void Stop() { if (!m_Active) { return; } m_ParticleSystem.Stop(true, ParticleSystemStopBehavior.StopEmitting); // Optionally fade the particle out of the world. if (m_FadeOutDuration > 0) { if (m_FadeEvent != null) { SchedulerBase.Cancel(m_FadeEvent); m_FadeEvent = null; } if (m_Renderers == null) { m_Renderers = m_ParticleSystem.GetComponentsInChildren <ParticleSystemRenderer>(); } var interval = m_FadeOutDuration / (1 / m_FadeStep); // Reset the alpha if the renderers have no fade in duration. if (m_FadeInDuration == 0) { SetRendererAlpha(1); } m_FadeEvent = SchedulerBase.Schedule(interval, FadeMaterials, interval, 0f); } m_Active = false; base.Stop(); }
/// <summary> /// The ability has stopped running. /// </summary> /// <param name="force">Was the ability force stopped?</param> protected override void AbilityStopped(bool force) { base.AbilityStopped(force); // The item may require root motion to prevent sliding. for (int i = 0; i < m_UsableItems.Length; ++i) { if (m_UsableItems[i] != null) { if (m_UsableItems[i].ForceRootMotionPosition) { m_CharacterLocomotion.ForceRootMotionPosition = false; } if (m_UsableItems[i].ForceRootMotionRotation) { m_CharacterLocomotion.ForceRootMotionRotation = false; } m_UsableItems[i].StopItemUse(); EventHandler.ExecuteEvent(m_GameObject, "OnItemStartUse", m_UsableItems[i], false); m_UsableItems[i] = null; m_UseCompleted[i] = true; if (m_UseEvent[i] != null) { SchedulerBase.Cancel(m_UseEvent[i]); m_UseEvent[i] = null; } ResetCanStopEvent(i); } } m_Started = false; EventHandler.ExecuteEvent(m_GameObject, "OnUseAbilityStart", false, this); }
/// <summary> /// The ability has stopped running. /// </summary> /// <param name="force">Was the ability force stopped?</param> protected override void AbilityStopped(bool force) { base.AbilityStopped(force); if (m_ExitedTrigger) { m_Interactable = null; m_DetectedTriggerObjectsCount = 0; DetectedObject = null; m_ExitedTrigger = false; } // The ability may end before the interaction duration has elapsed. if (m_DisableIKInteractionEvents != null) { for (int i = 0; i < m_DisableIKInteractionEvents.Length; ++i) { if (m_DisableIKInteractionEvents[i] == null) { continue; } m_DisableIKInteractionEvents[i].Invoke(); SchedulerBase.Cancel(m_DisableIKInteractionEvents[i]); m_DisableIKInteractionEvents[i] = null; } } }
/// <summary> /// Performs the cast. /// </summary> /// <param name="origin">The location that the cast should spawn from.</param> /// <param name="direction">The direction of the cast.</param> /// <param name="targetPosition">The target position of the cast.</param> public override void Cast(Transform origin, Vector3 direction, Vector3 targetPosition) { if (m_AudioSource != null && m_FadeEvent == null) { return; } if (m_AudioClips == null || m_AudioClips.Length == 0) { Debug.LogError("Error: An Audio Clip must be specified.", m_MagicItem); return; } var audioClip = m_AudioClips[Random.Range(0, m_AudioClips.Length)]; if (audioClip == null) { Debug.Log("Error: The Audio Clip array has a null value."); return; } m_AudioSource = AudioManager.PlayAtPosition(audioClip, m_PlayAtOrigin ? origin.position : m_GameObject.transform.position).AudioSource; if (m_AudioSource != null) { m_AudioSource.volume = 1; m_AudioSource.loop = m_Loop; } if (m_FadeEvent != null) { SchedulerBase.Cancel(m_FadeEvent); m_FadeEvent = null; } }
/// <summary> /// The effect has stopped running. /// </summary> protected override void EffectStopped() { base.EffectStopped(); SchedulerBase.Cancel(m_StopEvent); m_StopEvent = null; }
/// <summary> /// Cancels the remove event. /// </summary> public void CancelRemoveEvent() { if (m_RemoveEvent != null) { SchedulerBase.Cancel(m_RemoveEvent); m_RemoveEvent = null; } }
/// <summary> /// Cancels the respawn. /// </summary> public void CancelRespawn() { if (m_ScheduledRespawnEvent != null) { SchedulerBase.Cancel(m_ScheduledRespawnEvent); m_ScheduledRespawnEvent = null; } }
/// <summary> /// The object has been disabled. /// </summary> public void OnDisable() { if (m_DestructionEvent != null) { SchedulerBase.Cancel(m_DestructionEvent); m_DestructionEvent = null; } }
/// <summary> /// The object has collided with another object. /// </summary> /// <param name="hit">The RaycastHit of the object. Can be null.</param> protected override void OnCollision(RaycastHit?hit) { if (m_ScheduledDeactivation != null) { SchedulerBase.Cancel(m_ScheduledDeactivation); m_ScheduledDeactivation = null; } base.OnCollision(hit); }
/// <summary> /// Destroys the spring. /// </summary> public void Destroy() { if (m_ScheduledEvent != null) { SchedulerBase.Cancel(m_ScheduledEvent); m_ScheduledEvent = null; } m_SoftForceFrames = null; }
/// <summary> /// Schedules an auto update if the auto update value type is not set to none. /// </summary> /// <param name="delay">The amount to delay the attribute update event by.</param> public void ScheduleAutoUpdate(float delay) { SchedulerBase.Cancel(m_AutoUpdateEvent); if ((m_AutoUpdateValueType == AutoUpdateValue.Increase && m_Value != m_MaxValue) || (m_AutoUpdateValueType == AutoUpdateValue.Decrease && m_Value != m_MinValue)) { m_AutoUpdateEvent = SchedulerBase.Schedule(delay, UpdateValue); } }
/// <summary> /// Unregisters the object with the KinematicObjectManager. /// </summary> protected virtual void OnDisable() { if (m_NextWaypointEvent != null) { SchedulerBase.Cancel(m_NextWaypointEvent); m_NextWaypointEvent = null; } KinematicObjectManager.UnregisterKinematicObject(m_KinematicObjectIndex); }
/// <summary> /// The GameObject has been destroyed. /// </summary> protected virtual void OnDestroy() { if (m_ScheduledRespawnEvent != null) { SchedulerBase.Cancel(m_ScheduledRespawnEvent); m_ScheduledRespawnEvent = null; } EventHandler.UnregisterEvent <Vector3, Vector3, GameObject>(m_GameObject, "OnDeath", OnDeath); }
/// <summary> /// The ability has stopped running. /// </summary> /// <param name="force">Was the ability force stopped?</param> protected override void AbilityStopped(bool force) { base.AbilityStopped(force); m_CanStartTime = -1; // DetermineAbilityFloatDataValue no longer needs to be called. SchedulerBase.Cancel(m_FloatChangeEvent); m_FloatChangeEvent = null; }
/// <summary> /// The object has been destroyed. /// </summary> private void OnDestroy() { SchedulerBase.Cancel(m_ColliderOffsetEvent); EventHandler.UnregisterEvent(m_CharacterGameObject, "OnAnimatorSnapped", Initialize); EventHandler.UnregisterEvent <float>(m_CharacterGameObject, "OnHeightChangeAdjustHeight", AdjustCapsuleColliderHeight); EventHandler.UnregisterEvent <bool>(m_CharacterGameObject, "OnCharacterImmediateTransformChange", OnImmediateTransformChange); EventHandler.UnregisterEvent <Vector3, Vector3, GameObject>(m_CharacterGameObject, "OnDeath", OnDeath); EventHandler.UnregisterEvent(m_CharacterGameObject, "OnRespawn", OnRespawn); }
/// <summary> /// The component has been disabled. /// </summary> protected override void OnDisable() { base.OnDisable(); if (m_ScheduledDeactivation != null) { SchedulerBase.Cancel(m_ScheduledDeactivation); m_ScheduledDeactivation = null; } }
/// <summary> /// The ability has started. /// </summary> protected override void AbilityStarted() { base.AbilityStarted(); if (m_AlignToGravityReset != null) { SchedulerBase.Cancel(m_AlignToGravityReset); } m_CharacterLocomotion.AlignToGravity = true; m_Stopping = false; m_StoppingFromUpdate = false; }
/// <summary> /// The GameObject has been destroyed. /// </summary> private void OnDestroy() { EventHandler.UnregisterEvent <float>(gameObject, "OnCharacterChangeTimeScale", ChangeTimeScale); EventHandler.UnregisterEvent <bool>(gameObject, "OnEnableGameplayInput", EnableGameplayInput); EventHandler.UnregisterEvent <Vector3, Vector3, GameObject>(gameObject, "OnDeath", OnDeath); EventHandler.UnregisterEvent(gameObject, "OnRespawn", OnRespawn); if (m_ControllerCheckEvent != null) { SchedulerBase.Cancel(m_ControllerCheckEvent); m_ControllerCheckEvent = null; } }
/// <summary> /// Schedules the use event. /// </summary> /// <param name="slotID">The id of the slot that should be scheduled.</param> private void ScheduleUseEvent(int slotID) { if (m_UseEvent[slotID] != null) { SchedulerBase.Cancel(m_UseEvent[slotID]); m_UseEvent[slotID] = null; } if (!m_UsableItems[slotID].UseEvent.WaitForAnimationEvent) { m_UseEvent[slotID] = SchedulerBase.ScheduleFixed(m_UsableItems[slotID].UseEvent.Duration, UseItem, slotID); } }
/// <summary> /// Enables or disables the modifier. /// </summary> /// <param name="enable">Should the modifier be enabled?</param> public void EnableModifier(bool enable) { if (m_Attribute == null) { return; } m_DisableAutoUpdateEvent = null; // The attribute can be changed by a single value... if (enable && (!m_AutoUpdate || m_AutoUpdateStartDelay > 0)) { m_Attribute.Value += m_Amount; } if (!m_AutoUpdate || m_AutoUpdating == enable) { return; } // ...Or a change with a longer duration. m_AutoUpdating = enable; if (enable) { m_Attribute.StoreRestoreAutoUpdateValues(true); m_Attribute.AutoUpdateAmount = Mathf.Abs(m_Amount); m_Attribute.AutoUpdateStartDelay = -1; // Set the start delay to -1 to prevent the attribute from updating when changing the attribute properties. m_Attribute.AutoUpdateInterval = m_AutoUpdateInterval; m_Attribute.AutoUpdateValueType = m_Amount < 0 ? Attribute.AutoUpdateValue.Decrease : Attribute.AutoUpdateValue.Increase; m_Attribute.AutoUpdateStartDelay = m_AutoUpdateStartDelay; // Setting the actual start delay will update the value. if (m_AutoUpdateDuration > 0) { m_DisableAutoUpdateEvent = SchedulerBase.Schedule(m_AutoUpdateDuration, EnableModifier, false); } } else { m_Attribute.StoreRestoreAutoUpdateValues(false); if (m_DisableAutoUpdateEvent != null) { SchedulerBase.Cancel(m_DisableAutoUpdateEvent); m_DisableAutoUpdateEvent = null; } m_Attribute.ScheduleAutoUpdate(m_Attribute.AutoUpdateStartDelay); } EventHandler.ExecuteEvent(this, "OnAttributeModifierAutoUpdateEnabled", this, enable); }
/// <summary> /// The crate has been destroyed. Stop the particles. /// </summary> private void StopParticles() { if (m_StopEvent == null) { return; } SchedulerBase.Cancel(m_StopEvent); m_StopEvent = null; m_DamageTrigger.enabled = false; m_FlameParticle.Stop(true); m_FlameParticle = null; SchedulerBase.Schedule(0.2f, FadeAudioSource); }
/// <summary> /// Callback when a pointer has dragged the button. /// </summary> /// <param name="data">The pointer data.</param> public void OnDrag(PointerEventData data) { if (RectTransformUtility.RectangleContainsScreenPoint(m_RectTransform, data.position, null)) { var canvasScale = m_CanvasScalarTransform == null ? Vector3.one : m_CanvasScalarTransform.localScale; m_DeltaPosition.x += data.delta.x / canvasScale.x; m_DeltaPosition.y += data.delta.y / canvasScale.y; SchedulerBase.Cancel(m_ActiveDragScheduler); if (m_RequireActiveDrag) { m_ActiveDragScheduler = SchedulerBase.Schedule(Time.fixedDeltaTime, DampenDeltaPosition); } } }
/// <summary> /// The grenade has reached its lifespan. /// </summary> protected void Deactivate() { SchedulerBase.Cancel(m_ScheduledDeactivation); m_ScheduledDeactivation = null; InitializeComponentReferences(); // The grenade may explode before Awake is called. // Change the layer of the GameObject so the explosion doesn't detect the grenade when performing its overlap check. var prevLayer = m_GameObject.layer; m_GameObject.layer = LayerManager.IgnoreRaycast; Destruct(null); m_GameObject.layer = prevLayer; }
/// <summary> /// The action has stopped. /// </summary> public override void Stop() { if (!m_Active) { return; } #if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER if (m_MagicItem.NetworkInfo != null && !m_MagicItem.NetworkInfo.IsLocalPlayer()) { SchedulerBase.Cancel(m_UpdateEvent); m_UpdateEvent = null; } #endif EventHandler.ExecuteEvent(m_Character, "OnCharacterIndependentFade", false, false); m_Active = false; if (!m_RevertFadeOnStop) { return; } // Revert the values back to the original values. var fade = m_BeginFadeMaterials != null ? m_BeginFadeMaterials : this; var originalMaterialValues = fade.OriginalMaterialValuesMap; var materials = fade.Materials; for (int i = 0; i < materials.Count; ++i) { if (!originalMaterialValues.TryGetValue(materials[i], out var originalMaterialValue)) { continue; } // Revert the material back to the starting value. materials[i].SetColor(m_ColorID, originalMaterialValue.Color); if (originalMaterialValue.ContainsMode) { materials[i].SetFloat(OriginalMaterialValue.ModeID, originalMaterialValue.Mode); materials[i].SetInt(OriginalMaterialValue.SrcBlendID, originalMaterialValue.SrcBlend); materials[i].SetInt(OriginalMaterialValue.DstBlendID, originalMaterialValue.DstBlend); } if (!originalMaterialValue.AlphaBlend) { materials[i].DisableKeyword(OriginalMaterialValue.AlphaBlendString); } materials[i].renderQueue = originalMaterialValue.RenderQueue; } }
/// <summary> /// The ability has stopped running. /// </summary> /// <param name="force">Was the ability force stopped?</param> protected override void AbilityStopped(bool force) { base.AbilityStopped(force); // Ensure the arrays are set to null for the next run. for (int i = 0; i < m_ReloadableItems.Length; ++i) { if (m_ReloadableItems[i] != null) { m_ReloadableItems[i].ItemReloadComplete(!force, force); m_ReloadableItems[i] = null; SchedulerBase.Cancel(m_ReloadEvents[i]); m_ReloadEvents[i] = null; } } }