From 05f52c38a2a2952a3de8288ec66d8f9a4121a40c Mon Sep 17 00:00:00 2001 From: FizzyApple12 Date: Fri, 3 Jun 2022 23:24:17 -0400 Subject: [PATCH] added a json configuration file and uWindowCapture configuration --- .gitignore | 6 + Assets/Scenes/WACVR.unity | 13 +++ Assets/Script/Configuration.meta | 8 ++ .../Script/Configuration/JsonConfiguration.cs | 107 ++++++++++++++++++ .../Configuration/JsonConfiguration.cs.meta | 11 ++ Assets/Script/HeightAdjuster.cs | 4 +- Assets/Script/PanelThirdPersonButton.cs | 6 +- Assets/Script/SkyboxSwitcher.cs | 15 ++- Assets/Script/UwcConfigurator.cs | 30 +++++ Assets/Script/UwcConfigurator.cs.meta | 11 ++ ProjectSettings/ProjectSettings.asset | 2 + README.md | 19 ++++ 12 files changed, 226 insertions(+), 6 deletions(-) create mode 100644 Assets/Script/Configuration.meta create mode 100644 Assets/Script/Configuration/JsonConfiguration.cs create mode 100644 Assets/Script/Configuration/JsonConfiguration.cs.meta create mode 100644 Assets/Script/UwcConfigurator.cs create mode 100644 Assets/Script/UwcConfigurator.cs.meta diff --git a/.gitignore b/.gitignore index 67b221e..9efdfe4 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,9 @@ crashlytics-build.properties # WACVR-specific uWindowCapture.log + +# Visual Studio Code cache directory +.vscode/ + +# Game configuration file +config.json \ No newline at end of file diff --git a/Assets/Scenes/WACVR.unity b/Assets/Scenes/WACVR.unity index 9e1b597..1ec2ac9 100644 --- a/Assets/Scenes/WACVR.unity +++ b/Assets/Scenes/WACVR.unity @@ -19642,6 +19642,7 @@ GameObject: - component: {fileID: 4876933052092147598} - component: {fileID: 1305037035229797219} - component: {fileID: 1908947391} + - component: {fileID: 4931218028133408142} m_Layer: 0 m_Name: Plane m_TagString: Untagged @@ -26242,6 +26243,18 @@ Transform: m_Father: {fileID: 543450651832966738} m_RootOrder: 240 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &4931218028133408142 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2193423312523191491} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0ca064e37a912ac49a2b617a99d67189, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!23 &4939662662149421075 MeshRenderer: m_ObjectHideFlags: 0 diff --git a/Assets/Script/Configuration.meta b/Assets/Script/Configuration.meta new file mode 100644 index 0000000..5d2ba5f --- /dev/null +++ b/Assets/Script/Configuration.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0de9bd717f0719141be868c495dcf805 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Script/Configuration/JsonConfiguration.cs b/Assets/Script/Configuration/JsonConfiguration.cs new file mode 100644 index 0000000..40b7c17 --- /dev/null +++ b/Assets/Script/Configuration/JsonConfiguration.cs @@ -0,0 +1,107 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System.IO; + +public static class JsonConfiguration { + private static bool hasInitialized = false; + private static JObject config; + + private static void ensureInitialization() { + if (hasInitialized) return; + + loadFile(); + + hasInitialized = true; + } + + private static string getFileName() { + return Application.dataPath + "/../config.json"; + } + + private static void saveFile() { + File.WriteAllText(getFileName(), config.ToString()); + } + + private static void loadFile() { + if (File.Exists(getFileName())) + config = JObject.Parse(File.ReadAllText(getFileName())); + else { + config = new JObject(); + saveFile(); + } + } + + public static void DeleteAll() { + ensureInitialization(); + + config.RemoveAll(); + + saveFile(); + } + public static void DeleteKey(string key) { + ensureInitialization(); + + config.Remove(key); + + saveFile(); + } + + public static bool HasKey(string key) { + ensureInitialization(); + + return config.ContainsKey(key); + } + + public static void SetBoolean(string key, bool boolean) { + ensureInitialization(); + + config[key] = boolean; + + saveFile(); + } + public static void SetString(string key, string text) { + ensureInitialization(); + + config[key] = text; + + saveFile(); + } + public static void SetInt(string key, int number) { + ensureInitialization(); + + config[key] = number; + + saveFile(); + } + public static void SetDouble(string key, double number) { + ensureInitialization(); + + config[key] = number; + + saveFile(); + } + + public static bool GetBoolean(string key) { + ensureInitialization(); + + return config.Value(key); + } + public static string GetString(string key) { + ensureInitialization(); + + return config.Value(key); + } + public static int GetInt(string key) { + ensureInitialization(); + + return config.Value(key); + } + public static double GetDouble(string key) { + ensureInitialization(); + + return config.Value(key); + } +} diff --git a/Assets/Script/Configuration/JsonConfiguration.cs.meta b/Assets/Script/Configuration/JsonConfiguration.cs.meta new file mode 100644 index 0000000..425e0dd --- /dev/null +++ b/Assets/Script/Configuration/JsonConfiguration.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1ac3a0e2569fb414f987646d98807ef9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Script/HeightAdjuster.cs b/Assets/Script/HeightAdjuster.cs index 54400c8..e684a71 100644 --- a/Assets/Script/HeightAdjuster.cs +++ b/Assets/Script/HeightAdjuster.cs @@ -37,7 +37,7 @@ public class HeightAdjuster : MonoBehaviour void Start() { - if (PlayerPrefs.HasKey("Height")) height = PlayerPrefs.GetFloat("Height"); + if (JsonConfiguration.HasKey("Height")) height = JsonConfiguration.GetDouble("Height"); else SaveHeight(); incrementButton.ButtonPressed += StartIncrementing; @@ -82,6 +82,6 @@ public class HeightAdjuster : MonoBehaviour } private void SaveHeight() { - PlayerPrefs.SetFloat("Height", (float) height); + JsonConfiguration.SetDouble("Height", height); } } diff --git a/Assets/Script/PanelThirdPersonButton.cs b/Assets/Script/PanelThirdPersonButton.cs index 39c0efc..fad0208 100644 --- a/Assets/Script/PanelThirdPersonButton.cs +++ b/Assets/Script/PanelThirdPersonButton.cs @@ -13,10 +13,10 @@ public class PanelThirdPersonButton : MonoBehaviour void Start() { - cr = GetComponent(); - SetTP(isTP); + if (JsonConfiguration.HasKey("ThirdPerson")) SetTP(JsonConfiguration.GetBoolean("ThirdPerson")); + else SetTP(isTP); } private void OnTriggerEnter(Collider other) @@ -31,5 +31,7 @@ public class PanelThirdPersonButton : MonoBehaviour isTP = state; cr.material.color = state ? Color.green : Color.red; tpCamera?.SetActive(state); + + JsonConfiguration.SetBoolean("ThirdPerson", state); } } diff --git a/Assets/Script/SkyboxSwitcher.cs b/Assets/Script/SkyboxSwitcher.cs index 5b96d19..1b1014b 100644 --- a/Assets/Script/SkyboxSwitcher.cs +++ b/Assets/Script/SkyboxSwitcher.cs @@ -16,7 +16,7 @@ public class SkyboxSwitcher : MonoBehaviour [SerializeField] private List skyboxes; [SerializeField] - private int currentSkyboxIndex; // should start at 0 + private int currentSkyboxIndex = 0; [Header("Components")] [SerializeField] @@ -28,6 +28,9 @@ public class SkyboxSwitcher : MonoBehaviour void Start() { + if (JsonConfiguration.HasKey("Skybox")) currentSkyboxIndex = JsonConfiguration.GetInt("Skybox"); + else SaveSkyboxIndex(); + incrementBtn.ButtonPressed += IncrementEvent; decrementBtn.ButtonPressed += DecrementEvent; @@ -71,6 +74,8 @@ public class SkyboxSwitcher : MonoBehaviour } } } + + SetSkybox(); //foreach (var file in hdrFiles) // HDR files -- no way to use by scripting? //{ // var uwr = UnityWebRequest.Get(file.ToString()); @@ -119,7 +124,13 @@ public class SkyboxSwitcher : MonoBehaviour private void SetSkybox() { counterTxt.text = (currentSkyboxIndex + 1).ToString(); - if (skyboxes[currentSkyboxIndex] != null) + if (currentSkyboxIndex < skyboxes.Count && skyboxes[currentSkyboxIndex] != null) RenderSettings.skybox = skyboxes[currentSkyboxIndex]; + SaveSkyboxIndex(); + } + + private void SaveSkyboxIndex() + { + JsonConfiguration.SetInt("Skybox", currentSkyboxIndex); } } diff --git a/Assets/Script/UwcConfigurator.cs b/Assets/Script/UwcConfigurator.cs new file mode 100644 index 0000000..22d3f96 --- /dev/null +++ b/Assets/Script/UwcConfigurator.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System.IO; +using System.Runtime.InteropServices; +using System; +using uWindowCapture; + +public class UwcConfigurator : MonoBehaviour { + private UwcWindowTexture uwcWindowTexture; + + void Start() { + uwcWindowTexture = GetComponent(); + + if (JsonConfiguration.HasKey("CaptureMode")) { + int rawCaptureMode = JsonConfiguration.GetInt("CaptureMode"); + + if (rawCaptureMode > 3 || rawCaptureMode < 0) { + JsonConfiguration.SetInt("CaptureMode", (int) uwcWindowTexture.captureMode); + } else + uwcWindowTexture.captureMode = (CaptureMode) JsonConfiguration.GetInt("CaptureMode"); + } else + JsonConfiguration.SetInt("CaptureMode", (int) uwcWindowTexture.captureMode); + + if (JsonConfiguration.HasKey("CaptureFramerate")) + uwcWindowTexture.captureFrameRate = JsonConfiguration.GetInt("CaptureFramerate"); + else + JsonConfiguration.SetInt("CaptureFramerate", uwcWindowTexture.captureFrameRate); + } +} diff --git a/Assets/Script/UwcConfigurator.cs.meta b/Assets/Script/UwcConfigurator.cs.meta new file mode 100644 index 0000000..a2617fe --- /dev/null +++ b/Assets/Script/UwcConfigurator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0ca064e37a912ac49a2b617a99d67189 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 9f3b190..28e8e60 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -137,6 +137,8 @@ PlayerSettings: bundleVersion: 0.1.1 preloadedAssets: - {fileID: 11400000, guid: 74eeb7429f216ca45a7093c586513e98, type: 2} + - {fileID: -6265376527240436808, guid: 5e2dc0db42cc5b3459a781fecb0b76f9, type: 2} + - {fileID: -6348321304186183749, guid: 6460523340b221f4ea5611d2c011a26c, type: 2} metroInputSource: 0 wsaTransparentSwapchain: 0 m_HolographicPauseOnTrackingLoss: 1 diff --git a/README.md b/README.md index d6bc15c..c969162 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,37 @@ # WACVR + A VR arcade emulator ## Current stage + - Successfully started the game itself - Successfully initialized touch - Successfully send touch signal - Successfully enabled Freeplay and tested the touch signal in game ## Current issue + - None! ## Quick guide + - Port binding is same as my other repo MaiDXR - add "[touch] enable=0" to ini file +## Configuration + +A ``config.json`` is automatically created in the WACVR root on startup + +- ``Skybox``: the current skybox selected for use (Default: 0) +- ``Height``: the offset from default height that the player is moved (Default: 0.0) +- ``ThirdPerson``: whether or not the camera is in third person (Default: true) +- ``CaptureMode``: the method uWindowCapture will use for window capture + - ``0``: PrintScreen + - ``1``: BitBlt + - ``2``: Windows Graphics Capture + - ``3``: Automatic (Recommended, Default) +- ``CaptureFramerate``: the framerate to capture the game at (Default: 60) + ## Why this repo now? + I don't have much time and enough skills to make this project by myself. I'm not familiar with Unreal Engine etc. So I want this project to be a community project.