/// <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; } // 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_StoredAutoUpdateAmount = m_Attribute.AutoUpdateAmount; m_StoredAutoUpdateInterval = m_Attribute.AutoUpdateInterval; m_StoredAutoUpdateStartDelay = m_Attribute.AutoUpdateStartDelay; m_StoredAutoUpdateValueType = m_Attribute.AutoUpdateValueType; m_Attribute.AutoUpdateAmount = Mathf.Abs(m_Amount); m_Attribute.AutoUpdateInterval = m_AutoUpdateInterval; m_Attribute.AutoUpdateStartDelay = m_AutoUpdateStartDelay; m_Attribute.AutoUpdateValueType = m_Amount < 0 ? Attribute.AutoUpdateValue.Decrease : Attribute.AutoUpdateValue.Increase; m_Attribute.ScheduleAutoUpdate(m_AutoUpdateStartDelay); if (m_AutoUpdateDuration > 0) { m_DisableAutoUpdateEvent = Scheduler.Schedule(m_AutoUpdateDuration, EnableModifier, false); } } else { m_Attribute.AutoUpdateAmount = m_StoredAutoUpdateAmount; m_Attribute.AutoUpdateInterval = m_StoredAutoUpdateInterval; m_Attribute.AutoUpdateStartDelay = m_StoredAutoUpdateStartDelay; m_Attribute.AutoUpdateValueType = m_StoredAutoUpdateValueType; if (m_DisableAutoUpdateEvent != null) { Scheduler.Cancel(m_DisableAutoUpdateEvent); m_DisableAutoUpdateEvent = null; } m_Attribute.ScheduleAutoUpdate(m_StoredAutoUpdateStartDelay); } EventHandler.ExecuteEvent(this, "OnAttributeModifierAutoUpdateEnabled", this, enable); }
/// <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); }