DESKTOP-DDTRVOR\asus 36fa2e1e12 修改声音
2024-12-26 11:39:49 +08:00

237 lines
5.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundSystem : MonoBehaviour
{
public static SoundSystem ins;
[SerializeField] private AudioSource _audioSource;
[SerializeField] private AudioSource _eventSource;
[SerializeField] private AudioClip mainSound;//主界面音效
[SerializeField] private AudioClip attacking;//战斗过程音效
[SerializeField] private AudioClip openSound;//开店音效
[SerializeField] private AudioClip closeSound;//关店音效
[SerializeField] private AudioClip levelUp;//升级音效
[SerializeField] private AudioClip attack1;//剑攻击
[SerializeField] private AudioClip attack2;//弓箭攻击音效
[SerializeField] private AudioClip attack3;//轻甲攻击音效
[SerializeField] private AudioClip attack4;//重甲攻击音效
[SerializeField] private AudioClip attack5;//长柄攻击音效
[SerializeField] private AudioClip attack6;//飞镖攻击音效
[SerializeField] private AudioClip forge;//锻造成功
[SerializeField] private AudioClip forgingClick;//锻造成功
[SerializeField] private AudioClip eventClip;//点击通用音效
[SerializeField] private AudioClip winClip;//胜利音效
[SerializeField] private AudioClip loseClip;//胜利音效
public bool audioBo = true;
public bool eventBo = true;
public void Init()
{
ins = this;
}
/// <summary>
/// 停止音乐
/// </summary>
public void StopAudioSource()
{
audioBo = !audioBo;
if (audioBo)
{
_audioSource.Play();
}
else
{
_audioSource.Stop();
}
}
/// <summary>
/// 停止音效
/// </summary>
public void EventAudioSource()
{
eventBo = !eventBo;
if (!eventBo)
{
_eventSource.Stop();
}
}
/// <summary>
/// 主界面音效
/// </summary>
public void MainAudio()
{
if (_audioSource.clip==mainSound)
{
return;
}
_audioSource.clip = mainSound;
if (!audioBo)
{
return;
}
_audioSource.Play();
_audioSource.loop = true;
}
/// <summary>
/// 开店音效
/// </summary>
public void OpenAudio()
{
_eventSource.clip = openSound;
if (!audioBo)
{
return;
}
_eventSource.Play();
_eventSource.loop = false;
}
/// <summary>
/// 关店音效
/// </summary>
public void CloseAudio()
{
_eventSource.clip = closeSound;
if (!audioBo)
{
return;
}
_eventSource.Play();
_eventSource.loop = false;
}
/// <summary>
/// 等级提升音效
/// </summary>
public void LevelAudio()
{
_eventSource.clip = levelUp;
if (!audioBo)
{
return;
}
_eventSource.Play();
_eventSource.loop = false;
}
public void Attack1Audio()
{
_eventSource.clip = attack1;
if (!audioBo)
{
return;
}
_eventSource.Play();
_eventSource.loop = false;
}
public void Attack2Audio()
{
_eventSource.clip = attack2;
if (!audioBo)
{
return;
}
_eventSource.Play();
_eventSource.loop = false;
}
public void Attack3Audio()
{
_eventSource.clip = attack3;
if (!audioBo)
{
return;
}
_eventSource.Play();
_eventSource.loop = false;
}
public void Attack4Audio()
{
_eventSource.clip = attack4;
if (!audioBo)
{
return;
}
_eventSource.Play();
_eventSource.loop = false;
}
public void Attack5Audio()
{
_eventSource.clip = attack5;
if (!audioBo)
{
return;
}
_eventSource.Play();
_eventSource.loop = false;
}
public void Attack6Audio()
{
_eventSource.clip = attack6;
if (!audioBo)
{
return;
}
_eventSource.Play();
_eventSource.loop = false;
}
public void ForgeAudio()
{
_eventSource.clip = forge;
if (!audioBo)
{
return;
}
_eventSource.Play();
_eventSource.loop = false;
}
public void ForgingClickAudio()
{
_eventSource.clip = forgingClick;
if (!audioBo)
{
return;
}
_eventSource.Play();
_eventSource.loop = false;
}
public void ButtonEventAudio()
{
_eventSource.clip = eventClip;
if (!audioBo)
{
return;
}
_eventSource.Play();
_eventSource.loop = false;
}
public void AttackAudio()
{
_audioSource.clip = attacking;
if (!audioBo)
{
return;
}
_audioSource.Play();
_audioSource.loop = true;
}
public void WinEventAudio()
{
_eventSource.clip = winClip;
if (!audioBo)
{
return;
}
_eventSource.Play();
_eventSource.loop = false;
}
public void LoseEventAudio()
{
_eventSource.clip = loseClip;
if (!audioBo)
{
return;
}
_eventSource.Play();
_eventSource.loop = false;
}
}