forked from cgvr/DeltaVR
Merge branch 'cgvr-master'
This commit is contained in:
8
Assets/_PROJECT/Scripts/Managers.meta
Normal file
8
Assets/_PROJECT/Scripts/Managers.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7db8366967e9da242adbfd3af7e17fcd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
196
Assets/_PROJECT/Scripts/Managers/ConfigManager.cs
Normal file
196
Assets/_PROJECT/Scripts/Managers/ConfigManager.cs
Normal file
@@ -0,0 +1,196 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
public class ConfigManager : MonoBehaviour
|
||||
{
|
||||
public static ConfigManager instance = null;
|
||||
|
||||
[System.Serializable]
|
||||
public class Config
|
||||
{
|
||||
public bool isContinuousLocomotion = false;
|
||||
public float continuousLocomotionSpeed = 3.0f;
|
||||
public float volumeMaster = 0.5f;
|
||||
public float volumeAmbient = 0.5f;
|
||||
public float volumeMusic = 0.5f;
|
||||
public float volumeSFX = 0.5f;
|
||||
public float volumeUI = 0.5f;
|
||||
public float volumeVO = 0.5f;
|
||||
public string trellisUrl = "http://192.168.0.53:7960";
|
||||
public string invokeAiUrl = "http://192.168.0.53:9090";
|
||||
public string invokeAiModelKey = "81d45960-08a0-4b8c-a48b-e7d73b21bfe2";
|
||||
}
|
||||
protected Config currentConfig = new Config();
|
||||
protected string configFileName = "config.json";
|
||||
protected string configFilePath;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (!instance) { instance = this; }
|
||||
else if (instance != this) { Destroy(gameObject); }
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
configFilePath = Directory.GetCurrentDirectory() + "\\" + configFileName;
|
||||
Debug.Log(configFilePath);
|
||||
currentConfig = LoadConfigFromFile();
|
||||
}
|
||||
|
||||
public Config GetConfig()
|
||||
{
|
||||
return currentConfig;
|
||||
}
|
||||
|
||||
|
||||
protected void SaveConfigToFile()
|
||||
{
|
||||
FileStream fileStream;
|
||||
if (!File.Exists(configFilePath))
|
||||
{
|
||||
fileStream = File.Create(configFilePath);
|
||||
fileStream.Close();
|
||||
|
||||
}
|
||||
|
||||
string json = JsonUtility.ToJson(currentConfig, true);
|
||||
File.WriteAllText(configFilePath, json);
|
||||
}
|
||||
|
||||
|
||||
protected Config LoadConfigFromFile()
|
||||
{
|
||||
if (!File.Exists(configFilePath))
|
||||
{
|
||||
CreateDefaultConfigFile(); // File did not exist, try to create an empty file
|
||||
if (!File.Exists(configFilePath))
|
||||
{
|
||||
Debug.LogError("Config file was not found and could not be created: " + configFilePath);
|
||||
return currentConfig;
|
||||
}
|
||||
}
|
||||
Config config = JsonUtility.FromJson<Config>(File.ReadAllText(configFilePath));
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
protected void CreateDefaultConfigFile()
|
||||
{
|
||||
currentConfig = new Config();
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public void RestoreDefaultConfig()
|
||||
{
|
||||
currentConfig = new Config();
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public bool GetIsContinuousLocomotion()
|
||||
{
|
||||
|
||||
return currentConfig.isContinuousLocomotion;
|
||||
}
|
||||
public void SetIsContinuousLocomotion(bool isContinuousLocomotion)
|
||||
{
|
||||
currentConfig.isContinuousLocomotion = isContinuousLocomotion;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public float GetContinuousLocomotionSpeed()
|
||||
{
|
||||
|
||||
return currentConfig.continuousLocomotionSpeed;
|
||||
}
|
||||
public void SetContinuousLocomotionSpeed(float continuousLocomotionSpeed)
|
||||
{
|
||||
currentConfig.continuousLocomotionSpeed = continuousLocomotionSpeed;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public float GetVolumeMaster()
|
||||
{
|
||||
|
||||
return currentConfig.volumeMaster;
|
||||
}
|
||||
public void SetVolumeMaster(float masterVolume)
|
||||
{
|
||||
currentConfig.volumeMaster = masterVolume;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public float GetVolumeAmbient()
|
||||
{
|
||||
|
||||
return currentConfig.volumeAmbient;
|
||||
}
|
||||
public void SetVolumeAmbient(float ambientVolume)
|
||||
{
|
||||
currentConfig.volumeAmbient = ambientVolume;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public float GetVolumeMusic()
|
||||
{
|
||||
|
||||
return currentConfig.volumeMusic;
|
||||
}
|
||||
public void SetVolumeMusic(float musicVolume)
|
||||
{
|
||||
currentConfig.volumeMusic = musicVolume;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public float GetVolumeSFX()
|
||||
{
|
||||
|
||||
return currentConfig.volumeSFX;
|
||||
}
|
||||
public void SetVolumeSFX(float sfxVolume)
|
||||
{
|
||||
currentConfig.volumeSFX = sfxVolume;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public float GetVolumeUI()
|
||||
{
|
||||
|
||||
return currentConfig.volumeUI;
|
||||
}
|
||||
public void SetVolumeUI(float uiVolume)
|
||||
{
|
||||
currentConfig.volumeUI = uiVolume;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public float GetVolumeVO()
|
||||
{
|
||||
|
||||
return currentConfig.volumeVO;
|
||||
}
|
||||
public void SetVolumeVO(float voVolume)
|
||||
{
|
||||
currentConfig.volumeVO = voVolume;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public string GetTrellisUrl()
|
||||
{
|
||||
return currentConfig.trellisUrl;
|
||||
}
|
||||
|
||||
public string GetInvokeAiUrl()
|
||||
{
|
||||
return currentConfig.invokeAiUrl;
|
||||
}
|
||||
|
||||
public string GetInvokeAiModelKey()
|
||||
{
|
||||
return currentConfig.invokeAiModelKey;
|
||||
}
|
||||
}
|
||||
11
Assets/_PROJECT/Scripts/Managers/ConfigManager.cs.meta
Normal file
11
Assets/_PROJECT/Scripts/Managers/ConfigManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7622588c230b4b448152a6dfd6c0588
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user