Add Custom Enviroment Option (Need to fix Lighting issue))
This commit is contained in:
@@ -20,6 +20,7 @@ public class Config
|
||||
public float HandZ = 0;
|
||||
public float PlayerHeight = 0;
|
||||
public int Skybox = 0;
|
||||
public int Enviroment = 0;
|
||||
public float HapticDuration = 0.1f;
|
||||
public float HapticAmplitude = 0.75f;
|
||||
public int TouchSampleRate = 3;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class ConfigManager : MonoBehaviour
|
||||
void Awake()
|
||||
{
|
||||
onConfigChanged += EnsureInitialization;
|
||||
onConfigChanged += SaveFile;
|
||||
onConfigChanged += SaveFileWait;
|
||||
|
||||
}
|
||||
void Start()
|
||||
@@ -53,7 +53,7 @@ public class ConfigManager : MonoBehaviour
|
||||
{
|
||||
Debug.Log("Config file does not exist");
|
||||
config = new Config();
|
||||
SaveFile();
|
||||
SaveFileWait();
|
||||
Debug.Log("Config file created");
|
||||
}
|
||||
}
|
||||
@@ -61,13 +61,13 @@ public class ConfigManager : MonoBehaviour
|
||||
{
|
||||
return Application.dataPath + "/../config.json";
|
||||
}
|
||||
public static void SaveFile()
|
||||
public static void SaveFileWait()
|
||||
{
|
||||
isSavingConfig = true;
|
||||
saverTimer = 0;
|
||||
//Debug.Log("Saving config file");
|
||||
}
|
||||
public void saveFileWait()
|
||||
public void saveFile()
|
||||
{
|
||||
File.WriteAllText(GetFileName(), JsonConvert.SerializeObject(config, Formatting.Indented));
|
||||
Debug.Log("Config file saved");
|
||||
@@ -82,11 +82,16 @@ public class ConfigManager : MonoBehaviour
|
||||
{
|
||||
isSavingConfig = false;
|
||||
saverTimer = 0;
|
||||
saveFileWait();
|
||||
saveFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
saveFile();
|
||||
}
|
||||
|
||||
public static GameObject GetConfigPanelWidget(string configKeyName)
|
||||
{
|
||||
EnsureInitialization();
|
||||
@@ -123,10 +128,12 @@ public class ConfigManager : MonoBehaviour
|
||||
foreach (var configPanelComponent in _configPanelComponents)
|
||||
{
|
||||
var widget = configPanelComponent.Widget;
|
||||
if (widget.GetComponent<TMP_Dropdown>() != null)
|
||||
var dropdown = widget.GetComponent<TMP_Dropdown>();
|
||||
var toggle = widget.GetComponent<Toggle>();
|
||||
var slider = widget.GetComponent<Slider>();
|
||||
var valueManager = widget.GetComponent<ValueManager>();
|
||||
if (dropdown != null) // add listener to dropdown to update config by key name
|
||||
{
|
||||
var dropdown = widget.GetComponent<TMP_Dropdown>();
|
||||
// add listener to dropdown to update config by key name
|
||||
dropdown.onValueChanged.AddListener((int value) =>
|
||||
{
|
||||
var field = config.GetType().GetField(configPanelComponent.ConfigKeyName);
|
||||
@@ -134,9 +141,8 @@ public class ConfigManager : MonoBehaviour
|
||||
onConfigChanged?.Invoke();
|
||||
});
|
||||
}
|
||||
else if (widget.GetComponent<Toggle>() != null)
|
||||
else if (toggle != null)
|
||||
{
|
||||
var toggle = widget.GetComponent<Toggle>();
|
||||
toggle.onValueChanged.AddListener((bool value) =>
|
||||
{
|
||||
var field = config.GetType().GetField(configPanelComponent.ConfigKeyName);
|
||||
@@ -144,9 +150,8 @@ public class ConfigManager : MonoBehaviour
|
||||
onConfigChanged?.Invoke();
|
||||
});
|
||||
}
|
||||
else if (widget.GetComponent<Slider>() != null)
|
||||
else if (slider != null)
|
||||
{
|
||||
var slider = widget.GetComponent<Slider>();
|
||||
slider.onValueChanged.AddListener((float value) =>
|
||||
{
|
||||
var field = config.GetType().GetField(configPanelComponent.ConfigKeyName);
|
||||
@@ -154,9 +159,8 @@ public class ConfigManager : MonoBehaviour
|
||||
onConfigChanged?.Invoke();
|
||||
});
|
||||
}
|
||||
else if (widget.GetComponent<ValueManager>() != null)
|
||||
else if (valueManager != null)
|
||||
{
|
||||
var valueManager = widget.GetComponent<ValueManager>();
|
||||
valueManager.onValueChanged.AddListener(delegate
|
||||
{
|
||||
var field = config.GetType().GetField(configPanelComponent.ConfigKeyName);
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using System.IO;
|
||||
|
||||
[RequireComponent(typeof(TMP_Dropdown))]
|
||||
public class EnviromentManager : MonoBehaviour
|
||||
{
|
||||
private TMP_Dropdown Dropdown;
|
||||
public bool useEnvironment = true;
|
||||
public Transform EnvironmentParent;
|
||||
public GameObject CurrentEnvironment;
|
||||
|
||||
private string currentEnvironmentName;
|
||||
private List<FileInfo> enviromentFiles = new List<FileInfo>();
|
||||
void Start()
|
||||
{
|
||||
Dropdown = GetComponent<TMP_Dropdown>();
|
||||
AddEnviorments();
|
||||
Dropdown.onValueChanged.AddListener((int value) => {
|
||||
currentEnvironmentName = Dropdown.options[value].text;
|
||||
if (value == 0)
|
||||
useEnvironment = false;
|
||||
else
|
||||
{
|
||||
useEnvironment = true;
|
||||
SetEnvironment();
|
||||
}
|
||||
Debug.Log("Value: " + value);
|
||||
});
|
||||
Dropdown.onValueChanged?.Invoke(Dropdown.value);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (useEnvironment)
|
||||
{
|
||||
CurrentEnvironment.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentEnvironment.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
void AddEnviorments()
|
||||
{
|
||||
Dropdown.options.Clear();
|
||||
Dropdown.options.Add(new TMP_Dropdown.OptionData("None"));
|
||||
|
||||
enviromentFiles = AssetBundleManager.Instance.GetAssetBundleFiles("Enviroments");
|
||||
foreach (var file in enviromentFiles)
|
||||
{
|
||||
Dropdown.options.Add(new TMP_Dropdown.OptionData(file.Name));
|
||||
}
|
||||
}
|
||||
void SetEnvironment()
|
||||
{
|
||||
if (CurrentEnvironment != null)
|
||||
{
|
||||
Destroy(CurrentEnvironment);
|
||||
}
|
||||
GameObject env = AssetBundleManager.Instance.LoadAsset<GameObject>("Enviroments", currentEnvironmentName);
|
||||
CurrentEnvironment = Instantiate(env, EnvironmentParent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8c67c63085e2bf48ba095e6a2b471bf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -23,27 +23,29 @@ public class SkyboxSwitcher : MonoBehaviour
|
||||
private TMP_Dropdown Dropdown;
|
||||
|
||||
void Start()
|
||||
{
|
||||
{
|
||||
Dropdown = GetComponent<TMP_Dropdown>(); // get the dropdown component
|
||||
|
||||
skyboxes.Insert(0, RenderSettings.skybox); // add ubiquitous default skybox (should be current)
|
||||
|
||||
// check StreamingAssets folder for additional skybox textures
|
||||
skyboxPath = Path.Combine(Application.streamingAssetsPath, "SkyboxTextures");
|
||||
StartCoroutine(AddSkyboxes());
|
||||
|
||||
Dropdown = GetComponent<TMP_Dropdown>();
|
||||
Dropdown.onValueChanged.AddListener((int value) => {
|
||||
if (value == 0)
|
||||
Dropdown.value = ConfigManager.config.Skybox; // set the dropdown to the current skybox index
|
||||
Dropdown.onValueChanged.AddListener((int value) => { // add listener to dropdown
|
||||
if (value == 0) // if the first option is selected, disable the room
|
||||
{
|
||||
Room.SetActive(true);
|
||||
}
|
||||
else
|
||||
else // otherwise, enable the room and set the skybox
|
||||
{
|
||||
Room.SetActive(false);
|
||||
currentSkyboxIndex = Dropdown.value;
|
||||
SetSkybox();
|
||||
}
|
||||
});
|
||||
Dropdown.onValueChanged?.Invoke(Dropdown.value);
|
||||
Dropdown.onValueChanged?.Invoke(Dropdown.value); // invoke the listener to set the skybox on startup
|
||||
}
|
||||
|
||||
IEnumerator AddSkyboxes()
|
||||
@@ -76,7 +78,7 @@ public class SkyboxSwitcher : MonoBehaviour
|
||||
skyboxMat.SetTexture("_MainTex", texture);
|
||||
skyboxes.Add(skyboxMat);
|
||||
|
||||
Dropdown.options.Add(new TMP_Dropdown.OptionData(file.Name));
|
||||
Dropdown.options.Add(new TMP_Dropdown.OptionData(file.Name)); // add the skybox option to the dropdown
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +95,6 @@ public class SpectatorManager : MonoBehaviour
|
||||
ConfigManager.config.TPCamRotation[0] = SpectatorTPTarget.rotation.eulerAngles.x;
|
||||
ConfigManager.config.TPCamRotation[1] = SpectatorTPTarget.rotation.eulerAngles.y;
|
||||
ConfigManager.config.TPCamRotation[2] = SpectatorTPTarget.rotation.eulerAngles.z;
|
||||
ConfigManager.SaveFile();
|
||||
ConfigManager.SaveFileWait();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
@@ -7,11 +5,21 @@ using Lavender.Systems;
|
||||
|
||||
public class StartBatchManager : MonoBehaviour
|
||||
{
|
||||
uint pid = 0;
|
||||
private void Start()
|
||||
{
|
||||
ConfigManager.EnsureInitialization();
|
||||
if (ConfigManager.config.batFileLocation != "")
|
||||
StartExternalProcess.Start(ConfigManager.config.batFileLocation);
|
||||
pid = StartExternalProcess.Start(ConfigManager.config.batFileLocation);
|
||||
UnityEngine.Debug.Log("Batch file with PID: " + pid);
|
||||
//Process.Start(Path.GetFullPath(ConfigManager.config.batFileLocation));
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (pid != 0)
|
||||
{
|
||||
StartExternalProcess.KillProcess(pid);
|
||||
UnityEngine.Debug.Log("Batch file with PID: " + pid + " killed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user