Skip to content

Commit

Permalink
change folders
Browse files Browse the repository at this point in the history
change function names
apply targetFolders to BGM
  • Loading branch information
wakepon committed Dec 9, 2020
1 parent 83d84d8 commit 2a0664b
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 29 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions Assets/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
64 changes: 44 additions & 20 deletions Assets/SoundManager.cs → Assets/Scripts/SoundManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections;
using System;
using System.Linq;
using UnityEngine.Serialization;

public class BgmDefine
{
Expand Down Expand Up @@ -149,15 +150,18 @@ public void callCompleteCallback()
private int numChannel = 16;

[SerializeField]
private bool readOnAwake = true;
private bool loadSettingsOnAwake = true;

[SerializeField]
private string[] targetSeFolders = {"SE"};

[SerializeField]
private string[] targetBgmFolders = {"BGM"};

[SerializeField] private SoundVolume volume = new SoundVolume();

public Action ReadFunction;
public Action SaveFunction;
public Action LoadSettingsFunction;
public Action SaveSettingsFunction;

public SoundVolume Volume
{
Expand Down Expand Up @@ -196,8 +200,8 @@ public SoundVolume Volume
//------------------------------------------------------------------------------
protected override void doAwake()
{
ReadFunction = () => DefaultRead();
SaveFunction = () => DefaultSave();
LoadSettingsFunction = () => DefaultLoadSettings();
SaveSettingsFunction = () => DefaultSaveSettings();

bgmSource = gameObject.AddComponent<AudioSource>();
bgmSource.loop = true;
Expand All @@ -217,19 +221,28 @@ protected override void doAwake()
seClips = seClips.Concat(Resources.LoadAll<AudioClip>(path)).ToArray();
}

// check duplications.
var duplicates = seClips.GroupBy(audioClip => audioClip.name)
.Where(name => name.Count() > 1)
.Select(group => group.Key).ToList();
Debug.Assert(duplicates.Count == 0, "Detected duplicated file name(s)!");
Debug.Assert(!checkDuplications(seClips), "Detected duplicated file name(s)!");

#if USE_INTRO_LOOP
introLoopBgms = Resources.LoadAll<IntroloopAudio>("Audio/BGM");
introLoopBgms = new IntroloopAudio[0];
foreach (var folder in targetBgmFolders)
{
var path = "Audio/" + folder;
introLoopBgms = introLoopBgms.Concat(Resources.LoadAll<IntroloopAudio>(path)).ToArray();
}

Debug.Log( "introLoopBgms : " + introLoopBgms.Length );
#else
bgmSource = gameObject.AddComponent<AudioSource>();
bgmSource.loop = true;
bgmClips = Resources.LoadAll<AudioClip>("Audio/BGM");
bgmClips = new AudioClip[0]; // <= Required initialize to use Concat(Linq).
foreach (var folder in targetBgmFolders)
{
var path = "Audio/" + folder;
bgmClips = bgmClips.Concat(Resources.LoadAll<AudioClip>(path)).ToArray();
}

Debug.Assert(!checkDuplications(bgmClips), "Detected duplicated file name(s)!");
#endif

for (int i = 0; i < seClips.Length; ++i)
Expand All @@ -250,7 +263,7 @@ protected override void doAwake()
}
#endif

if (readOnAwake) Read();
if (loadSettingsOnAwake) LoadSettings();

/* Debug.Log("se ========================"); */
/* foreach(var ac in seClips ) { Debug.Log( ac.name ); } */
Expand Down Expand Up @@ -337,25 +350,24 @@ void Update()
//------------------------------------------------------------------------------
public void Save()
{
SaveFunction();
SaveSettingsFunction();
}

public void DefaultSave()
public void DefaultSaveSettings()
{
PlayerPrefs.SetInt(cSaveMuteKey, volume.mute ? 1 : 0);
PlayerPrefs.SetFloat(cSaveSeVolumeKey, volume.se);
PlayerPrefs.SetFloat(cSaveBgmVolumeKey, volume.bgm);
}

//------------------------------------------------------------------------------
public void Read()
public void LoadSettings()
{
ReadFunction();
Debug.Log("se volume : " + volume.se);
Debug.Log("bgm volume : " + volume.bgm);
LoadSettingsFunction();
Debug.Log("bgm volume : " + volume.bgm + ", se volume : " + volume.se);
}

public void DefaultRead()
public void DefaultLoadSettings()
{
volume.mute = PlayerPrefs.GetInt(cSaveMuteKey, 0) == 1;
volume.se = PlayerPrefs.GetFloat(cSaveSeVolumeKey, 1.0f);
Expand Down Expand Up @@ -564,10 +576,22 @@ public AudioSource GetSeAudioSource(Handle handle)
{
return seHandles[handle];
}

//------------------------------------------------------------------------------
private bool checkDuplications(AudioClip[] clips)
{
var duplicates = clips.GroupBy(audioClip => audioClip.name)
.Where(name => name.Count() > 1)
.Select(group => group.Key).ToList();
return duplicates.Count != 0;
}

//------------------------------------------------------------------------------
private IEnumerator DelayMethod(float wait_time, Action action)
{
yield return new WaitForSeconds(wait_time);
action();
}


}
File renamed without changes.
4 changes: 2 additions & 2 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"dependencies": {
"com.unity.collab-proxy": "1.2.16",
"com.unity.ide.rider": "1.1.4",
"com.unity.ide.vscode": "1.2.1",
"com.unity.test-framework": "1.1.14",
"com.unity.ide.vscode": "1.2.3",
"com.unity.test-framework": "1.1.19",
"com.unity.textmeshpro": "2.0.1",
"com.unity.timeline": "1.2.12",
"com.unity.ugui": "1.0.0",
Expand Down
11 changes: 6 additions & 5 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://packages.unity.com"
},
"com.unity.ext.nunit": {
"version": "1.0.0",
"version": "1.0.5",
"depth": 1,
"source": "registry",
"dependencies": {},
Expand All @@ -24,18 +24,18 @@
"url": "https://packages.unity.com"
},
"com.unity.ide.vscode": {
"version": "1.2.1",
"version": "1.2.3",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.test-framework": {
"version": "1.1.14",
"version": "1.1.19",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ext.nunit": "1.0.0",
"com.unity.ext.nunit": "1.0.5",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
},
Expand All @@ -62,7 +62,8 @@
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.ui": "1.0.0"
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.imgui": "1.0.0"
}
},
"com.unity.modules.ai": {
Expand Down
38 changes: 38 additions & 0 deletions ProjectSettings/PackageManagerSettings.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &1
MonoBehaviour:
m_ObjectHideFlags: 61
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 13960, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_EditorClassIdentifier:
m_ScopedRegistriesSettingsExpanded: 1
oneTimeWarningShown: 0
m_Registries:
- m_Id: main
m_Name:
m_Url: https://packages.unity.com
m_Scopes: []
m_IsDefault: 1
m_UserSelectedRegistryName:
m_UserAddingNewScopedRegistry: 0
m_RegistryInfoDraft:
m_ErrorMessage:
m_Original:
m_Id:
m_Name:
m_Url:
m_Scopes: []
m_IsDefault: 0
m_Modified: 0
m_Name:
m_Url:
m_Scopes:
-
m_SelectedScopeIndex: 0
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2019.4.7f1
m_EditorVersionWithRevision: 2019.4.7f1 (e992b1a16e65)
m_EditorVersion: 2019.4.16f1
m_EditorVersionWithRevision: 2019.4.16f1 (e05b6e02d63e)

0 comments on commit 2a0664b

Please sign in to comment.