Fix camera, null exception in base builder

This commit is contained in:
Nick J. Connors 2022-01-16 22:25:21 -05:00
parent ee8c7ebcaf
commit d7084c6d41
5 changed files with 35 additions and 28 deletions

View File

@ -50,7 +50,7 @@ namespace NewHorizons.Builder.General
astroObject.SetValue("_primaryBody", primaryBody);
// Expand gravitational sphere of influence of the primary to encompass this body if needed
if(primaryBody != null && !config.Orbit.IsStatic)
if(primaryBody?.gameObject?.GetComponent<SphereCollider>() != null && !config.Orbit.IsStatic)
{
var primarySphereOfInfluence = primaryBody.GetGravityVolume().gameObject.GetComponent<SphereCollider>();
if (primarySphereOfInfluence.radius < config.Orbit.SemiMajorAxis)

View File

@ -58,7 +58,8 @@ namespace NewHorizons
ShaderBundle = Main.Instance.ModHelper.Assets.LoadBundle("AssetBundle/shader");
BodyDict["SolarSystem"] = new List<NewHorizonsBody>();
Utility.Patches.Apply();
Tools.Patches.Apply();
Tools.OWCameraFix.Apply();
Logger.Log("Begin load of config files...", Logger.LogType.Log);
@ -97,6 +98,10 @@ namespace NewHorizons
return;
}
FurthestOrbit = 30000;
Tools.OWCameraFix.Apply();
HeavenlyBodyBuilder.Reset();
NewHorizonsData.Load();
@ -203,19 +208,6 @@ namespace NewHorizons
Logger.Log($"Is the player warping in? {IsWarping}");
if (IsWarping) Instance.ModHelper.Events.Unity.FireInNUpdates(() => _shipWarpController.WarpIn(WearingSuit), 1);
IsWarping = false;
// Fix some camera stuff
/*
foreach(var owc in GameObject.FindObjectsOfType<OWCamera>())
{
var far = Main.FurthestOrbit * 10f;
if (owc.farClipPlane < far)
{
owc.farClipPlane = far;
owc.mainCamera.farClipPlane = far;
}
}
*/
}
#region TitleScreen

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Tools
{
public static class OWCameraFix
{
public static void Apply()
{
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<OWCamera>("Awake", typeof(OWCameraFix), nameof(OWCameraFix.OnOWCameraAwake));
}
private static void OnOWCameraAwake(OWCamera __instance)
{
var newDist = __instance.farClipPlane * 10f;
if (__instance.useFarCamera) newDist = Mathf.Min(500000f, newDist);
__instance.farClipPlane = newDist;
__instance.farCameraDistance = newDist;
}
}
}

View File

@ -9,8 +9,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Utility
namespace NewHorizons.Tools
{
public class Patches
{
@ -55,7 +56,6 @@ namespace NewHorizons.Utility
// Postfixes
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<MapController>("Awake", typeof(Patches), nameof(Patches.OnMapControllerAwake));
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<OWCamera>("Awake", typeof(Patches), nameof(Patches.OnOWCameraAwake));
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<ShipLogMapMode>("EnterMode", typeof(Patches), nameof(Patches.OnShipLogMapModeEnterMode));
}
@ -80,7 +80,6 @@ namespace NewHorizons.Utility
public static void OnMapControllerAwake(MapController __instance, ref float ____maxPanDistance, ref float ____maxZoomDistance, ref float ____minPitchAngle, ref float ____zoomSpeed)
{
Logger.Log($"Other far? {Main.FurthestOrbit}");
____maxPanDistance = Main.FurthestOrbit * 1.5f;
____maxZoomDistance *= 6f;
____minPitchAngle = -90f;
@ -88,15 +87,6 @@ namespace NewHorizons.Utility
__instance._mapCamera.farClipPlane = Main.FurthestOrbit * 10f;
}
public static void OnOWCameraAwake(OWCamera __instance)
{
/*
var far = Main.FurthestOrbit * 10f;
__instance.farClipPlane = far;
__instance.mainCamera.farClipPlane = far;
*/
}
public static bool OnSunLightParamUpdaterLateUpdate(SunLightParamUpdater __instance)
{
if (__instance.sunLight)

View File

@ -3,7 +3,7 @@
"author": "xen",
"name": "New Horizons",
"uniqueName": "xen.NewHorizons",
"version": "0.7.2",
"version": "0.7.3",
"owmlVersion": "2.1.0",
"dependencies": [ "PacificEngine.OW_CommonResources" ],
"conflicts": [ "Raicuparta.QuantumSpaceBuddies", "Vesper.OuterWildsMMO", "Vesper.AutoResume" ]