chore: initial commit
This commit is contained in:
523
Assets/Feel/MMTools/Core/MMUI/MMFader.cs
Normal file
523
Assets/Feel/MMTools/Core/MMUI/MMFader.cs
Normal file
@@ -0,0 +1,523 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
#if MM_UI
|
||||
using UnityEngine.UI;
|
||||
#endif
|
||||
using MoreMountains.Tools;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// An event used to stop fades
|
||||
/// </summary>
|
||||
public struct MMFadeStopEvent
|
||||
{
|
||||
/// an ID that has to match the one on the fader
|
||||
public int ID;
|
||||
public bool Restore;
|
||||
|
||||
public MMFadeStopEvent(int id = 0, bool restore = false)
|
||||
{
|
||||
Restore = restore;
|
||||
ID = id;
|
||||
}
|
||||
static MMFadeStopEvent e;
|
||||
public static void Trigger(int id = 0, bool restore = false)
|
||||
{
|
||||
e.ID = id;
|
||||
e.Restore = restore;
|
||||
MMEventManager.TriggerEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Events used to trigger faders on or off
|
||||
/// </summary>
|
||||
public struct MMFadeEvent
|
||||
{
|
||||
/// an ID that has to match the one on the fader
|
||||
public int ID;
|
||||
/// the duration of the fade, in seconds
|
||||
public float Duration;
|
||||
/// the alpha to aim for
|
||||
public float TargetAlpha;
|
||||
/// the curve to apply to the fade
|
||||
public MMTweenType Curve;
|
||||
/// whether or not this fade should ignore timescale
|
||||
public bool IgnoreTimeScale;
|
||||
/// a world position for a target object. Useless for regular fades, but can be useful for alt implementations (circle fade for example)
|
||||
public Vector3 WorldPosition;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MoreMountains.MMInterface.MMFadeEvent"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="duration">Duration, in seconds.</param>
|
||||
/// <param name="targetAlpha">Target alpha, from 0 to 1.</param>
|
||||
public MMFadeEvent(float duration, float targetAlpha, MMTweenType tween, int id=0,
|
||||
bool ignoreTimeScale = true, Vector3 worldPosition = new Vector3())
|
||||
{
|
||||
ID = id;
|
||||
Duration = duration;
|
||||
TargetAlpha = targetAlpha;
|
||||
Curve = tween;
|
||||
IgnoreTimeScale = ignoreTimeScale;
|
||||
WorldPosition = worldPosition;
|
||||
}
|
||||
static MMFadeEvent e;
|
||||
public static void Trigger(float duration, float targetAlpha)
|
||||
{
|
||||
Trigger(duration, targetAlpha, new MMTweenType(MMTween.MMTweenCurve.EaseInCubic));
|
||||
}
|
||||
public static void Trigger(float duration, float targetAlpha, MMTweenType tween, int id = 0,
|
||||
bool ignoreTimeScale = true, Vector3 worldPosition = new Vector3())
|
||||
{
|
||||
e.ID = id;
|
||||
e.Duration = duration;
|
||||
e.TargetAlpha = targetAlpha;
|
||||
e.Curve = tween;
|
||||
e.IgnoreTimeScale = ignoreTimeScale;
|
||||
e.WorldPosition = worldPosition;
|
||||
MMEventManager.TriggerEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
public struct MMFadeInEvent
|
||||
{
|
||||
/// an ID that has to match the one on the fader
|
||||
public int ID;
|
||||
/// the duration of the fade, in seconds
|
||||
public float Duration;
|
||||
/// the curve to apply to the fade
|
||||
public MMTweenType Curve;
|
||||
/// whether or not this fade should ignore timescale
|
||||
public bool IgnoreTimeScale;
|
||||
/// a world position for a target object. Useless for regular fades, but can be useful for alt implementations (circle fade for example)
|
||||
public Vector3 WorldPosition;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MoreMountains.MMInterface.MMFadeInEvent"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="duration">Duration.</param>
|
||||
public MMFadeInEvent(float duration, MMTweenType tween, int id = 0,
|
||||
bool ignoreTimeScale = true, Vector3 worldPosition = new Vector3())
|
||||
{
|
||||
ID = id;
|
||||
Duration = duration;
|
||||
Curve = tween;
|
||||
IgnoreTimeScale = ignoreTimeScale;
|
||||
WorldPosition = worldPosition;
|
||||
}
|
||||
static MMFadeInEvent e;
|
||||
public static void Trigger(float duration, MMTweenType tween, int id = 0,
|
||||
bool ignoreTimeScale = true, Vector3 worldPosition = new Vector3())
|
||||
{
|
||||
e.ID = id;
|
||||
e.Duration = duration;
|
||||
e.Curve = tween;
|
||||
e.IgnoreTimeScale = ignoreTimeScale;
|
||||
e.WorldPosition = worldPosition;
|
||||
MMEventManager.TriggerEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
public struct MMFadeOutEvent
|
||||
{
|
||||
/// an ID that has to match the one on the fader
|
||||
public int ID;
|
||||
/// the duration of the fade, in seconds
|
||||
public float Duration;
|
||||
/// the curve to apply to the fade
|
||||
public MMTweenType Curve;
|
||||
/// whether or not this fade should ignore timescale
|
||||
public bool IgnoreTimeScale;
|
||||
/// a world position for a target object. Useless for regular fades, but can be useful for alt implementations (circle fade for example)
|
||||
public Vector3 WorldPosition;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MoreMountains.MMInterface.MMFadeOutEvent"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="duration">Duration.</param>
|
||||
public MMFadeOutEvent(float duration, MMTweenType tween, int id = 0,
|
||||
bool ignoreTimeScale = true, Vector3 worldPosition = new Vector3())
|
||||
{
|
||||
ID = id;
|
||||
Duration = duration;
|
||||
Curve = tween;
|
||||
IgnoreTimeScale = ignoreTimeScale;
|
||||
WorldPosition = worldPosition;
|
||||
}
|
||||
|
||||
static MMFadeOutEvent e;
|
||||
public static void Trigger(float duration, MMTweenType tween, int id = 0,
|
||||
bool ignoreTimeScale = true, Vector3 worldPosition = new Vector3())
|
||||
{
|
||||
e.ID = id;
|
||||
e.Duration = duration;
|
||||
e.Curve = tween;
|
||||
e.IgnoreTimeScale = ignoreTimeScale;
|
||||
e.WorldPosition = worldPosition;
|
||||
MMEventManager.TriggerEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Fader class can be put on an Image, and it'll intercept MMFadeEvents and turn itself on or off accordingly.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(CanvasGroup))]
|
||||
#if MM_UI
|
||||
[RequireComponent(typeof(Image))]
|
||||
#endif
|
||||
[AddComponentMenu("More Mountains/Tools/GUI/MMFader")]
|
||||
public class MMFader : MMMonoBehaviour, MMEventListener<MMFadeEvent>, MMEventListener<MMFadeInEvent>, MMEventListener<MMFadeOutEvent>, MMEventListener<MMFadeStopEvent>
|
||||
{
|
||||
public enum ForcedInitStates { None, Active, Inactive }
|
||||
|
||||
[MMInspectorGroup("Identification", true, 122)]
|
||||
/// the ID for this fader (0 is default), set more IDs if you need more than one fader
|
||||
[Tooltip("the ID for this fader (0 is default), set more IDs if you need more than one fader")]
|
||||
public int ID;
|
||||
|
||||
[MMInspectorGroup("Opacity", true, 123)]
|
||||
/// the opacity the fader should be at when inactive
|
||||
[Tooltip("the opacity the fader should be at when inactive")]
|
||||
public float InactiveAlpha = 0f;
|
||||
/// the opacity the fader should be at when active
|
||||
[Tooltip("the opacity the fader should be at when active")]
|
||||
public float ActiveAlpha = 1f;
|
||||
/// determines whether a state should be forced on init
|
||||
[Tooltip("determines whether a state should be forced on init")]
|
||||
public ForcedInitStates ForcedInitState = ForcedInitStates.Inactive;
|
||||
|
||||
[MMInspectorGroup("Timing", true, 124)]
|
||||
/// the default duration of the fade in/out
|
||||
[Tooltip("the default duration of the fade in/out")]
|
||||
public float DefaultDuration = 0.2f;
|
||||
/// the default curve to use for this fader
|
||||
[Tooltip("the default curve to use for this fader")]
|
||||
public MMTweenType DefaultTween = new MMTweenType(MMTween.MMTweenCurve.LinearTween);
|
||||
/// whether or not the fade should happen in unscaled time
|
||||
[Tooltip("whether or not the fade should happen in unscaled time")]
|
||||
public bool IgnoreTimescale = true;
|
||||
/// whether or not this fader can cause a fade if the requested final alpha is the same as the current one
|
||||
[Tooltip("whether or not this fader can cause a fade if the requested final alpha is the same as the current one")]
|
||||
public bool CanFadeToCurrentAlpha = true;
|
||||
|
||||
[MMInspectorGroup("Interaction", true, 125)]
|
||||
/// whether or not the fader should block raycasts when visible
|
||||
[Tooltip("whether or not the fader should block raycasts when visible")]
|
||||
public bool ShouldBlockRaycasts = false;
|
||||
|
||||
[MMInspectorGroup("Debug", true, 126)]
|
||||
[MMInspectorButtonBar(new string[] { "FadeIn1Second", "FadeOut1Second", "DefaultFade", "ResetFader" },
|
||||
new string[] { "FadeIn1Second", "FadeOut1Second", "DefaultFade", "ResetFader" },
|
||||
new bool[] { true, true, true, true },
|
||||
new string[] { "main-call-to-action", "", "", "" })]
|
||||
public bool DebugToolbar;
|
||||
|
||||
protected CanvasGroup _canvasGroup;
|
||||
#if MM_UI
|
||||
protected Image _image;
|
||||
#endif
|
||||
|
||||
protected float _initialAlpha;
|
||||
protected float _currentTargetAlpha;
|
||||
protected float _currentDuration;
|
||||
protected MMTweenType _currentCurve;
|
||||
|
||||
protected bool _fading = false;
|
||||
protected float _fadeStartedAt;
|
||||
protected bool _frameCountOne;
|
||||
|
||||
/// <summary>
|
||||
/// Test method triggered by an inspector button
|
||||
/// </summary>
|
||||
protected virtual void ResetFader()
|
||||
{
|
||||
_canvasGroup.alpha = InactiveAlpha;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test method triggered by an inspector button
|
||||
/// </summary>
|
||||
protected virtual void DefaultFade()
|
||||
{
|
||||
MMFadeEvent.Trigger(DefaultDuration, ActiveAlpha, DefaultTween, ID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test method triggered by an inspector button
|
||||
/// </summary>
|
||||
protected virtual void FadeIn1Second()
|
||||
{
|
||||
MMFadeInEvent.Trigger(1f, new MMTweenType(MMTween.MMTweenCurve.LinearTween));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test method triggered by an inspector button
|
||||
/// </summary>
|
||||
protected virtual void FadeOut1Second()
|
||||
{
|
||||
MMFadeOutEvent.Trigger(1f, new MMTweenType(MMTween.MMTweenCurve.LinearTween));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On Start, we initialize our fader
|
||||
/// </summary>
|
||||
protected virtual void Awake()
|
||||
{
|
||||
Initialization();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On init, we grab our components, and disable/hide everything
|
||||
/// </summary>
|
||||
protected virtual void Initialization()
|
||||
{
|
||||
_canvasGroup = GetComponent<CanvasGroup>();
|
||||
|
||||
#if MM_UI
|
||||
_image = GetComponent<Image>();
|
||||
|
||||
if (ForcedInitState == ForcedInitStates.Inactive)
|
||||
{
|
||||
_canvasGroup.alpha = InactiveAlpha;
|
||||
_image.enabled = false;
|
||||
}
|
||||
else if (ForcedInitState == ForcedInitStates.Active)
|
||||
{
|
||||
_canvasGroup.alpha = ActiveAlpha;
|
||||
_image.enabled = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On Update, we update our alpha
|
||||
/// </summary>
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (_canvasGroup == null) { return; }
|
||||
|
||||
if (_fading)
|
||||
{
|
||||
Fade();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fades the canvasgroup towards its target alpha
|
||||
/// </summary>
|
||||
protected virtual void Fade()
|
||||
{
|
||||
float currentTime = IgnoreTimescale ? Time.unscaledTime : Time.time;
|
||||
|
||||
if (_frameCountOne)
|
||||
{
|
||||
if (Time.frameCount <= 2)
|
||||
{
|
||||
_canvasGroup.alpha = _initialAlpha;
|
||||
return;
|
||||
}
|
||||
_fadeStartedAt = IgnoreTimescale ? Time.unscaledTime : Time.time;
|
||||
currentTime = _fadeStartedAt;
|
||||
_frameCountOne = false;
|
||||
}
|
||||
|
||||
float endTime = _fadeStartedAt + _currentDuration;
|
||||
if (currentTime - _fadeStartedAt < _currentDuration)
|
||||
{
|
||||
float result = MMTween.Tween(currentTime, _fadeStartedAt, endTime, _initialAlpha, _currentTargetAlpha, _currentCurve);
|
||||
_canvasGroup.alpha = result;
|
||||
}
|
||||
else
|
||||
{
|
||||
StopFading();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the fading.
|
||||
/// </summary>
|
||||
protected virtual void StopFading()
|
||||
{
|
||||
_canvasGroup.alpha = _currentTargetAlpha;
|
||||
_fading = false;
|
||||
if (_canvasGroup.alpha == InactiveAlpha)
|
||||
{
|
||||
DisableFader();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disables the fader.
|
||||
/// </summary>
|
||||
protected virtual void DisableFader()
|
||||
{
|
||||
#if MM_UI
|
||||
_image.enabled = false;
|
||||
#endif
|
||||
if (ShouldBlockRaycasts)
|
||||
{
|
||||
_canvasGroup.blocksRaycasts = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables the fader.
|
||||
/// </summary>
|
||||
protected virtual void EnableFader()
|
||||
{
|
||||
#if MM_UI
|
||||
_image.enabled = true;
|
||||
#endif
|
||||
if (ShouldBlockRaycasts)
|
||||
{
|
||||
_canvasGroup.blocksRaycasts = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts fading this fader from the specified initial alpha to the target
|
||||
/// </summary>
|
||||
/// <param name="initialAlpha"></param>
|
||||
/// <param name="endAlpha"></param>
|
||||
/// <param name="duration"></param>
|
||||
/// <param name="curve"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="ignoreTimeScale"></param>
|
||||
protected virtual void StartFading(float initialAlpha, float endAlpha, float duration, MMTweenType curve, bool ignoreTimeScale)
|
||||
{
|
||||
if ((!CanFadeToCurrentAlpha) && (_canvasGroup.alpha == endAlpha))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IgnoreTimescale = ignoreTimeScale;
|
||||
EnableFader();
|
||||
_fading = true;
|
||||
_initialAlpha = initialAlpha;
|
||||
_currentTargetAlpha = endAlpha;
|
||||
_fadeStartedAt = IgnoreTimescale ? Time.unscaledTime : Time.time;
|
||||
_currentCurve = curve;
|
||||
_currentDuration = duration;
|
||||
if (Time.frameCount == 1)
|
||||
{
|
||||
_frameCountOne = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When catching a fade event, we fade our image in or out
|
||||
/// </summary>
|
||||
/// <param name="fadeEvent">Fade event.</param>
|
||||
public virtual void OnMMEvent(MMFadeEvent fadeEvent)
|
||||
{
|
||||
if (fadeEvent.ID != ID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Fade(fadeEvent.TargetAlpha, fadeEvent.Duration, fadeEvent.Curve, fadeEvent.IgnoreTimeScale);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When catching an MMFadeInEvent, we fade our image in
|
||||
/// </summary>
|
||||
/// <param name="fadeEvent">Fade event.</param>
|
||||
public virtual void OnMMEvent(MMFadeInEvent fadeEvent)
|
||||
{
|
||||
if (fadeEvent.ID != ID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FadeIn(fadeEvent.Duration, fadeEvent.Curve, fadeEvent.IgnoreTimeScale);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When catching an MMFadeOutEvent, we fade our image out
|
||||
/// </summary>
|
||||
/// <param name="fadeEvent">Fade event.</param>
|
||||
public virtual void OnMMEvent(MMFadeOutEvent fadeEvent)
|
||||
{
|
||||
if (fadeEvent.ID != ID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FadeOut(fadeEvent.Duration, fadeEvent.Curve, fadeEvent.IgnoreTimeScale);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method to fade towards the specified target alpha
|
||||
/// </summary>
|
||||
/// <param name="targetAlpha"></param>
|
||||
/// <param name="duration"></param>
|
||||
/// <param name="curve"></param>
|
||||
/// <param name="ignoreTimeScale"></param>
|
||||
public virtual void Fade(float targetAlpha, float duration, MMTweenType curve, bool ignoreTimeScale)
|
||||
{
|
||||
_currentTargetAlpha = (targetAlpha == -1) ? ActiveAlpha : targetAlpha;
|
||||
StartFading(_canvasGroup.alpha, _currentTargetAlpha, duration, curve, ignoreTimeScale);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method to cause a fade in over the specified duration and curve
|
||||
/// </summary>
|
||||
/// <param name="duration"></param>
|
||||
/// <param name="curve"></param>
|
||||
/// <param name="ignoreTimeScale"></param>
|
||||
public virtual void FadeIn(float duration, MMTweenType curve, bool ignoreTimeScale = true)
|
||||
{
|
||||
StartFading(InactiveAlpha, ActiveAlpha, duration, curve, ignoreTimeScale);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method to cause a fade out over the specified duration and curve
|
||||
/// </summary>
|
||||
/// <param name="duration"></param>
|
||||
/// <param name="curve"></param>
|
||||
/// <param name="ignoreTimeScale"></param>
|
||||
public virtual void FadeOut(float duration, MMTweenType curve, bool ignoreTimeScale = true)
|
||||
{
|
||||
StartFading(ActiveAlpha, InactiveAlpha, duration, curve, ignoreTimeScale);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When catching an MMFadeStopEvent, we stop our fade
|
||||
/// </summary>
|
||||
/// <param name="fadeEvent">Fade event.</param>
|
||||
public virtual void OnMMEvent(MMFadeStopEvent fadeStopEvent)
|
||||
{
|
||||
if (fadeStopEvent.ID == ID)
|
||||
{
|
||||
_fading = false;
|
||||
if (fadeStopEvent.Restore)
|
||||
{
|
||||
_canvasGroup.alpha = _initialAlpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On enable, we start listening to events
|
||||
/// </summary>
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
this.MMEventStartListening<MMFadeEvent>();
|
||||
this.MMEventStartListening<MMFadeStopEvent>();
|
||||
this.MMEventStartListening<MMFadeInEvent>();
|
||||
this.MMEventStartListening<MMFadeOutEvent>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On disable, we stop listening to events
|
||||
/// </summary>
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
this.MMEventStopListening<MMFadeEvent>();
|
||||
this.MMEventStopListening<MMFadeStopEvent>();
|
||||
this.MMEventStopListening<MMFadeInEvent>();
|
||||
this.MMEventStopListening<MMFadeOutEvent>();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Assets/Feel/MMTools/Core/MMUI/MMFader.cs.meta
Normal file
13
Assets/Feel/MMTools/Core/MMUI/MMFader.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efe052b91c95c534b8bf0f64fb0b9151
|
||||
timeCreated: 1523969902
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
367
Assets/Feel/MMTools/Core/MMUI/MMFaderDirectional.cs
Normal file
367
Assets/Feel/MMTools/Core/MMUI/MMFaderDirectional.cs
Normal file
@@ -0,0 +1,367 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// The Fader class can be put on an Image, and it'll intercept MMFadeEvents and turn itself on or off accordingly.
|
||||
/// This specific fader will move from left to right, right to left, top to bottom or bottom to top
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(CanvasGroup))]
|
||||
[AddComponentMenu("More Mountains/Tools/GUI/MMFaderDirectional")]
|
||||
public class MMFaderDirectional : MMMonoBehaviour, MMEventListener<MMFadeEvent>, MMEventListener<MMFadeInEvent>, MMEventListener<MMFadeOutEvent>, MMEventListener<MMFadeStopEvent>
|
||||
{
|
||||
/// the possible directions this fader can move in
|
||||
public enum Directions { TopToBottom, LeftToRight, RightToLeft, BottomToTop }
|
||||
|
||||
[MMInspectorGroup("Identification", true, 122)]
|
||||
/// the ID for this fader (0 is default), set more IDs if you need more than one fader
|
||||
[Tooltip("the ID for this fader (0 is default), set more IDs if you need more than one fader")]
|
||||
public int ID;
|
||||
|
||||
[MMInspectorGroup("Directional Fader", true, 123)]
|
||||
/// the direction this fader should move in when fading in
|
||||
[Tooltip("the direction this fader should move in when fading in")]
|
||||
public Directions FadeInDirection = Directions.LeftToRight;
|
||||
/// the direction this fader should move in when fading out
|
||||
[Tooltip("the direction this fader should move in when fading out")]
|
||||
public Directions FadeOutDirection = Directions.LeftToRight;
|
||||
|
||||
[MMInspectorGroup("Timing", true, 124)]
|
||||
/// the default duration of the fade in/out
|
||||
[Tooltip("the default duration of the fade in/out")]
|
||||
public float DefaultDuration = 0.2f;
|
||||
/// the default curve to use for this fader
|
||||
[Tooltip("the default curve to use for this fader")]
|
||||
public MMTweenType DefaultTween = new MMTweenType(MMTween.MMTweenCurve.LinearTween);
|
||||
/// whether or not the fade should happen in unscaled time
|
||||
[Tooltip("whether or not the fade should happen in unscaled time")]
|
||||
public bool IgnoreTimescale = true;
|
||||
/// whether or not to automatically disable this fader on init
|
||||
[Tooltip("whether or not to automatically disable this fader on init")]
|
||||
public bool DisableOnInit = true;
|
||||
|
||||
[MMInspectorGroup("Delay", true, 127)]
|
||||
/// a delay (in seconds) to apply before playing this fade
|
||||
[Tooltip("a delay (in seconds) to apply before playing this fade")]
|
||||
public float InitialDelay = 0f;
|
||||
|
||||
[MMInspectorGroup("Interaction", true, 125)]
|
||||
/// whether or not the fader should block raycasts when visible
|
||||
[Tooltip("whether or not the fader should block raycasts when visible")]
|
||||
public bool ShouldBlockRaycasts = false;
|
||||
|
||||
/// the width of the fader
|
||||
public virtual float Width { get { return _rectTransform.rect.width; } }
|
||||
/// the height of the fader
|
||||
public virtual float Height { get { return _rectTransform.rect.height; } }
|
||||
|
||||
[MMInspectorGroup("Debug", true, 126)]
|
||||
[MMInspectorButtonBar(new string[] { "FadeIn1Second", "FadeOut1Second", "DefaultFade", "ResetFader" },
|
||||
new string[] { "FadeIn1Second", "FadeOut1Second", "DefaultFade", "ResetFader" },
|
||||
new bool[] { true, true, true, true },
|
||||
new string[] { "main-call-to-action", "", "", "" })]
|
||||
public bool DebugToolbar;
|
||||
|
||||
protected RectTransform _rectTransform;
|
||||
protected CanvasGroup _canvasGroup;
|
||||
protected float _currentDuration;
|
||||
protected MMTweenType _currentCurve;
|
||||
protected bool _fading = false;
|
||||
protected float _fadeStartedAt;
|
||||
protected Vector2 _initialPosition;
|
||||
|
||||
protected Vector2 _fromPosition;
|
||||
protected Vector2 _toPosition;
|
||||
protected Vector2 _newPosition;
|
||||
protected bool _active;
|
||||
protected bool _initialized = false;
|
||||
|
||||
/// <summary>
|
||||
/// Test method triggered by an inspector button
|
||||
/// </summary>
|
||||
protected virtual void ResetFader()
|
||||
{
|
||||
_rectTransform.anchoredPosition = _initialPosition;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test method triggered by an inspector button
|
||||
/// </summary>
|
||||
protected virtual void DefaultFade()
|
||||
{
|
||||
MMFadeEvent.Trigger(DefaultDuration, 1f, DefaultTween, ID, IgnoreTimescale, this.transform.position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test method triggered by an inspector button
|
||||
/// </summary>
|
||||
protected virtual void FadeIn1Second()
|
||||
{
|
||||
MMFadeInEvent.Trigger(1f, DefaultTween, ID, IgnoreTimescale, this.transform.position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test method triggered by an inspector button
|
||||
/// </summary>
|
||||
protected virtual void FadeOut1Second()
|
||||
{
|
||||
MMFadeOutEvent.Trigger(1f, DefaultTween, ID, IgnoreTimescale, this.transform.position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On Start, we initialize our fader
|
||||
/// </summary>
|
||||
protected virtual void Start()
|
||||
{
|
||||
Initialization();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On init, we grab our components, and disable/hide everything
|
||||
/// </summary>
|
||||
//protected virtual IEnumerator Initialization()
|
||||
protected virtual void Initialization()
|
||||
{
|
||||
_canvasGroup = this.gameObject.GetComponent<CanvasGroup>();
|
||||
_rectTransform = this.gameObject.GetComponent<RectTransform>();
|
||||
_initialPosition = _rectTransform.anchoredPosition;
|
||||
if (DisableOnInit)
|
||||
{
|
||||
DisableFader();
|
||||
}
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On Update, we update our alpha
|
||||
/// </summary>
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (_canvasGroup == null) { return; }
|
||||
|
||||
if (_fading)
|
||||
{
|
||||
Fade();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fades the canvasgroup towards its target alpha
|
||||
/// </summary>
|
||||
protected virtual void Fade()
|
||||
{
|
||||
float currentTime = IgnoreTimescale ? Time.unscaledTime : Time.time;
|
||||
float endTime = _fadeStartedAt + _currentDuration;
|
||||
|
||||
if (currentTime - _fadeStartedAt < _currentDuration)
|
||||
{
|
||||
_newPosition = MMTween.Tween(currentTime, _fadeStartedAt, endTime, _fromPosition, _toPosition, _currentCurve);
|
||||
_rectTransform.anchoredPosition = _newPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
StopFading();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the fading.
|
||||
/// </summary>
|
||||
protected virtual void StopFading()
|
||||
{
|
||||
_rectTransform.anchoredPosition = _toPosition;
|
||||
_fading = false;
|
||||
|
||||
if (_initialPosition != _toPosition)
|
||||
{
|
||||
DisableFader();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts a fade
|
||||
/// </summary>
|
||||
/// <param name="fadingIn"></param>
|
||||
/// <param name="duration"></param>
|
||||
/// <param name="curve"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="ignoreTimeScale"></param>
|
||||
/// <param name="worldPosition"></param>
|
||||
protected virtual IEnumerator StartFading(bool fadingIn, float duration, MMTweenType curve, int id,
|
||||
bool ignoreTimeScale, Vector3 worldPosition)
|
||||
{
|
||||
if (id != ID)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (InitialDelay > 0f)
|
||||
{
|
||||
yield return MMCoroutine.WaitFor(InitialDelay);
|
||||
}
|
||||
|
||||
if (!_initialized)
|
||||
{
|
||||
Initialization();
|
||||
}
|
||||
|
||||
if (curve == null)
|
||||
{
|
||||
curve = DefaultTween;
|
||||
}
|
||||
|
||||
IgnoreTimescale = ignoreTimeScale;
|
||||
EnableFader();
|
||||
_fading = true;
|
||||
|
||||
_fadeStartedAt = IgnoreTimescale ? Time.unscaledTime : Time.time;
|
||||
_currentCurve = curve;
|
||||
_currentDuration = duration;
|
||||
|
||||
_fromPosition = _rectTransform.anchoredPosition;
|
||||
_toPosition = fadingIn ? _initialPosition : ExitPosition();
|
||||
|
||||
_newPosition = MMTween.Tween(0f, 0f, duration, _fromPosition, _toPosition, _currentCurve);
|
||||
_rectTransform.anchoredPosition = _newPosition;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines the position of the fader before entry
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected virtual Vector2 BeforeEntryPosition()
|
||||
{
|
||||
switch (FadeInDirection)
|
||||
{
|
||||
case Directions.BottomToTop:
|
||||
return _initialPosition + Vector2.down * Height;
|
||||
case Directions.LeftToRight:
|
||||
return _initialPosition + Vector2.left * Width;
|
||||
case Directions.RightToLeft:
|
||||
return _initialPosition + Vector2.right * Width;
|
||||
case Directions.TopToBottom:
|
||||
return _initialPosition + Vector2.up * Height;
|
||||
}
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines the exit position of the fader
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected virtual Vector2 ExitPosition()
|
||||
{
|
||||
switch (FadeOutDirection)
|
||||
{
|
||||
case Directions.BottomToTop:
|
||||
return _initialPosition + Vector2.up * Height;
|
||||
case Directions.LeftToRight:
|
||||
return _initialPosition + Vector2.right * Width;
|
||||
case Directions.RightToLeft:
|
||||
return _initialPosition + Vector2.left * Width;
|
||||
case Directions.TopToBottom:
|
||||
return _initialPosition + Vector2.down * Height;
|
||||
}
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disables the fader.
|
||||
/// </summary>
|
||||
protected virtual void DisableFader()
|
||||
{
|
||||
if (ShouldBlockRaycasts)
|
||||
{
|
||||
_canvasGroup.blocksRaycasts = false;
|
||||
}
|
||||
_active = false;
|
||||
_canvasGroup.alpha = 0;
|
||||
_rectTransform.anchoredPosition = BeforeEntryPosition();
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables the fader.
|
||||
/// </summary>
|
||||
protected virtual void EnableFader()
|
||||
{
|
||||
this.enabled = true;
|
||||
if (ShouldBlockRaycasts)
|
||||
{
|
||||
_canvasGroup.blocksRaycasts = true;
|
||||
}
|
||||
_active = true;
|
||||
_canvasGroup.alpha = 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When catching a fade event, we fade our image in or out
|
||||
/// </summary>
|
||||
/// <param name="fadeEvent">Fade event.</param>
|
||||
public virtual void OnMMEvent(MMFadeEvent fadeEvent)
|
||||
{
|
||||
bool status = _active ? false : true;
|
||||
StartCoroutine(StartFading(status, fadeEvent.Duration, fadeEvent.Curve, fadeEvent.ID,
|
||||
fadeEvent.IgnoreTimeScale, fadeEvent.WorldPosition));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When catching an MMFadeInEvent, we fade our image in
|
||||
/// </summary>
|
||||
/// <param name="fadeEvent">Fade event.</param>
|
||||
public virtual void OnMMEvent(MMFadeInEvent fadeEvent)
|
||||
{
|
||||
StartCoroutine(StartFading(true, fadeEvent.Duration, fadeEvent.Curve, fadeEvent.ID,
|
||||
fadeEvent.IgnoreTimeScale, fadeEvent.WorldPosition));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When catching an MMFadeOutEvent, we fade our image out
|
||||
/// </summary>
|
||||
/// <param name="fadeEvent">Fade event.</param>
|
||||
public virtual void OnMMEvent(MMFadeOutEvent fadeEvent)
|
||||
{
|
||||
StartCoroutine(StartFading(false, fadeEvent.Duration, fadeEvent.Curve, fadeEvent.ID,
|
||||
fadeEvent.IgnoreTimeScale, fadeEvent.WorldPosition));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When catching an MMFadeStopEvent, we stop our fade
|
||||
/// </summary>
|
||||
/// <param name="fadeEvent">Fade event.</param>
|
||||
public virtual void OnMMEvent(MMFadeStopEvent fadeStopEvent)
|
||||
{
|
||||
if (fadeStopEvent.ID == ID)
|
||||
{
|
||||
_fading = false;
|
||||
if (fadeStopEvent.Restore)
|
||||
{
|
||||
_rectTransform.anchoredPosition = _initialPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On enable, we start listening to events
|
||||
/// </summary>
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
this.MMEventStartListening<MMFadeEvent>();
|
||||
this.MMEventStartListening<MMFadeStopEvent>();
|
||||
this.MMEventStartListening<MMFadeInEvent>();
|
||||
this.MMEventStartListening<MMFadeOutEvent>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On disable, we stop listening to events
|
||||
/// </summary>
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
this.MMEventStopListening<MMFadeEvent>();
|
||||
this.MMEventStopListening<MMFadeStopEvent>();
|
||||
this.MMEventStopListening<MMFadeInEvent>();
|
||||
this.MMEventStopListening<MMFadeOutEvent>();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Feel/MMTools/Core/MMUI/MMFaderDirectional.cs.meta
Normal file
11
Assets/Feel/MMTools/Core/MMUI/MMFaderDirectional.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 315af83f344d8a24e9f6d1399e439fdd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
304
Assets/Feel/MMTools/Core/MMUI/MMFaderRound.cs
Normal file
304
Assets/Feel/MMTools/Core/MMUI/MMFaderRound.cs
Normal file
@@ -0,0 +1,304 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// The Fader class can be put on an Image, and it'll intercept MMFadeEvents and turn itself on or off accordingly.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(CanvasGroup))]
|
||||
[AddComponentMenu("More Mountains/Tools/GUI/MMFaderRound")]
|
||||
public class MMFaderRound : MMMonoBehaviour, MMEventListener<MMFadeEvent>, MMEventListener<MMFadeInEvent>, MMEventListener<MMFadeOutEvent>, MMEventListener<MMFadeStopEvent>
|
||||
{
|
||||
public enum CameraModes { Main, Override }
|
||||
|
||||
[MMInspectorGroup("Bindings", true, 121)]
|
||||
public CameraModes CameraMode = CameraModes.Main;
|
||||
[MMEnumCondition("CameraMode",(int)CameraModes.Override)]
|
||||
/// the camera to pick the position from (usually the "regular" game camera)
|
||||
public Camera TargetCamera;
|
||||
/// the background to fade
|
||||
public RectTransform FaderBackground;
|
||||
/// the mask used to draw a hole in the background that will get faded / scaled
|
||||
public RectTransform FaderMask;
|
||||
|
||||
[MMInspectorGroup("Identification", true, 122)]
|
||||
/// the ID for this fader (0 is default), set more IDs if you need more than one fader
|
||||
public int ID;
|
||||
|
||||
[MMInspectorGroup("Mask", true, 127)]
|
||||
[MMVector("min", "max")]
|
||||
/// the mask's scale at minimum and maximum opening
|
||||
public Vector2 MaskScale;
|
||||
|
||||
[MMInspectorGroup("Timing", true, 124)]
|
||||
/// the default duration of the fade in/out
|
||||
public float DefaultDuration = 0.2f;
|
||||
/// the default curve to use for this fader
|
||||
public MMTweenType DefaultTween = new MMTweenType(MMTween.MMTweenCurve.LinearTween);
|
||||
/// whether or not the fade should happen in unscaled time
|
||||
public bool IgnoreTimescale = true;
|
||||
|
||||
[MMInspectorGroup("Interaction", true, 125)]
|
||||
/// whether or not the fader should block raycasts when visible
|
||||
public bool ShouldBlockRaycasts = false;
|
||||
|
||||
[MMInspectorGroup("Debug", true, 126)]
|
||||
public Transform DebugWorldPositionTarget;
|
||||
[MMInspectorButtonBar(new string[] { "FadeIn1Second", "FadeOut1Second", "DefaultFade", "ResetFader" },
|
||||
new string[] { "FadeIn1Second", "FadeOut1Second", "DefaultFade", "ResetFader" },
|
||||
new bool[] { true, true, true, true },
|
||||
new string[] { "main-call-to-action", "", "", "" })]
|
||||
public bool DebugToolbar;
|
||||
protected CanvasGroup _canvasGroup;
|
||||
|
||||
protected float _initialScale;
|
||||
protected float _currentTargetScale;
|
||||
|
||||
protected float _currentDuration;
|
||||
protected MMTweenType _currentCurve;
|
||||
|
||||
protected bool _fading = false;
|
||||
protected float _fadeStartedAt;
|
||||
|
||||
/// <summary>
|
||||
/// Test method triggered by an inspector button
|
||||
/// </summary>
|
||||
protected virtual void ResetFader()
|
||||
{
|
||||
FaderMask.transform.localScale = MaskScale.x * Vector3.one;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test method triggered by an inspector button
|
||||
/// </summary>
|
||||
protected virtual void DefaultFade()
|
||||
{
|
||||
MMFadeEvent.Trigger(DefaultDuration, MaskScale.y, DefaultTween, ID, IgnoreTimescale, DebugWorldPositionTarget.transform.position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test method triggered by an inspector button
|
||||
/// </summary>
|
||||
protected virtual void FadeIn1Second()
|
||||
{
|
||||
MMFadeInEvent.Trigger(1f, DefaultTween, ID, IgnoreTimescale, DebugWorldPositionTarget.transform.position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test method triggered by an inspector button
|
||||
/// </summary>
|
||||
protected virtual void FadeOut1Second()
|
||||
{
|
||||
MMFadeOutEvent.Trigger(1f, DefaultTween, ID, IgnoreTimescale, DebugWorldPositionTarget.transform.position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On Start, we initialize our fader
|
||||
/// </summary>
|
||||
protected virtual void Awake()
|
||||
{
|
||||
Initialization();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On init, we grab our components, and disable/hide everything
|
||||
/// </summary>
|
||||
protected virtual void Initialization()
|
||||
{
|
||||
if (CameraMode == CameraModes.Main)
|
||||
{
|
||||
TargetCamera = Camera.main;
|
||||
}
|
||||
_canvasGroup = GetComponent<CanvasGroup>();
|
||||
FaderMask.transform.localScale = MaskScale.x * Vector3.one;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On Update, we update our alpha
|
||||
/// </summary>
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (_canvasGroup == null) { return; }
|
||||
|
||||
if (_fading)
|
||||
{
|
||||
Fade();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fades the canvasgroup towards its target alpha
|
||||
/// </summary>
|
||||
protected virtual void Fade()
|
||||
{
|
||||
float currentTime = IgnoreTimescale ? Time.unscaledTime : Time.time;
|
||||
float endTime = _fadeStartedAt + _currentDuration;
|
||||
if (currentTime - _fadeStartedAt < _currentDuration)
|
||||
{
|
||||
float newScale = MMTween.Tween(currentTime, _fadeStartedAt, endTime, _initialScale, _currentTargetScale, _currentCurve);
|
||||
FaderMask.transform.localScale = newScale * Vector3.one;
|
||||
}
|
||||
else
|
||||
{
|
||||
StopFading();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the fading.
|
||||
/// </summary>
|
||||
protected virtual void StopFading()
|
||||
{
|
||||
FaderMask.transform.localScale = _currentTargetScale * Vector3.one;
|
||||
_fading = false;
|
||||
if (FaderMask.transform.localScale == MaskScale.y * Vector3.one)
|
||||
{
|
||||
DisableFader();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disables the fader.
|
||||
/// </summary>
|
||||
protected virtual void DisableFader()
|
||||
{
|
||||
if (ShouldBlockRaycasts)
|
||||
{
|
||||
_canvasGroup.blocksRaycasts = false;
|
||||
}
|
||||
_canvasGroup.alpha = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables the fader.
|
||||
/// </summary>
|
||||
protected virtual void EnableFader()
|
||||
{
|
||||
if (ShouldBlockRaycasts)
|
||||
{
|
||||
_canvasGroup.blocksRaycasts = true;
|
||||
}
|
||||
_canvasGroup.alpha = 1;
|
||||
}
|
||||
|
||||
protected virtual void StartFading(float initialAlpha, float endAlpha, float duration, MMTweenType curve, int id,
|
||||
bool ignoreTimeScale, Vector3 worldPosition)
|
||||
{
|
||||
if (id != ID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (TargetCamera == null)
|
||||
{
|
||||
Debug.LogWarning(this.name + " : You're using a fader round but its TargetCamera hasn't been setup in its inspector. It can't fade.");
|
||||
return;
|
||||
}
|
||||
|
||||
FaderMask.anchoredPosition = Vector3.zero;
|
||||
|
||||
Vector3 viewportPosition = TargetCamera.WorldToViewportPoint(worldPosition);
|
||||
viewportPosition.x = Mathf.Clamp01(viewportPosition.x);
|
||||
viewportPosition.y = Mathf.Clamp01(viewportPosition.y);
|
||||
viewportPosition.z = Mathf.Clamp01(viewportPosition.z);
|
||||
|
||||
FaderMask.anchorMin = viewportPosition;
|
||||
FaderMask.anchorMax = viewportPosition;
|
||||
|
||||
IgnoreTimescale = ignoreTimeScale;
|
||||
EnableFader();
|
||||
_fading = true;
|
||||
_initialScale = initialAlpha;
|
||||
_currentTargetScale = endAlpha;
|
||||
_fadeStartedAt = IgnoreTimescale ? Time.unscaledTime : Time.time;
|
||||
_currentCurve = curve;
|
||||
_currentDuration = duration;
|
||||
|
||||
float newScale = MMTween.Tween(0f, 0f, duration, _initialScale, _currentTargetScale, _currentCurve);
|
||||
FaderMask.transform.localScale = newScale * Vector3.one;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When catching a fade event, we fade our image in or out
|
||||
/// </summary>
|
||||
/// <param name="fadeEvent">Fade event.</param>
|
||||
public virtual void OnMMEvent(MMFadeEvent fadeEvent)
|
||||
{
|
||||
_currentTargetScale = (fadeEvent.TargetAlpha == -1) ? MaskScale.y : fadeEvent.TargetAlpha;
|
||||
StartFading(FaderMask.transform.localScale.x, _currentTargetScale, fadeEvent.Duration, fadeEvent.Curve, fadeEvent.ID,
|
||||
fadeEvent.IgnoreTimeScale, fadeEvent.WorldPosition);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When catching an MMFadeInEvent, we fade our image in
|
||||
/// </summary>
|
||||
/// <param name="fadeEvent">Fade event.</param>
|
||||
public virtual void OnMMEvent(MMFadeInEvent fadeEvent)
|
||||
{
|
||||
if (fadeEvent.Duration > 0)
|
||||
{
|
||||
StartFading(MaskScale.y, MaskScale.x, fadeEvent.Duration, fadeEvent.Curve, fadeEvent.ID,
|
||||
fadeEvent.IgnoreTimeScale, fadeEvent.WorldPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
FaderMask.transform.localScale = MaskScale.x * Vector3.one;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When catching an MMFadeOutEvent, we fade our image out
|
||||
/// </summary>
|
||||
/// <param name="fadeEvent">Fade event.</param>
|
||||
public virtual void OnMMEvent(MMFadeOutEvent fadeEvent)
|
||||
{
|
||||
if (fadeEvent.Duration > 0)
|
||||
{
|
||||
StartFading(MaskScale.x, MaskScale.y, fadeEvent.Duration, fadeEvent.Curve, fadeEvent.ID,
|
||||
fadeEvent.IgnoreTimeScale, fadeEvent.WorldPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
FaderMask.transform.localScale = MaskScale.y * Vector3.one;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When catching an MMFadeStopEvent, we stop our fade
|
||||
/// </summary>
|
||||
/// <param name="fadeEvent">Fade event.</param>
|
||||
public virtual void OnMMEvent(MMFadeStopEvent fadeStopEvent)
|
||||
{
|
||||
if (fadeStopEvent.ID == ID)
|
||||
{
|
||||
_fading = false;
|
||||
if (fadeStopEvent.Restore)
|
||||
{
|
||||
FaderMask.transform.localScale = _initialScale * Vector3.one;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On enable, we start listening to events
|
||||
/// </summary>
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
this.MMEventStartListening<MMFadeEvent>();
|
||||
this.MMEventStartListening<MMFadeStopEvent>();
|
||||
this.MMEventStartListening<MMFadeInEvent>();
|
||||
this.MMEventStartListening<MMFadeOutEvent>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On disable, we stop listening to events
|
||||
/// </summary>
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
this.MMEventStopListening<MMFadeEvent>();
|
||||
this.MMEventStopListening<MMFadeStopEvent>();
|
||||
this.MMEventStopListening<MMFadeInEvent>();
|
||||
this.MMEventStopListening<MMFadeOutEvent>();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Assets/Feel/MMTools/Core/MMUI/MMFaderRound.cs.meta
Normal file
13
Assets/Feel/MMTools/Core/MMUI/MMFaderRound.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2691418b0bcfc540b38b297cf91acf2
|
||||
timeCreated: 1523969902
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1002
Assets/Feel/MMTools/Core/MMUI/MMProgressBar.cs
Normal file
1002
Assets/Feel/MMTools/Core/MMUI/MMProgressBar.cs
Normal file
File diff suppressed because it is too large
Load Diff
13
Assets/Feel/MMTools/Core/MMUI/MMProgressBar.cs.meta
Normal file
13
Assets/Feel/MMTools/Core/MMUI/MMProgressBar.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a42a23ce4f9ed24abde69beacbef2f4
|
||||
timeCreated: 1523894192
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user