music control from main menu, minor fixes
This commit is contained in:
parent
16852906d3
commit
d158c8fb37
@ -12,7 +12,11 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: ad850cd32937403f853eb6043fd04112, type: 3}
|
m_Script: {fileID: 11500000, guid: ad850cd32937403f853eb6043fd04112, type: 3}
|
||||||
m_Name: MusicData
|
m_Name: MusicData
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
_settingsDataPath: /Resources/JSONData/Settings.json
|
||||||
startMusic: {fileID: 0}
|
startMusic: {fileID: 0}
|
||||||
backMusic: {fileID: 0}
|
backMusic: {fileID: 0}
|
||||||
sfxMusic:
|
sfxMusic:
|
||||||
_step: {fileID: 8300000, guid: db2b24c43cc41514b85fb4a4950c1299, type: 3}
|
steps:
|
||||||
|
- {fileID: 8300000, guid: db2b24c43cc41514b85fb4a4950c1299, type: 3}
|
||||||
|
- {fileID: 8300000, guid: 14662fc30f12b7847929c0d90295de95, type: 3}
|
||||||
|
- {fileID: 8300000, guid: ed81a29d95a7c6843855e95917ff40ed, type: 3}
|
||||||
|
@ -1 +1 @@
|
|||||||
{"isMusicAllowed":true,"isSFXAllowed":false}
|
{"isMusicAllowed":true,"isSFXAllowed":true}
|
@ -19,7 +19,7 @@ namespace Controller
|
|||||||
new MusicController();
|
new MusicController();
|
||||||
MusicController.Instance.SetMusicData(data.MusicData);
|
MusicController.Instance.SetMusicData(data.MusicData);
|
||||||
controllers.Add(hexGrid);
|
controllers.Add(hexGrid);
|
||||||
hexGrid.OnHexPainted += DoSomething;
|
|
||||||
UIController uiController = new UIController(data.UIData);
|
UIController uiController = new UIController(data.UIData);
|
||||||
uiController.Spawn();
|
uiController.Spawn();
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ namespace Controller
|
|||||||
{
|
{
|
||||||
if (unit.isPlayer)
|
if (unit.isPlayer)
|
||||||
{
|
{
|
||||||
player = new Unit(unit, JsonUtility.FromJson<Weapon>(data.ChosenWeapon.text), hexGrid);
|
player = new Unit(unit, JsonUtility.FromJson<Weapon>(data.ChosenWeapon), hexGrid);
|
||||||
PlayerControl playerControl = new PlayerControl(player, uiController.PlayerControlView);
|
PlayerControl playerControl = new PlayerControl(player, uiController.PlayerControlView);
|
||||||
controllers.Add(playerControl);
|
controllers.Add(playerControl);
|
||||||
CameraControl cameraControl =
|
CameraControl cameraControl =
|
||||||
@ -54,9 +54,6 @@ namespace Controller
|
|||||||
hexGrid.OnGridLoaded += unitFactory.Spawn;
|
hexGrid.OnGridLoaded += unitFactory.Spawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DoSomething(HexCell cell)
|
|
||||||
{
|
|
||||||
Debug.Log("Painted! " + cell.coordinates);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,9 +20,9 @@ namespace Data
|
|||||||
private UIData _uiData;
|
private UIData _uiData;
|
||||||
[SerializeField] private string musicDataPath;
|
[SerializeField] private string musicDataPath;
|
||||||
private MusicData _musicData;
|
private MusicData _musicData;
|
||||||
[SerializeField] private TextAsset chosenWeapon;
|
[SerializeField] private string chosenWeaponDataPath;
|
||||||
|
|
||||||
public TextAsset ChosenWeapon => chosenWeapon;
|
public string ChosenWeapon => File.ReadAllText(Application.dataPath + chosenWeaponDataPath);
|
||||||
|
|
||||||
public MusicData MusicData
|
public MusicData MusicData
|
||||||
{
|
{
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using MainMenu;
|
||||||
using MK.Toon;
|
using MK.Toon;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using AudioSettings = MainMenu.AudioSettings;
|
||||||
|
|
||||||
namespace Data
|
namespace Data
|
||||||
{
|
{
|
||||||
[CreateAssetMenu(fileName = "MusicData", menuName = "Data/MusicData", order = 0)]
|
[CreateAssetMenu(fileName = "MusicData", menuName = "Data/MusicData", order = 0)]
|
||||||
public class MusicData : ScriptableObject
|
public class MusicData : ScriptableObject
|
||||||
{
|
{
|
||||||
|
[SerializeField] private string _settingsDataPath;
|
||||||
[SerializeField] private AudioClip startMusic;
|
[SerializeField] private AudioClip startMusic;
|
||||||
[SerializeField] private AudioClip backMusic;
|
[SerializeField] private AudioClip backMusic;
|
||||||
[SerializeField] private SFXMusic sfxMusic;
|
[SerializeField] private SFXMusic sfxMusic;
|
||||||
@ -14,13 +19,15 @@ namespace Data
|
|||||||
public AudioClip StartMusic => startMusic;
|
public AudioClip StartMusic => startMusic;
|
||||||
public AudioClip BackMusic => backMusic;
|
public AudioClip BackMusic => backMusic;
|
||||||
public SFXMusic SfxMusic => sfxMusic;
|
public SFXMusic SfxMusic => sfxMusic;
|
||||||
|
|
||||||
|
public AudioSettings Settings => JsonUtility.FromJson<AudioSettings>(File.ReadAllText(Application.dataPath + _settingsDataPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public struct SFXMusic
|
public struct SFXMusic
|
||||||
{
|
{
|
||||||
[SerializeField] private AudioClip _step;
|
[SerializeField] private List<AudioClip> steps;
|
||||||
|
|
||||||
public AudioClip Step => _step;
|
public List<AudioClip> Step => steps;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,12 +4,12 @@ using DefaultNamespace;
|
|||||||
namespace MainMenu
|
namespace MainMenu
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class Settings
|
public class AudioSettings
|
||||||
{
|
{
|
||||||
public bool isMusicAllowed;
|
public bool isMusicAllowed;
|
||||||
public bool isSFXAllowed;
|
public bool isSFXAllowed;
|
||||||
|
|
||||||
public Settings(GameMenuData data)
|
public AudioSettings(GameMenuData data)
|
||||||
{
|
{
|
||||||
isMusicAllowed = data.isMusicAllowed;
|
isMusicAllowed = data.isMusicAllowed;
|
||||||
isSFXAllowed = data.isMusicAllowed;
|
isSFXAllowed = data.isMusicAllowed;
|
@ -4,6 +4,7 @@ using DG.Tweening;
|
|||||||
using MainMenu;
|
using MainMenu;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using AudioSettings = MainMenu.AudioSettings;
|
||||||
|
|
||||||
public class SettingsController : MonoBehaviour
|
public class SettingsController : MonoBehaviour
|
||||||
{
|
{
|
||||||
@ -17,7 +18,7 @@ public class SettingsController : MonoBehaviour
|
|||||||
private bool _isActive = false;
|
private bool _isActive = false;
|
||||||
private bool _isMusicAllowed = true;
|
private bool _isMusicAllowed = true;
|
||||||
private bool _isSFXAllowed = true;
|
private bool _isSFXAllowed = true;
|
||||||
private Settings _settings;
|
private AudioSettings _audioSettings;
|
||||||
private Vector3 defailtPosition;
|
private Vector3 defailtPosition;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
@ -25,11 +26,11 @@ public class SettingsController : MonoBehaviour
|
|||||||
dataFilePath = Application.dataPath + dataFilePath;
|
dataFilePath = Application.dataPath + dataFilePath;
|
||||||
|
|
||||||
if(File.Exists(dataFilePath))
|
if(File.Exists(dataFilePath))
|
||||||
_settings = JsonUtility.FromJson<Settings>(File.ReadAllText(dataFilePath));
|
_audioSettings = JsonUtility.FromJson<AudioSettings>(File.ReadAllText(dataFilePath));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_settings = new Settings(GameData);
|
_audioSettings = new AudioSettings(GameData);
|
||||||
File.WriteAllText(dataFilePath, JsonUtility.ToJson(_settings));
|
File.WriteAllText(dataFilePath, JsonUtility.ToJson(_audioSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
defailtPosition = transform.position;
|
defailtPosition = transform.position;
|
||||||
@ -39,8 +40,8 @@ public class SettingsController : MonoBehaviour
|
|||||||
|
|
||||||
private void UpdateVisuals()
|
private void UpdateVisuals()
|
||||||
{
|
{
|
||||||
musImg.sprite = _settings.isMusicAllowed ? musOnSpr : musOffSpr;
|
musImg.sprite = _audioSettings.isMusicAllowed ? musOnSpr : musOffSpr;
|
||||||
sfxImg.sprite = _settings.isSFXAllowed ? sfxOnSpr : sfxOffSpr;
|
sfxImg.sprite = _audioSettings.isSFXAllowed ? sfxOnSpr : sfxOffSpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnSettingsBtnClick()
|
public void OnSettingsBtnClick()
|
||||||
@ -56,22 +57,22 @@ public class SettingsController : MonoBehaviour
|
|||||||
|
|
||||||
public void OnMusicBtnClick()
|
public void OnMusicBtnClick()
|
||||||
{
|
{
|
||||||
_settings.isMusicAllowed = !_settings.isMusicAllowed;
|
_audioSettings.isMusicAllowed = !_audioSettings.isMusicAllowed;
|
||||||
musImg.sprite = _settings.isMusicAllowed ? musOnSpr : musOffSpr;
|
musImg.sprite = _audioSettings.isMusicAllowed ? musOnSpr : musOffSpr;
|
||||||
SetMenuMusicState();
|
SetMenuMusicState();
|
||||||
File.WriteAllText(dataFilePath, JsonUtility.ToJson(_settings));
|
File.WriteAllText(dataFilePath, JsonUtility.ToJson(_audioSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnSFXBtnClick()
|
public void OnSFXBtnClick()
|
||||||
{
|
{
|
||||||
_settings.isSFXAllowed = !_settings.isSFXAllowed;
|
_audioSettings.isSFXAllowed = !_audioSettings.isSFXAllowed;
|
||||||
sfxImg.sprite = _settings.isSFXAllowed ? sfxOnSpr : sfxOffSpr;
|
sfxImg.sprite = _audioSettings.isSFXAllowed ? sfxOnSpr : sfxOffSpr;
|
||||||
File.WriteAllText(dataFilePath, JsonUtility.ToJson(_settings));
|
File.WriteAllText(dataFilePath, JsonUtility.ToJson(_audioSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetMenuMusicState()
|
private void SetMenuMusicState()
|
||||||
{
|
{
|
||||||
if (_settings.isMusicAllowed)
|
if (_audioSettings.isMusicAllowed)
|
||||||
{
|
{
|
||||||
menuMusSRC.Play();
|
menuMusSRC.Play();
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ namespace DefaultNamespace
|
|||||||
public void PlayerAudioClip(AudioClip clip, GameObject source)
|
public void PlayerAudioClip(AudioClip clip, GameObject source)
|
||||||
{
|
{
|
||||||
_sources[source].clip = clip;
|
_sources[source].clip = clip;
|
||||||
|
_sources[source].volume = _data.Settings.isSFXAllowed ? 1f : 0f;
|
||||||
_sources[source].Play();
|
_sources[source].Play();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,10 +40,6 @@ namespace DefaultNamespace
|
|||||||
|
|
||||||
public void AddAudioSource(GameObject gameObject)
|
public void AddAudioSource(GameObject gameObject)
|
||||||
{
|
{
|
||||||
if (_sources.ContainsKey(new GameObject(null)))
|
|
||||||
{
|
|
||||||
_sources.Remove(new GameObject(null));
|
|
||||||
}
|
|
||||||
var source = gameObject.AddComponent<AudioSource>();
|
var source = gameObject.AddComponent<AudioSource>();
|
||||||
_sources.Add(gameObject, source);
|
_sources.Add(gameObject, source);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ using TMPro;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using Weapons;
|
using Weapons;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
|
|
||||||
public class UnitView : MonoBehaviour
|
public class UnitView : MonoBehaviour
|
||||||
{
|
{
|
||||||
@ -45,8 +47,6 @@ public class UnitView : MonoBehaviour
|
|||||||
_startRegen = regenMana;
|
_startRegen = regenMana;
|
||||||
_manaRegen = manaRegen;
|
_manaRegen = manaRegen;
|
||||||
_capureHex = captureHex;
|
_capureHex = captureHex;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HardCaptureHex()
|
public void HardCaptureHex()
|
||||||
@ -97,7 +97,9 @@ public class UnitView : MonoBehaviour
|
|||||||
private void Step()
|
private void Step()
|
||||||
{
|
{
|
||||||
OnStep?.Invoke();
|
OnStep?.Invoke();
|
||||||
MusicController.Instance.PlayerAudioClip(MusicController.Instance.MusicData.SfxMusic.Step, gameObject);
|
MusicController.Instance.PlayerAudioClip(
|
||||||
|
MusicController.Instance.MusicData.SfxMusic.Step[
|
||||||
|
Random.Range(0, MusicController.Instance.MusicData.SfxMusic.Step.Count - 1)], gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AttackEnd()
|
private void AttackEnd()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user