API
This commit is contained in:
1
Assets/Old/Pong/obj/xdoc/cache/final/1012460391
vendored
Normal file
1
Assets/Old/Pong/obj/xdoc/cache/final/1012460391
vendored
Normal file
File diff suppressed because one or more lines are too long
1
Assets/Old/Pong/obj/xdoc/cache/final/878574385
vendored
Normal file
1
Assets/Old/Pong/obj/xdoc/cache/final/878574385
vendored
Normal file
File diff suppressed because one or more lines are too long
2
Assets/Old/Pong/obj/xdoc/cache/obj/.inter
vendored
2
Assets/Old/Pong/obj/xdoc/cache/obj/.inter
vendored
File diff suppressed because one or more lines are too long
11844
Assets/Old/Pong/obj/xdoc/cache/obj/naxaga1g.gz0
vendored
Normal file
11844
Assets/Old/Pong/obj/xdoc/cache/obj/naxaga1g.gz0
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,101 +1,172 @@
|
||||
using System.Collections;
|
||||
using NUnit.Framework.Constraints;
|
||||
using UnityEngine; using Game; using Music; using Player;
|
||||
using UnityEngine;
|
||||
using Game;
|
||||
using Music;
|
||||
using Player;
|
||||
|
||||
namespace Game{
|
||||
public class DayNightCycle : MonoBehaviour
|
||||
namespace Game
|
||||
{
|
||||
public SpriteRenderer daySky, eveningSky, nightSky;
|
||||
public SpriteRenderer dayBackClouds, eveningBackClouds, nightBackClouds;
|
||||
public SpriteRenderer dayFrontClouds, eveningFrontClouds, nightFrontClouds;
|
||||
|
||||
public float transitionDuration = 5f; // Duration of transition
|
||||
public float cycleDuration = 60f; // Time before transitioning to next phase
|
||||
|
||||
private void Start()
|
||||
/// <summary>
|
||||
/// Manages the day-night cycle by transitioning between different sky and cloud sprites.
|
||||
/// </summary>
|
||||
public class DayNightCycle : MonoBehaviour
|
||||
{
|
||||
// Set initial alpha (only day visible)
|
||||
SetAlpha(daySky, 1);
|
||||
SetAlpha(eveningSky, 0);
|
||||
SetAlpha(nightSky, 0);
|
||||
/// <summary>
|
||||
/// Sprite representing the sky during the day.
|
||||
/// </summary>
|
||||
public SpriteRenderer daySky;
|
||||
|
||||
SetAlpha(dayBackClouds, 1);
|
||||
SetAlpha(eveningBackClouds, 0);
|
||||
SetAlpha(nightBackClouds, 0);
|
||||
/// <summary>
|
||||
/// Sprite representing the sky during the evening.
|
||||
/// </summary>
|
||||
public SpriteRenderer eveningSky;
|
||||
|
||||
SetAlpha(dayFrontClouds, 1);
|
||||
SetAlpha(eveningFrontClouds, 0);
|
||||
SetAlpha(nightFrontClouds, 0);
|
||||
/// <summary>
|
||||
/// Sprite representing the sky during the night.
|
||||
/// </summary>
|
||||
public SpriteRenderer nightSky;
|
||||
|
||||
// Start the cycle
|
||||
StartCoroutine(DayNightCycleRoutine());
|
||||
}
|
||||
/// <summary>
|
||||
/// Sprite representing the back clouds during the day.
|
||||
/// </summary>
|
||||
public SpriteRenderer dayBackClouds;
|
||||
|
||||
private IEnumerator DayNightCycleRoutine()
|
||||
{
|
||||
while (true)
|
||||
/// <summary>
|
||||
/// Sprite representing the back clouds during the evening.
|
||||
/// </summary>
|
||||
public SpriteRenderer eveningBackClouds;
|
||||
|
||||
/// <summary>
|
||||
/// Sprite representing the back clouds during the night.
|
||||
/// </summary>
|
||||
public SpriteRenderer nightBackClouds;
|
||||
|
||||
/// <summary>
|
||||
/// Sprite representing the front clouds during the day.
|
||||
/// </summary>
|
||||
public SpriteRenderer dayFrontClouds;
|
||||
|
||||
/// <summary>
|
||||
/// Sprite representing the front clouds during the evening.
|
||||
/// </summary>
|
||||
public SpriteRenderer eveningFrontClouds;
|
||||
|
||||
/// <summary>
|
||||
/// Sprite representing the front clouds during the night.
|
||||
/// </summary>
|
||||
public SpriteRenderer nightFrontClouds;
|
||||
|
||||
/// <summary>
|
||||
/// Duration of the transition between different phases of the day-night cycle.
|
||||
/// </summary>
|
||||
public float transitionDuration = 5f;
|
||||
|
||||
/// <summary>
|
||||
/// Duration of each phase (day, evening, night) before transitioning to the next phase.
|
||||
/// </summary>
|
||||
public float cycleDuration = 60f;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the day-night cycle by setting the initial alpha values and starting the cycle routine.
|
||||
/// </summary>
|
||||
private void Start()
|
||||
{
|
||||
yield return new WaitForSeconds(cycleDuration);
|
||||
yield return StartCoroutine(FadeTransition(
|
||||
new SpriteRenderer[] { daySky, dayBackClouds, dayFrontClouds },
|
||||
new SpriteRenderer[] { eveningSky, eveningBackClouds, eveningFrontClouds },
|
||||
transitionDuration));
|
||||
// Set initial alpha (only day visible)
|
||||
SetAlpha(daySky, 1);
|
||||
SetAlpha(eveningSky, 0);
|
||||
SetAlpha(nightSky, 0);
|
||||
|
||||
yield return new WaitForSeconds(cycleDuration);
|
||||
yield return StartCoroutine(FadeTransition(
|
||||
new SpriteRenderer[] { eveningSky, eveningBackClouds, eveningFrontClouds },
|
||||
new SpriteRenderer[] { nightSky, nightBackClouds, nightFrontClouds },
|
||||
transitionDuration));
|
||||
SetAlpha(dayBackClouds, 1);
|
||||
SetAlpha(eveningBackClouds, 0);
|
||||
SetAlpha(nightBackClouds, 0);
|
||||
|
||||
yield return new WaitForSeconds(cycleDuration);
|
||||
yield return StartCoroutine(FadeTransition(
|
||||
new SpriteRenderer[] { nightSky, nightBackClouds, nightFrontClouds },
|
||||
new SpriteRenderer[] { daySky, dayBackClouds, dayFrontClouds },
|
||||
transitionDuration));
|
||||
SetAlpha(dayFrontClouds, 1);
|
||||
SetAlpha(eveningFrontClouds, 0);
|
||||
SetAlpha(nightFrontClouds, 0);
|
||||
|
||||
// Start the cycle
|
||||
StartCoroutine(DayNightCycleRoutine());
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator FadeTransition(SpriteRenderer[] from, SpriteRenderer[] to, float duration)
|
||||
{
|
||||
float elapsedTime = 0;
|
||||
while (elapsedTime < duration)
|
||||
/// <summary>
|
||||
/// Coroutine that manages the day-night cycle by transitioning between phases in a loop.
|
||||
/// </summary>
|
||||
private IEnumerator DayNightCycleRoutine()
|
||||
{
|
||||
elapsedTime += Time.deltaTime;
|
||||
float alpha = elapsedTime / duration;
|
||||
|
||||
// Apply fading to all elements simultaneously
|
||||
for (int i = 0; i < from.Length; i++)
|
||||
while (true)
|
||||
{
|
||||
SetAlpha(from[i], 1 - alpha);
|
||||
SetAlpha(to[i], alpha);
|
||||
yield return new WaitForSeconds(cycleDuration);
|
||||
yield return StartCoroutine(FadeTransition(
|
||||
new SpriteRenderer[] { daySky, dayBackClouds, dayFrontClouds },
|
||||
new SpriteRenderer[] { eveningSky, eveningBackClouds, eveningFrontClouds },
|
||||
transitionDuration));
|
||||
|
||||
yield return new WaitForSeconds(cycleDuration);
|
||||
yield return StartCoroutine(FadeTransition(
|
||||
new SpriteRenderer[] { eveningSky, eveningBackClouds, eveningFrontClouds },
|
||||
new SpriteRenderer[] { nightSky, nightBackClouds, nightFrontClouds },
|
||||
transitionDuration));
|
||||
|
||||
yield return new WaitForSeconds(cycleDuration);
|
||||
yield return StartCoroutine(FadeTransition(
|
||||
new SpriteRenderer[] { nightSky, nightBackClouds, nightFrontClouds },
|
||||
new SpriteRenderer[] { daySky, dayBackClouds, dayFrontClouds },
|
||||
transitionDuration));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Coroutine that handles the fade transition between two sets of sprites over a specified duration.
|
||||
/// </summary>
|
||||
/// <param name="from">Array of sprites to fade out.</param>
|
||||
/// <param name="to">Array of sprites to fade in.</param>
|
||||
/// <param name="duration">Duration of the fade transition.</param>
|
||||
private IEnumerator FadeTransition(SpriteRenderer[] from, SpriteRenderer[] to, float duration)
|
||||
{
|
||||
float elapsedTime = 0;
|
||||
while (elapsedTime < duration)
|
||||
{
|
||||
elapsedTime += Time.deltaTime;
|
||||
float alpha = elapsedTime / duration;
|
||||
|
||||
// Apply fading to all elements simultaneously
|
||||
for (int i = 0; i < from.Length; i++)
|
||||
{
|
||||
SetAlpha(from[i], 1 - alpha);
|
||||
SetAlpha(to[i], alpha);
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// Ensure final alpha values are set correctly
|
||||
for (int i = 0; i < from.Length; i++)
|
||||
{
|
||||
SetAlpha(from[i], 0);
|
||||
SetAlpha(to[i], 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetAlpha(SpriteRenderer sprite, float alpha)
|
||||
{
|
||||
if (sprite)
|
||||
{
|
||||
Color color = sprite.color;
|
||||
color.a = alpha;
|
||||
sprite.color = color;
|
||||
foreach (Transform child in sprite.transform)
|
||||
// Ensure final alpha values are set correctly
|
||||
for (int i = 0; i < from.Length; i++)
|
||||
{
|
||||
if (child.TryGetComponent(out SpriteRenderer childSprite))
|
||||
SetAlpha(from[i], 0);
|
||||
SetAlpha(to[i], 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the alpha value of a sprite and its child sprites (if any).
|
||||
/// </summary>
|
||||
/// <param name="sprite">The sprite renderer to modify.</param>
|
||||
/// <param name="alpha">The alpha value to set (0 to 1).</param>
|
||||
private void SetAlpha(SpriteRenderer sprite, float alpha)
|
||||
{
|
||||
if (sprite)
|
||||
{
|
||||
Color color = sprite.color;
|
||||
color.a = alpha;
|
||||
sprite.color = color;
|
||||
foreach (Transform child in sprite.transform)
|
||||
{
|
||||
childSprite.color = color;
|
||||
if (child.TryGetComponent(out SpriteRenderer childSprite))
|
||||
{
|
||||
childSprite.color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user