数据库设计
创建user表:
创建战绩表:
所有数据设置UN属性,即数据不能为Null,其中userId和totleCount设置默认值为0。
设置result表与user表的关联(设置外键)
声音管理器AudioManager
动态加载声音管理器,首先要在Scene场景里面添加AudioListener
首先创建实例化AudioSource,然后通过它添加AudioClip(动态实例化)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioManager : BaseManager {
//子类调用父类的构造方法
public AudioManager(GameFacade facade) : base(facade) { }
private const string Sound_Prefix = "Sounds/"; //地址前缀
public const string Sound_Alert = "Alert";
public const string Sound_ArrowShoot = "ArrowShoot";
public const string Sound_Bg_fast = "Bg(fast)";
public const string Sound_Bg_moderate = "Bg(moderate)";
public const string Sound_ButtonClick = "ButtonClick";
public const string Sound_Miss = "Miss";
public const string Sound_ShootPerson = "ShootPerson";
public const string Sound_Timer = "Timer";
//定义声音管理器
private AudioSource bgAudioSource;
private AudioSource normalAudioSource;
public override void OnInit()
{
base.OnInit();
GameObject audioSourceGo = new GameObject("AudioSource(GameObject)");
bgAudioSource = audioSourceGo.AddComponent<AudioSource>();
normalAudioSource = audioSourceGo.AddComponent<AudioSource>();
PlaySound(bgAudioSource, LoadSound(Sound_Bg_moderate), 0.5f,true); //加载背景音乐
}
//对外提供的方法
public void PlayBgSound(string soundName)
{
PlaySound(bgAudioSource, LoadSound(soundName), 0.5f, true); //加载背景音乐
}
public void PlayNormalSound(string soundName)
{
PlaySound(normalAudioSource, LoadSound(soundName), 1f, false);
}
private void PlaySound(AudioSource audioSource,AudioClip clip,float volume, bool loop=false)
{
audioSource.volume = volume;
audioSource.clip = clip;
audioSource.loop = loop;
audioSource.Play();
}
/// <summary>
/// 得到实例化的声音片段
/// </summary>
/// <param name="soundsName"></param>
/// <returns></returns>
private AudioClip LoadSound(string soundsName)
{
return Resources.Load<AudioClip>(Sound_Prefix + soundsName);
}
}
//注意:需要在外部添加AudioListener
外部调用:
public void PlayBgSound(string soundName)
{
audioMng.PlayBgSound(soundName);
}
public void PlayNormalSound(string soundName)
{
audioMng.PlayNormalSound(soundName);
}