Items #3
30
Assets/ChosenWeapon.cs
Normal file
30
Assets/ChosenWeapon.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using Weapons;
|
||||||
|
|
||||||
|
public class ChosenWeapon : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private TMP_Text attackText;
|
||||||
|
[SerializeField] private TMP_Text reloadText;
|
||||||
|
[SerializeField] private string chosenWeaponDataPath;
|
||||||
|
|
||||||
|
private Weapon Weapon =>
|
||||||
|
JsonUtility.FromJson<Weapon>(File.ReadAllText(Application.persistentDataPath + "/" + chosenWeaponDataPath));
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
attackText.text = Weapon.damage.ToString();
|
||||||
|
reloadText.text = Weapon.reloadTime.ToString(CultureInfo.CurrentCulture);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangeChosenWeapon(Weapon weapon)
|
||||||
|
{
|
||||||
|
attackText.text = weapon.damage.ToString();
|
||||||
|
reloadText.text = weapon.reloadTime.ToString(CultureInfo.CurrentCulture);
|
||||||
|
}
|
||||||
|
}
|
11
Assets/ChosenWeapon.cs.meta
Normal file
11
Assets/ChosenWeapon.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a2920b048f18f5946b93c003a602952b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -88770,7 +88770,7 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
menuMusSrc: {fileID: 579284492}
|
menuMusSrc: {fileID: 579284492}
|
||||||
GameData: {fileID: 11400000, guid: 4828646b64dadac47a63b0be91a92517, type: 2}
|
GameData: {fileID: 11400000, guid: 4828646b64dadac47a63b0be91a92517, type: 2}
|
||||||
dataFilePath: AduioSettings
|
dataFilePath: AudioSettings.json
|
||||||
musicSlider: {fileID: 1813936035}
|
musicSlider: {fileID: 1813936035}
|
||||||
sfxSlider: {fileID: 597565998}
|
sfxSlider: {fileID: 597565998}
|
||||||
musicImage: {fileID: 1040137649}
|
musicImage: {fileID: 1040137649}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using DefaultNamespace.Weapons;
|
using DefaultNamespace.Weapons;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Events;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using Weapons;
|
using Weapons;
|
||||||
|
|
||||||
@ -11,6 +13,8 @@ public class WeaponSelection : MonoBehaviour
|
|||||||
[SerializeField] private WeaponIcon weaponIcon;
|
[SerializeField] private WeaponIcon weaponIcon;
|
||||||
[SerializeField] private Transform grid;
|
[SerializeField] private Transform grid;
|
||||||
[SerializeField] private string dataFilePath;
|
[SerializeField] private string dataFilePath;
|
||||||
|
[SerializeField] private ChosenWeapon chosenWeapon;
|
||||||
|
private Action<Weapon> changeStats;
|
||||||
private List<Button> _buttons;
|
private List<Button> _buttons;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
@ -22,6 +26,8 @@ public class WeaponSelection : MonoBehaviour
|
|||||||
using StreamWriter writer = new StreamWriter(stream);
|
using StreamWriter writer = new StreamWriter(stream);
|
||||||
writer.Write(JsonUtility.ToJson(data.WeaponsList[0]));
|
writer.Write(JsonUtility.ToJson(data.WeaponsList[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
changeStats = chosenWeapon.ChangeChosenWeapon;
|
||||||
_buttons = new List<Button>();
|
_buttons = new List<Button>();
|
||||||
data.WeaponsList.ForEach(x =>
|
data.WeaponsList.ForEach(x =>
|
||||||
{
|
{
|
||||||
@ -46,5 +52,6 @@ public class WeaponSelection : MonoBehaviour
|
|||||||
FileStream stream = new FileStream(Application.persistentDataPath + "/" + dataFilePath, FileMode.Create);
|
FileStream stream = new FileStream(Application.persistentDataPath + "/" + dataFilePath, FileMode.Create);
|
||||||
using StreamWriter writer = new StreamWriter(stream);
|
using StreamWriter writer = new StreamWriter(stream);
|
||||||
writer.Write(JsonUtility.ToJson(weapon));
|
writer.Write(JsonUtility.ToJson(weapon));
|
||||||
|
changeStats?.Invoke(weapon);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user