mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Add orb proxies
This commit is contained in:
parent
6f34dc71d5
commit
b66752980c
52
NewHorizons/Builder/Body/ProxyBuilder.cs
Normal file
52
NewHorizons/Builder/Body/ProxyBuilder.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using NewHorizons.Components;
|
||||
using NewHorizons.Utility;
|
||||
using OWML.Common;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Builder.Body
|
||||
{
|
||||
public class ProxyBuilder
|
||||
{
|
||||
public static void Make(GameObject gameObject, NewHorizonsBody body)
|
||||
{
|
||||
var proxyName = $"{body.Config.Name}_Proxy";
|
||||
|
||||
// Stars don't work yet so uh
|
||||
/*
|
||||
if (body.Config.Star != null)
|
||||
{
|
||||
var sunProxy = SearchUtilities.CachedFind("SunProxy(Clone)");
|
||||
var oldProxyEffectController = sunProxy.GetComponentInChildren<SunProxyEffectController>();
|
||||
var newProxy = Object.Instantiate(sunProxy, gameObject.transform.position, Quaternion.identity);
|
||||
newProxy.name = proxyName;
|
||||
var proxyController = newProxy.GetComponent<SunProxy>();
|
||||
proxyController._proxySunController = newProxy.GetComponentInChildren<SunProxyEffectController>();
|
||||
proxyController._proxySunController._atmosphereMaterial = oldProxyEffectController._atmosphereMaterial;
|
||||
proxyController._proxySunController._fogMaterial = oldProxyEffectController._fogMaterial;
|
||||
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() =>
|
||||
{
|
||||
proxyController._sunTransform = gameObject.transform;
|
||||
proxyController._realSunController = gameObject.GetComponent<SunController>();
|
||||
});
|
||||
}
|
||||
*/
|
||||
// TODO: Make it not do it on vanilla bodies
|
||||
var newModel = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||
Object.Destroy(newModel.GetComponent<Collider>());
|
||||
var newProxy = new GameObject(proxyName);
|
||||
newModel.transform.SetParent(newProxy.transform);
|
||||
newModel.transform.position = Vector3.zero;
|
||||
newModel.transform.localScale = 1000 * Vector3.one;
|
||||
newModel.transform.rotation = Quaternion.identity;
|
||||
var proxyController = newProxy.AddComponent<NHProxy>();
|
||||
proxyController.astroName = body.Config.Name;
|
||||
proxyController._realObjectDiameter = body.Config.Base?.SurfaceSize ?? 100f;
|
||||
proxyController.renderer = newProxy.GetComponentInChildren<Renderer>();
|
||||
}
|
||||
|
||||
private static void MakeHeightMapProxy(NewHorizonsBody body, IModBehaviour mod)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -202,16 +202,16 @@ namespace NewHorizons.Builder.General
|
||||
|
||||
private static void RemoveProxy(string name)
|
||||
{
|
||||
if (name.Equals("TowerTwin")) name = "AshTwin";
|
||||
if (name.Equals("CaveTwin")) name = "EmberTwin";
|
||||
var distantProxy = GameObject.Find(name + "_DistantProxy");
|
||||
var distantProxyClone = GameObject.Find(name + "_DistantProxy(Clone)");
|
||||
|
||||
if (distantProxy != null) GameObject.Destroy(distantProxy.gameObject);
|
||||
if (distantProxyClone != null) GameObject.Destroy(distantProxyClone.gameObject);
|
||||
|
||||
if (distantProxy == null && distantProxyClone == null)
|
||||
Logger.Log($"Couldn't find proxy for {name}");
|
||||
// if (name.Equals("TowerTwin")) name = "AshTwin";
|
||||
// if (name.Equals("CaveTwin")) name = "EmberTwin";
|
||||
// var distantProxy = GameObject.Find(name + "_DistantProxy");
|
||||
// var distantProxyClone = GameObject.Find(name + "_DistantProxy(Clone)");
|
||||
//
|
||||
// if (distantProxy != null) GameObject.Destroy(distantProxy.gameObject);
|
||||
// if (distantProxyClone != null) GameObject.Destroy(distantProxyClone.gameObject);
|
||||
//
|
||||
// if (distantProxy == null && distantProxyClone == null)
|
||||
// Logger.Log($"Couldn't find proxy for {name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,15 +49,10 @@ namespace NewHorizons.Builder.StarSystem
|
||||
Logger.Log("Building Skybox");
|
||||
Material skyBoxMaterial = LoadMaterial(info.assetBundle, info.path, mod.ModHelper.Manifest.UniqueName, mod);
|
||||
RenderSettings.skybox = skyBoxMaterial;
|
||||
DynamicGI.UpdateEnvironment();
|
||||
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() =>
|
||||
{
|
||||
foreach (var camera in Resources.FindObjectsOfTypeAll<OWCamera>())
|
||||
{
|
||||
camera.clearFlags = CameraClearFlags.Skybox;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
38
NewHorizons/Components/NHProxy.cs
Normal file
38
NewHorizons/Components/NHProxy.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using NewHorizons.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Components
|
||||
{
|
||||
public class NHProxy : ProxyPlanet
|
||||
{
|
||||
public string astroName;
|
||||
public Renderer renderer;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
AstroObject astroObject = AstroObjectLocator.GetAstroObject(astroName);
|
||||
_realObjectTransform = astroObject.transform;
|
||||
_hasAtmosphere = _atmosphere != null;
|
||||
if (_hasAtmosphere)
|
||||
{
|
||||
_atmosphereMaterial = new Material(_atmosphere.sharedMaterial);
|
||||
_baseAtmoMatShellInnerRadius = _atmosphereMaterial.GetFloat(propID_AtmoInnerRadius);
|
||||
_baseAtmoMatShellOuterRadius = _atmosphereMaterial.GetFloat(propID_AtmoOuterRadius);
|
||||
_atmosphere.sharedMaterial = _atmosphereMaterial;
|
||||
}
|
||||
if (_fog != null)
|
||||
{
|
||||
_hasFog = true;
|
||||
_fogMaterial = new Material(_fog.sharedMaterial);
|
||||
_fogMaterial.SetFloat(propID_LODFade, 1f);
|
||||
_fog.sharedMaterial = _fogMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ToggleRendering(bool on)
|
||||
{
|
||||
base.ToggleRendering(on);
|
||||
renderer.enabled = on;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -119,7 +119,7 @@ namespace NewHorizons.Handlers
|
||||
Logger.Log("Done loading bodies");
|
||||
|
||||
// I don't know what these do but they look really weird from a distance
|
||||
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(PlanetDestroyer.RemoveAllProxies);
|
||||
// Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(PlanetDestroyer.RemoveAllProxies);
|
||||
|
||||
if (Main.SystemDict[Main.Instance.CurrentStarSystem].Config.destroyStockPlanets) PlanetDestroyer.RemoveSolarSystem();
|
||||
}
|
||||
@ -399,6 +399,11 @@ namespace NewHorizons.Handlers
|
||||
if (body.Config.Base.CloakRadius != 0f)
|
||||
CloakBuilder.Make(go, sector, body.Config.Base.CloakRadius);
|
||||
|
||||
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() =>
|
||||
{
|
||||
ProxyBuilder.Make(go, body);
|
||||
});
|
||||
|
||||
return go;
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace NewHorizons.Patches
|
||||
{
|
||||
@ -15,13 +16,25 @@ namespace NewHorizons.Patches
|
||||
[HarmonyPatch(typeof(OWCamera), nameof(OWCamera.Awake))]
|
||||
public static void OnOWCameraAwake(OWCamera __instance)
|
||||
{
|
||||
var oldDist = __instance.farClipPlane;
|
||||
var newDist = __instance.farClipPlane * 10f;
|
||||
if (__instance.useFarCamera) Mathf.Clamp(newDist, oldDist, 50000f);
|
||||
else newDist = Mathf.Clamp(newDist, oldDist, 10000000f);
|
||||
__instance.farClipPlane = newDist;
|
||||
__instance.farCameraDistance = newDist;
|
||||
__instance.mainCamera.farClipPlane = newDist;
|
||||
}
|
||||
// var oldDist = __instance.farClipPlane;
|
||||
// var newDist = __instance.farClipPlane * 10f;
|
||||
// if (__instance.useFarCamera) Mathf.Clamp(newDist, oldDist, 50000f);
|
||||
// else newDist = Mathf.Clamp(newDist, oldDist, 10000000f);
|
||||
// __instance.farClipPlane = newDist;
|
||||
// __instance.farCameraDistance = newDist;
|
||||
// __instance.mainCamera.farClipPlane = newDist;
|
||||
}
|
||||
|
||||
// [HarmonyPrefix]
|
||||
// [HarmonyPatch(typeof(OWCamera), nameof(OWCamera.RebuildSkybox))]
|
||||
// public static bool OnOWCameraRebuildSkybox(OWCamera __instance)
|
||||
// {
|
||||
// __instance._skyboxCommandBuffer = new CommandBuffer();
|
||||
// __instance._skyboxCommandBuffer.name = "Skybox";
|
||||
// var camera = __instance._useFarCamera && !SystemInfo.usesReversedZBuffer ? __instance._farCamera : __instance._mainCamera;
|
||||
// CameraEvent evt = CameraEvent.BeforeSkybox;
|
||||
// camera.AddCommandBuffer(evt, __instance._skyboxCommandBuffer);
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user