Skip to content

Commit

Permalink
Merge pull request #26 from wolf-org/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
VirtueSky authored Nov 15, 2024
2 parents 8b35818 + 09cd453 commit 835b7c5
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 25 deletions.
32 changes: 14 additions & 18 deletions Module/Audio/Runtime/AudioManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using VirtueSky.Core;
using VirtueSky.DataStorage;
Expand All @@ -16,8 +17,7 @@ public class AudioManager : MonoBehaviour
[SerializeField] private SoundComponent soundComponentPrefab;
private SoundComponent music;

private readonly Dictionary<SoundCache, SoundComponent> dictSfxCache =
new Dictionary<SoundCache, SoundComponent>();
[ReadOnly, SerializeField] private List<SoundComponent> listCacheSfx = new List<SoundComponent>();

private int key = 0;
private const string KEY_MUSIC_VOLUME = "KEY_MUSIC_VOLUME";
Expand Down Expand Up @@ -91,7 +91,8 @@ private SoundCache InternalPlaySfx(SoundData soundData)
sfxComponent.PlayAudioClip(soundData.GetAudioClip(), soundData.loop, soundData.volume * SfxVolume);
if (!soundData.loop) sfxComponent.OnCompleted += OnFinishPlayingAudio;
SoundCache soundCache = GetSoundCache(soundData);
dictSfxCache.Add(soundCache, sfxComponent);
sfxComponent.Key = key;
listCacheSfx.Add(sfxComponent);
return soundCache;
}

Expand All @@ -101,10 +102,6 @@ private void InternalStopSfx(SoundCache soundCache)
var soundComponent = GetSoundComponent(soundCache);
if (soundComponent == null) return;
StopAndCleanAudioComponent(soundComponent);
if (dictSfxCache.ContainsKey(soundCache))
{
dictSfxCache.Remove(soundCache);
}
}


Expand Down Expand Up @@ -133,12 +130,14 @@ private void InternalFinishSfx(SoundCache soundCache)

private void InternalStopAllSfx()
{
foreach (var cache in dictSfxCache)
var listTemp = listCacheSfx.ToList();
for (int i = 0; i < listTemp.Count; i++)
{
StopAndCleanAudioComponent(cache.Value);
StopAndCleanAudioComponent(listTemp[i]);
}

dictSfxCache.Clear();
listCacheSfx.Clear();
listTemp.Clear();
key = 0;
}

Expand Down Expand Up @@ -199,9 +198,9 @@ private void OnMusicVolumeChanged(float volume)

private void OnSfxVolumeChanged(float volume)
{
foreach (var cache in dictSfxCache)
for (var i = 0; i < listCacheSfx.Count; i++)
{
cache.Value.Volume = volume;
listCacheSfx[i].Volume = volume;
}
}

Expand Down Expand Up @@ -229,13 +228,10 @@ void StopAudioMusic(SoundComponent soundComponent)

SoundComponent GetSoundComponent(SoundCache soundCache)
{
if (!dictSfxCache.ContainsKey(soundCache)) return null;
foreach (var cache in dictSfxCache)
if (soundCache == null) return null;
for (var i = 0; i < listCacheSfx.Count; i++)
{
if (cache.Key == soundCache)
{
return cache.Value;
}
if (soundCache.key == listCacheSfx[i].Key) return listCacheSfx[i];
}

return null;
Expand Down
7 changes: 7 additions & 0 deletions Module/Audio/Runtime/SoundComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace VirtueSky.Audio
[EditorIcon("icon_csharp")]
public class SoundComponent : CacheComponent<AudioSource>
{
[ReadOnly, SerializeField] private int key;
public event UnityAction<SoundComponent> OnCompleted;
public event UnityAction<SoundComponent> OnPaused;
public event UnityAction<SoundComponent> OnResumed;
Expand All @@ -26,6 +27,12 @@ public float Volume
set => component.volume = value;
}

public int Key
{
get => key;
set => key = value;
}

private void Awake()
{
component.playOnAwake = false;
Expand Down
2 changes: 1 addition & 1 deletion Module/ControlPanel/ConstantPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class ConstantPackage
{
public const string VersionUnityCommon = "1.4.4";
public const string VersionUnityCommon = "1.4.5";
public const string PackageNameInAppPurchase = "com.unity.purchasing";
public const string MaxVersionInAppPurchase = "4.12.2";
public const string PackageNameNewtonsoftJson = "com.unity.nuget.newtonsoft-json";
Expand Down
2 changes: 1 addition & 1 deletion Module/Misc/Common.SkeletonAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Spine;
using Spine.Unity;
using UnityEngine;
using Wolf.Core;
using VirtueSky.Core;


namespace VirtueSky.Misc
Expand Down
2 changes: 1 addition & 1 deletion Module/Misc/Common.SkeletonGraphic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Spine;
using Spine.Unity;
using UnityEngine;
using Wolf.Core;
using VirtueSky.Core;

namespace VirtueSky.Misc
{
Expand Down
2 changes: 1 addition & 1 deletion Module/Utils/Editor/UnityPackage/Note_Package.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- Version Max Sdk: 8.0.0
- Version Admob Sdk: v9.2.0
- Version Admob Sdk: v9.4.0
- Version IronSource Sdk: v8.4.0
- Version Google Game Play Service: v11.01
Binary file modified Module/Utils/Editor/UnityPackage/google-mobile-ads.unitypackage
Binary file not shown.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
### 1: Download the repo and drop it into folder `Assets`
### 2: Add the line below to `Packages/manifest.json`

for version `1.4.4`
for version `1.4.5`
```csharp
"com.wolf-org.sunflower2":"https://github.com/wolf-org/sunflower_2.git#1.4.4",
"com.wolf-org.sunflower2":"https://github.com/wolf-org/sunflower_2.git#1.4.5",
```

## Includes modules
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.wolf-org.sunflower2",
"displayName": "Sunflower2",
"description": "Core singleton for building Unity games ",
"version": "1.4.4",
"version": "1.4.5",
"unity": "2022.3",
"category": "virtuesky",
"license": "MIT",
Expand Down

0 comments on commit 835b7c5

Please sign in to comment.