"How to save custom class unity" Code Answer's
You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "How to save custom class unity" answered properly. Developers are finding an appropriate answer about How to save custom class unity related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like How to save custom class unity. Enter your desired code related query in the search bar and get every piece of information about C# code related question on How to save custom class unity.
How to save custom class unity
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
[System.Serializable]
public class GameSettings
{
public float AudioVolume = .5f;
}
class AudioSettings : MonoBehaviour
{
private static AudioSettings _instance;
public static AudioSettings Instance { get { return _instance; } }
public GameSettings Gamer_Profile;
public string AppLocation => $"{Application.persistentDataPath}";
public string FileLocation => $"/Settings/";
public string FileName => $"gameSettings.json";
private void Awake()
{
if (_instance != null && _instance != this)
{
Destroy(this.gameObject);
}
else
{
_instance = this;
}
Gamer_Profile = Loadprofile();
}
GameSettings SetData(float audioVol)
{
return new GameSettings
{
AudioVolume = audioVol
};
}
public GameSettings Loadprofile()
{
if (Directory.Exists($"{Application.persistentDataPath}/Settings/"))
{
if (File.Exists($"{Application.persistentDataPath}/Settings/gameSettings.json"))
{
string inputString = File.ReadAllText($"{Application.persistentDataPath}/Settings/gameSettings.json");
return JsonUtility.FromJson<GameSettings>(inputString);
}
}
Directory.CreateDirectory($"{Application.persistentDataPath}/Settings/");
return SetData(0.5f);
}
public void SaveProfile()
{
var outputString = JsonUtility.ToJson(Gamer_Profile);
if (!Directory.Exists($"{Application.persistentDataPath}/PlayerProfile/"))
{
Directory.CreateDirectory($"{Application.persistentDataPath}/PlayerProfile/");
}
File.WriteAllText($"{Application.persistentDataPath}/PlayerProfile/gameSettings.json", outputString);
}
}
//-devbb on twitch
All those coders who are working on the C# based application and are stuck on How to save custom class unity can get a collection of related answers to their query. Programmers need to enter their query on How to save custom class unity related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about How to save custom class unity for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of How to save custom class unity while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "How to save custom class unity". Visit this developer's friendly online web community, CodeProZone, and get your queries like How to save custom class unity resolved professionally and stay updated to the latest C# updates.