From b5d688ad1921048dfca4467b68bd84e0a42bdb26 Mon Sep 17 00:00:00 2001 From: PureDark Date: Wed, 22 Aug 2018 22:28:47 +0800 Subject: [PATCH] v0.1.1 HMD option only works in no fail mode, built for BS v0.11.2 --- TransparentWall/Plugin.cs | 18 ++++++--- TransparentWall/TransparentWall.cs | 62 ++++++++++++++++-------------- 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/TransparentWall/Plugin.cs b/TransparentWall/Plugin.cs index 44bf29b..c91abcc 100644 --- a/TransparentWall/Plugin.cs +++ b/TransparentWall/Plugin.cs @@ -12,12 +12,14 @@ namespace TransparentWall class Plugin : IEnhancedPlugin, IPlugin { public static string PluginName = "TransparentWall"; - public const string VersionNum = "0.1.0"; + public const string VersionNum = "0.1.1"; public string Name => PluginName; public string Version => VersionNum; public string[] Filter { get; } - + + private static AsyncScenesLoader loader; + public const string KeyTranparentWall = "TransparentWall"; public const string KeyHMD = "HMD"; public const string KeyCameraPlus = "CameraPlus"; @@ -111,13 +113,19 @@ public void OnApplicationQuit() private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene) { - if (scene.buildIndex == 5) + if (scene.name == "StandardLevelLoader") { - new GameObject("TransparentWall").AddComponent(); + if (!loader) + loader = Resources.FindObjectsOfTypeAll().FirstOrDefault(); + loader.loadingDidFinishEvent += OnLoadingDidFinish; } } + public void OnLoadingDidFinish() + { + new GameObject("TransparentWall").AddComponent(); + } - public void OnLateUpdate() + public void OnLateUpdate() { } diff --git a/TransparentWall/TransparentWall.cs b/TransparentWall/TransparentWall.cs index 54033a7..dfb681a 100644 --- a/TransparentWall/TransparentWall.cs +++ b/TransparentWall/TransparentWall.cs @@ -13,6 +13,8 @@ public class TransparentWall : MonoBehaviour private void Start() { + if (!Plugin.IsTranparentWall) + return; try { this._beatmapObjectSpawnController = Resources.FindObjectsOfTypeAll().First(); @@ -53,8 +55,11 @@ private void setupCams() private IEnumerator setupCamerasCoroutine() { yield return new WaitForEndOfFrame(); + + var mainGameSceneSetupData = Resources.FindObjectsOfTypeAll().FirstOrDefault(); + Camera mainCamera = FindObjectsOfType().FirstOrDefault(x => x.CompareTag("MainCamera")); - if (Plugin.IsHMDOn) + if (Plugin.IsHMDOn && !mainGameSceneSetupData.gameplayOptions.validForScoreUse) mainCamera.cullingMask &= ~(1 << WallLayer); else mainCamera.cullingMask |= (1 << WallLayer); @@ -63,25 +68,27 @@ private IEnumerator setupCamerasCoroutine() { if (plugin.Name == "CameraPlus" || plugin.Name == "CameraPlusOrbitEdition" || plugin.Name == "DynamicCamera") { - var _cameraPlus = ReflectionUtil.GetPrivateField(plugin, "_cameraPlus"); - if (_cameraPlus != null) + MonoBehaviour _cameraPlus = ReflectionUtil.GetPrivateField(plugin, "_cameraPlus"); + while (_cameraPlus == null) + { + yield return new WaitForEndOfFrame(); + _cameraPlus = ReflectionUtil.GetPrivateField(plugin, "_cameraPlus"); + } + Camera cam = ReflectionUtil.GetPrivateField(_cameraPlus, "_cam"); + if (cam != null) { - Camera cam = ReflectionUtil.GetPrivateField(_cameraPlus, "_cam"); - if (cam !=null) - { - if (((plugin.Name == "CameraPlus" || plugin.Name == "CameraPlusOrbitEdition") && Plugin.IsCameraPlusOn) || (plugin.Name == "DynamicCamera" && Plugin.IsDynamicCameraOn)) - cam.cullingMask &= ~(1 << WallLayer); - else - cam.cullingMask |= (1 << WallLayer); - } - Camera multi = ReflectionUtil.GetPrivateField(_cameraPlus, "multi"); - if (multi != null) - { - if (Plugin.IsMutiViewFirstPersonOn) - multi.cullingMask &= ~(1 << WallLayer); - else - multi.cullingMask |= (1 << WallLayer); - } + if (((plugin.Name == "CameraPlus" || plugin.Name == "CameraPlusOrbitEdition") && Plugin.IsCameraPlusOn) || (plugin.Name == "DynamicCamera" && Plugin.IsDynamicCameraOn)) + cam.cullingMask &= ~(1 << WallLayer); + else + cam.cullingMask |= (1 << WallLayer); + } + Camera multi = ReflectionUtil.GetPrivateField(_cameraPlus, "multi"); + if (multi != null) + { + if (Plugin.IsMutiViewFirstPersonOn) + multi.cullingMask &= ~(1 << WallLayer); + else + multi.cullingMask |= (1 << WallLayer); } break; } @@ -92,16 +99,13 @@ public virtual void HandleObstacleDiStartMovementEvent(BeatmapObjectSpawnControl { try { - if (Plugin.IsTranparentWall) - { - StretchableObstacle _stretchableObstacle = ReflectionUtil.GetPrivateField(obstacleController, "_stretchableObstacle"); - StretchableCube _stretchableCoreOutside = ReflectionUtil.GetPrivateField(_stretchableObstacle, "_stretchableCoreOutside"); - StretchableCube _stretchableCoreInside = ReflectionUtil.GetPrivateField(_stretchableObstacle, "_stretchableCoreInside"); - MeshRenderer _meshRenderer = ReflectionUtil.GetPrivateField(_stretchableCoreOutside, "_meshRenderer"); - MeshRenderer _meshRenderer2 = ReflectionUtil.GetPrivateField(_stretchableCoreInside, "_meshRenderer"); - _stretchableCoreOutside.gameObject.layer = WallLayer; - _stretchableCoreInside.gameObject.layer = WallLayer; - } + StretchableObstacle _stretchableObstacle = ReflectionUtil.GetPrivateField(obstacleController, "_stretchableObstacle"); + StretchableCube _stretchableCoreOutside = ReflectionUtil.GetPrivateField(_stretchableObstacle, "_stretchableCoreOutside"); + StretchableCube _stretchableCoreInside = ReflectionUtil.GetPrivateField(_stretchableObstacle, "_stretchableCoreInside"); + //MeshRenderer _meshRenderer = ReflectionUtil.GetPrivateField(_stretchableCoreOutside, "_meshRenderer"); + //MeshRenderer _meshRenderer2 = ReflectionUtil.GetPrivateField(_stretchableCoreInside, "_meshRenderer"); + _stretchableCoreOutside.gameObject.layer = WallLayer; + _stretchableCoreInside.gameObject.layer = WallLayer; } catch (Exception ex) {