Feat - Add Loading menju
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ashwild.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Authoring container for the rotating quotes shown on the loading screen. A logic-free data
|
||||
/// asset (mirrors MusicPlaylist): create one via Assets ▸ Create ▸ UI ▸ Loading Quotes, fill the
|
||||
/// list in the inspector, and assign it to the LoadingScreen. Keeping the quotes here lets us add
|
||||
/// or reword lines without touching code, and lets the loading screen pick from them at random.
|
||||
/// </summary>
|
||||
[CreateAssetMenu(fileName = "LoadingQuotes", menuName = "UI/Loading Quotes")]
|
||||
public class LoadingQuotes : ScriptableObject
|
||||
{
|
||||
#region Types
|
||||
|
||||
/// <summary>
|
||||
/// A single line shown on the loading screen: the quote itself plus an optional author shown
|
||||
/// underneath. Leave the author empty for anonymous lines or plain loading tips.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public struct Quote
|
||||
{
|
||||
[TextArea] public string text;
|
||||
public string author;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Serialized Fields
|
||||
|
||||
[Header("Quotes")]
|
||||
[Tooltip("The pool of quotes the loading screen cycles through at random.")]
|
||||
[SerializeField] private Quote[] quotes;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public API
|
||||
|
||||
/// <summary>
|
||||
/// True when at least one quote is authored — guards the loading screen against an empty asset.
|
||||
/// </summary>
|
||||
public bool HasQuotes => quotes != null && quotes.Length > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Number of authored quotes.
|
||||
/// </summary>
|
||||
public int Count => quotes != null ? quotes.Length : 0;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a random quote while avoiding the one at <paramref name="avoidIndex"/> so the same
|
||||
/// line never shows twice in a row (unless there is only one quote). Outputs the chosen index
|
||||
/// so the caller can feed it back in on the next call.
|
||||
/// </summary>
|
||||
public Quote GetRandom(int avoidIndex, out int chosenIndex)
|
||||
{
|
||||
if (!HasQuotes)
|
||||
{
|
||||
chosenIndex = -1;
|
||||
return default;
|
||||
}
|
||||
|
||||
if (quotes.Length == 1)
|
||||
{
|
||||
chosenIndex = 0;
|
||||
return quotes[0];
|
||||
}
|
||||
|
||||
int index = Random.Range(0, quotes.Length);
|
||||
if (index == avoidIndex)
|
||||
index = (index + 1) % quotes.Length;
|
||||
|
||||
chosenIndex = index;
|
||||
return quotes[index];
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user