先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
66 lines
1.3 KiB
C#
66 lines
1.3 KiB
C#
// Crest Ocean System
|
|
|
|
// Copyright 2020 Wave Harmonic Ltd
|
|
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
namespace Crest.Examples
|
|
{
|
|
[RequireComponent(typeof(AudioSource))]
|
|
public class DemoMusic : MonoBehaviour
|
|
{
|
|
[SerializeField] float _stopTime = 175f;
|
|
|
|
public static DemoMusic Instance { get; private set; }
|
|
|
|
AudioSource _src;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance != null)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
|
|
_src = GetComponent<AudioSource>();
|
|
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (_src.time > _stopTime)
|
|
{
|
|
_src.Stop();
|
|
}
|
|
}
|
|
|
|
public void Play()
|
|
{
|
|
_src.Play();
|
|
}
|
|
|
|
public void FadeOut()
|
|
{
|
|
StartCoroutine(FadeOutMusic(_src, 2f));
|
|
}
|
|
|
|
private static IEnumerator FadeOutMusic(AudioSource a, float duration)
|
|
{
|
|
float startVolume = a.volume;
|
|
|
|
while (a.volume > 0f)
|
|
{
|
|
a.volume -= startVolume * Time.deltaTime / duration;
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
Destroy(a.gameObject);
|
|
}
|
|
}
|
|
}
|