Skip to content

Commit

Permalink
Add ScreenAnimationSpeed parameter to Add<T>. Add some overloading me…
Browse files Browse the repository at this point in the history
…thods of Destroy, Close
  • Loading branch information
AnhPham committed Jan 9, 2025
1 parent c52e2c0 commit bd94e01
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 27 deletions.
56 changes: 40 additions & 16 deletions SSv5/Assets/ThirdParties/SS/Screen/Scripts/ScreenManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public ScreenCoroutine(Coroutine coroutine, string screenName)
[SerializeField] string m_SceneLoadingName;
[SerializeField] string m_LoadingName;
[SerializeField] Color m_ScreenShieldColor = new Color(0, 0, 0, 0.8f);
[SerializeField] float m_ScreenAnimationSpeed = 1;
[SerializeField] Camera m_BackgroundCamera;
[SerializeField] Canvas m_Canvas;
[SerializeField] UnscaledAnimation m_SceneShield;
Expand Down Expand Up @@ -113,9 +114,10 @@ public static AsyncOperation asyncOperation
/// <param name="screenAnimationPath">The path (in Resources folder) of screen's animation clips</param>
/// <param name="sceneLoadingName">The name of the scene loading screen which is put in 'screenPath'. Set it to empty if you do not want to show the loading screen while loading a scene</param>
/// <param name="loadingName">The name of the loading screen which is put in 'screenPath'. This screen can show/hide on the top of all screens at any time using Loading(bool). Set it to empty if you don't need</param>
public static void Set(Color screenShieldColor, string screenPath = "Screens", string screenAnimationPath = "Animations", string sceneLoadingName = "", string loadingName = "")
/// <param name="screenAnimationSpeed">Screen Animation speed</param>
public static void Set(Color screenShieldColor, string screenPath = "Screens", string screenAnimationPath = "Animations", string sceneLoadingName = "", string loadingName = "", float screenAnimationSpeed = 1)
{
instance.Setup(screenShieldColor, screenPath, screenAnimationPath, sceneLoadingName, loadingName);
instance.Setup(screenShieldColor, screenPath, screenAnimationPath, sceneLoadingName, loadingName, screenAnimationSpeed);
}

/// <summary>
Expand All @@ -125,9 +127,10 @@ public static void Set(Color screenShieldColor, string screenPath = "Screens", s
/// <param name="screenAnimationPath">The path (in Resources folder) of screen's animation clips</param>
/// <param name="sceneLoadingName">The name of the scene loading screen which is put in 'screenPath'. Set it to empty if you do not want to show the loading screen while loading a scene</param>
/// <param name="loadingName">The name of the loading screen which is put in 'screenPath'. This screen can show/hide on the top of all screens at any time using Loading(bool). Set it to empty if you don't need</param>
public static void Set(string screenPath = "Screens", string screenAnimationPath = "Animations", string sceneLoadingName = "", string loadingName = "")
/// <param name="screenAnimationSpeed">Screen Animation speed</param>
public static void Set(string screenPath = "Screens", string screenAnimationPath = "Animations", string sceneLoadingName = "", string loadingName = "", float screenAnimationSpeed = 1)
{
instance.Setup(screenPath, screenAnimationPath, sceneLoadingName, loadingName);
instance.Setup(screenPath, screenAnimationPath, sceneLoadingName, loadingName, screenAnimationSpeed);
}

/// <summary>
Expand Down Expand Up @@ -226,6 +229,14 @@ public static void Close(Callback onScreenClosed, ScreenAnimation hideAnimation)
Close(onScreenClosed, hideAnimation.ToString());
}

/// <summary>
/// Close the screen which is at the top of all screens. Use ScreenAnimation enum instead of string for animations
/// </summary>\
public static void Close(ScreenAnimation hideAnimation)
{
Close(null, hideAnimation.ToString());
}

/// <summary>
/// Close a specific screen.
/// </summary>
Expand All @@ -245,6 +256,14 @@ public static void Close(Component screen, Callback onScreenClosed, ScreenAnimat
Close(screen, onScreenClosed, hideAnimation.ToString());
}

/// <summary>
/// Close a specific screen. Use ScreenAnimation enum instead of string for animations
/// </summary>
public static void Close(Component screen, ScreenAnimation hideAnimation)
{
Close(screen, null, hideAnimation.ToString());
}

/// <summary>
/// Show/Hide the loading screen (which has the name 'loadingName') on top of all screens.
/// </summary>
Expand Down Expand Up @@ -381,7 +400,7 @@ public static void ShowShield()
m_Instance.m_ScreenShield.gameObject.SetActive(true);
}

m_Instance.m_ScreenShield.Play("ShieldShow");
m_Instance.m_ScreenShield.Play("ShieldShow", speed: m_Instance.m_ScreenAnimationSpeed);
}
}

Expand All @@ -392,7 +411,7 @@ public static void HideShield()
{
if (m_Instance != null && m_Instance.m_ScreenShield != null)
{
m_Instance.m_ScreenShield.Play("ShieldHide");
m_Instance.m_ScreenShield.Play("ShieldHide", speed: m_Instance.m_ScreenAnimationSpeed);
}
}

Expand Down Expand Up @@ -496,20 +515,25 @@ private void SceneManager_sceneLoaded(Scene scene, LoadSceneMode mode)
#endregion

#region Private Functions
private void Setup(Color screenShieldColor, string screenPath = "Screens", string screenAnimationPath = "Animations", string sceneLoadingName = "", string loadingName = "")
private void Setup(Color screenShieldColor, string screenPath = "Screens", string screenAnimationPath = "Animations", string sceneLoadingName = "", string loadingName = "", float screenAnimationSpeed = 1)
{
m_ScreenShieldColor = screenShieldColor;
Setup(screenPath, screenAnimationPath, sceneLoadingName, loadingName);
Setup(screenPath, screenAnimationPath, sceneLoadingName, loadingName, screenAnimationSpeed);

UpdateScreenShieldColor();
}

private void Setup(string screenPath = "Screens", string screenAnimationPath = "Animations", string sceneLoadingName = "", string loadingName = "")
private void Setup(string screenPath = "Screens", string screenAnimationPath = "Animations", string sceneLoadingName = "", string loadingName = "", float screenAnimationSpeed = 1)
{
m_ScreenPath = screenPath;
m_ScreenAnimationPath = screenAnimationPath;
m_SceneLoadingName = sceneLoadingName;
m_LoadingName = loadingName;

if (screenAnimationSpeed > 0)
{
m_ScreenAnimationSpeed = screenAnimationSpeed;
}
}

private void LoadScene<T>(string sceneName, LoadSceneMode mode = LoadSceneMode.Single, OnSceneLoad<T> onSceneLoaded = null, bool clearAllScreen = true) where T : Component
Expand All @@ -523,9 +547,9 @@ private IEnumerator CoLoadScene<T>(string sceneName, LoadSceneMode mode, OnScene

if (mode == LoadSceneMode.Single)
{
m_SceneShield.Play("ShieldShow");
m_SceneShield.Play("ShieldShow", speed: m_ScreenAnimationSpeed);

yield return new WaitForSecondsRealtime(m_SceneShield.GetLength("ShieldShow"));
yield return new WaitForSecondsRealtime(m_SceneShield.GetLength("ShieldShow") / m_ScreenAnimationSpeed);

if (clearAllScreen)
{
Expand Down Expand Up @@ -573,7 +597,7 @@ private IEnumerator CoLoadScene<T>(string sceneName, LoadSceneMode mode, OnScene

if (mode == LoadSceneMode.Single)
{
m_SceneShield.Play("ShieldHide");
m_SceneShield.Play("ShieldHide", speed: m_ScreenAnimationSpeed);
}

if (mode == LoadSceneMode.Single && !string.IsNullOrEmpty(m_SceneLoadingName))
Expand Down Expand Up @@ -872,7 +896,7 @@ private void ShowScreenShield()
if (!m_ScreenShield.gameObject.activeInHierarchy)
{
m_ScreenShield.gameObject.SetActive(true);
m_ScreenShield.Play("ShieldShow");
m_ScreenShield.Play("ShieldShow", speed: m_ScreenAnimationSpeed);
}
}

Expand All @@ -882,7 +906,7 @@ private void HideScreenShield()
{
m_ScreenShield.Play("ShieldHide", (anim) => {
m_ScreenShield.gameObject.SetActive(false);
});
}, speed: m_ScreenAnimationSpeed);
}
}

Expand Down Expand Up @@ -1012,10 +1036,10 @@ private IEnumerator CoPlayAnimation(Animation anim, string animationName, int de
}

// Play animation
unscaledAnim.Play(animationName);
unscaledAnim.Play(animationName, speed: m_ScreenAnimationSpeed);

// Wait animation
yield return new WaitForSecondsRealtime(anim[animationName].length);
yield return new WaitForSecondsRealtime(anim[animationName].length / m_ScreenAnimationSpeed);

// Turn off screen shield after animation end
m_ScreenShieldTop.SetActive(false);
Expand Down
15 changes: 4 additions & 11 deletions SSv5/Assets/ThirdParties/SS/Screen/Scripts/UnscaledAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class UnscaledAnimation : MonoBehaviour
OnAnimationEndDelegate m_OnAnimationEnd;

float m_AccumTime = 0F;

float m_Speed = 1f;
AnimationState m_CurState;
bool m_IsPlayingAnim = false;
bool m_IsEndAnim = false;
Expand Down Expand Up @@ -47,7 +47,7 @@ public string currentClipName
}
}

public void Play(string clip, OnAnimationEndDelegate onAnimationEnd = null)
public void Play(string clip, OnAnimationEndDelegate onAnimationEnd = null, float speed = 1)
{
m_AccumTime = 0F;
m_CurClipName = clip;
Expand All @@ -59,6 +59,7 @@ public void Play(string clip, OnAnimationEndDelegate onAnimationEnd = null)
m_IsPlayingAnim = true;
m_IsEndAnim = false;
m_OnAnimationEnd = onAnimationEnd;
m_Speed = speed;
}

public void PauseAtBeginning(string animationName)
Expand All @@ -74,14 +75,6 @@ public float GetLength(string animationName)
return Animation[animationName].length;
}

public void SetDuration(string animationName, float duration)
{
if (duration > 0)
{
Animation[animationName].speed = Animation[animationName].length / duration;
}
}

private void Start()
{
if (Animation.playAutomatically)
Expand All @@ -108,7 +101,7 @@ private void Update()
return;
}

m_AccumTime += Time.unscaledDeltaTime * Animation[m_CurClipName].speed;
m_AccumTime += Time.unscaledDeltaTime * m_Speed;
if (m_AccumTime >= m_CurState.length)
{
if (m_CurState.wrapMode == WrapMode.Loop)
Expand Down

0 comments on commit bd94e01

Please sign in to comment.