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_Name: MusicData
|
||||
m_EditorClassIdentifier:
|
||||
_settingsDataPath: /Resources/JSONData/Settings.json
|
||||
startMusic: {fileID: 0}
|
||||
backMusic: {fileID: 0}
|
||||
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();
|
||||
MusicController.Instance.SetMusicData(data.MusicData);
|
||||
controllers.Add(hexGrid);
|
||||
hexGrid.OnHexPainted += DoSomething;
|
||||
|
||||
UIController uiController = new UIController(data.UIData);
|
||||
uiController.Spawn();
|
||||
|
||||
@ -29,7 +29,7 @@ namespace Controller
|
||||
{
|
||||
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);
|
||||
controllers.Add(playerControl);
|
||||
CameraControl cameraControl =
|
||||
@ -54,9 +54,6 @@ namespace Controller
|
||||
hexGrid.OnGridLoaded += unitFactory.Spawn;
|
||||
}
|
||||
|
||||
private void DoSomething(HexCell cell)
|
||||
{
|
||||
Debug.Log("Painted! " + cell.coordinates);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -20,9 +20,9 @@ namespace Data
|
||||
private UIData _uiData;
|
||||
[SerializeField] private string musicDataPath;
|
||||
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
|
||||
{
|
||||
|
@ -1,12 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using MainMenu;
|
||||
using MK.Toon;
|
||||
using UnityEngine;
|
||||
using AudioSettings = MainMenu.AudioSettings;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
[CreateAssetMenu(fileName = "MusicData", menuName = "Data/MusicData", order = 0)]
|
||||
public class MusicData : ScriptableObject
|
||||
{
|
||||
[SerializeField] private string _settingsDataPath;
|
||||
[SerializeField] private AudioClip startMusic;
|
||||
[SerializeField] private AudioClip backMusic;
|
||||
[SerializeField] private SFXMusic sfxMusic;
|
||||
@ -14,13 +19,15 @@ namespace Data
|
||||
public AudioClip StartMusic => startMusic;
|
||||
public AudioClip BackMusic => backMusic;
|
||||
public SFXMusic SfxMusic => sfxMusic;
|
||||
|
||||
public AudioSettings Settings => JsonUtility.FromJson<AudioSettings>(File.ReadAllText(Application.dataPath + _settingsDataPath));
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
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
|
||||
{
|
||||
[Serializable]
|
||||
public class Settings
|
||||
public class AudioSettings
|
||||
{
|
||||
public bool isMusicAllowed;
|
||||
public bool isSFXAllowed;
|
||||
|
||||
public Settings(GameMenuData data)
|
||||
public AudioSettings(GameMenuData data)
|
||||
{
|
||||
isMusicAllowed = data.isMusicAllowed;
|
||||
isSFXAllowed = data.isMusicAllowed;
|
@ -4,6 +4,7 @@ using DG.Tweening;
|
||||
using MainMenu;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using AudioSettings = MainMenu.AudioSettings;
|
||||
|
||||
public class SettingsController : MonoBehaviour
|
||||
{
|
||||
@ -17,7 +18,7 @@ public class SettingsController : MonoBehaviour
|
||||
private bool _isActive = false;
|
||||
private bool _isMusicAllowed = true;
|
||||
private bool _isSFXAllowed = true;
|
||||
private Settings _settings;
|
||||
private AudioSettings _audioSettings;
|
||||
private Vector3 defailtPosition;
|
||||
|
||||
private void Start()
|
||||
@ -25,11 +26,11 @@ public class SettingsController : MonoBehaviour
|
||||
dataFilePath = Application.dataPath + dataFilePath;
|
||||
|
||||
if(File.Exists(dataFilePath))
|
||||
_settings = JsonUtility.FromJson<Settings>(File.ReadAllText(dataFilePath));
|
||||
_audioSettings = JsonUtility.FromJson<AudioSettings>(File.ReadAllText(dataFilePath));
|
||||
else
|
||||
{
|
||||
_settings = new Settings(GameData);
|
||||
File.WriteAllText(dataFilePath, JsonUtility.ToJson(_settings));
|
||||
_audioSettings = new AudioSettings(GameData);
|
||||
File.WriteAllText(dataFilePath, JsonUtility.ToJson(_audioSettings));
|
||||
}
|
||||
|
||||
defailtPosition = transform.position;
|
||||
@ -39,8 +40,8 @@ public class SettingsController : MonoBehaviour
|
||||
|
||||
private void UpdateVisuals()
|
||||
{
|
||||
musImg.sprite = _settings.isMusicAllowed ? musOnSpr : musOffSpr;
|
||||
sfxImg.sprite = _settings.isSFXAllowed ? sfxOnSpr : sfxOffSpr;
|
||||
musImg.sprite = _audioSettings.isMusicAllowed ? musOnSpr : musOffSpr;
|
||||
sfxImg.sprite = _audioSettings.isSFXAllowed ? sfxOnSpr : sfxOffSpr;
|
||||
}
|
||||
|
||||
public void OnSettingsBtnClick()
|
||||
@ -56,22 +57,22 @@ public class SettingsController : MonoBehaviour
|
||||
|
||||
public void OnMusicBtnClick()
|
||||
{
|
||||
_settings.isMusicAllowed = !_settings.isMusicAllowed;
|
||||
musImg.sprite = _settings.isMusicAllowed ? musOnSpr : musOffSpr;
|
||||
_audioSettings.isMusicAllowed = !_audioSettings.isMusicAllowed;
|
||||
musImg.sprite = _audioSettings.isMusicAllowed ? musOnSpr : musOffSpr;
|
||||
SetMenuMusicState();
|
||||
File.WriteAllText(dataFilePath, JsonUtility.ToJson(_settings));
|
||||
File.WriteAllText(dataFilePath, JsonUtility.ToJson(_audioSettings));
|
||||
}
|
||||
|
||||
public void OnSFXBtnClick()
|
||||
{
|
||||
_settings.isSFXAllowed = !_settings.isSFXAllowed;
|
||||
sfxImg.sprite = _settings.isSFXAllowed ? sfxOnSpr : sfxOffSpr;
|
||||
File.WriteAllText(dataFilePath, JsonUtility.ToJson(_settings));
|
||||
_audioSettings.isSFXAllowed = !_audioSettings.isSFXAllowed;
|
||||
sfxImg.sprite = _audioSettings.isSFXAllowed ? sfxOnSpr : sfxOffSpr;
|
||||
File.WriteAllText(dataFilePath, JsonUtility.ToJson(_audioSettings));
|
||||
}
|
||||
|
||||
private void SetMenuMusicState()
|
||||
{
|
||||
if (_settings.isMusicAllowed)
|
||||
if (_audioSettings.isMusicAllowed)
|
||||
{
|
||||
menuMusSRC.Play();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace DefaultNamespace
|
||||
Instance ??= this;
|
||||
_sources = new Dictionary<GameObject, AudioSource>();
|
||||
}
|
||||
|
||||
|
||||
public void SetMusicData(MusicData data)
|
||||
{
|
||||
_data = data;
|
||||
@ -29,6 +29,7 @@ namespace DefaultNamespace
|
||||
public void PlayerAudioClip(AudioClip clip, GameObject source)
|
||||
{
|
||||
_sources[source].clip = clip;
|
||||
_sources[source].volume = _data.Settings.isSFXAllowed ? 1f : 0f;
|
||||
_sources[source].Play();
|
||||
}
|
||||
|
||||
@ -39,10 +40,6 @@ namespace DefaultNamespace
|
||||
|
||||
public void AddAudioSource(GameObject gameObject)
|
||||
{
|
||||
if (_sources.ContainsKey(new GameObject(null)))
|
||||
{
|
||||
_sources.Remove(new GameObject(null));
|
||||
}
|
||||
var source = gameObject.AddComponent<AudioSource>();
|
||||
_sources.Add(gameObject, source);
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Weapons;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
|
||||
public class UnitView : MonoBehaviour
|
||||
{
|
||||
@ -45,8 +47,6 @@ public class UnitView : MonoBehaviour
|
||||
_startRegen = regenMana;
|
||||
_manaRegen = manaRegen;
|
||||
_capureHex = captureHex;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void HardCaptureHex()
|
||||
@ -97,7 +97,9 @@ public class UnitView : MonoBehaviour
|
||||
private void Step()
|
||||
{
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user