mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Make proxies look right
This commit is contained in:
parent
437609cf8f
commit
bb08b575ce
@ -14,83 +14,13 @@ namespace NewHorizons.Builder.Atmosphere
|
|||||||
private static Material[] _gdCloudMaterials;
|
private static Material[] _gdCloudMaterials;
|
||||||
public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod)
|
public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod)
|
||||||
{
|
{
|
||||||
Texture2D image, cap, ramp;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
image = ImageUtilities.GetTexture(mod, atmo.Cloud);
|
|
||||||
|
|
||||||
if (atmo.CloudCap == null) cap = ImageUtilities.ClearTexture(128, 128);
|
|
||||||
else cap = ImageUtilities.GetTexture(mod, atmo.CloudCap);
|
|
||||||
if (atmo.CloudRamp == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height);
|
|
||||||
else ramp = ImageUtilities.GetTexture(mod, atmo.CloudRamp);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logger.LogError($"Couldn't load Cloud textures, {e.Message}, {e.StackTrace}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color cloudTint = atmo.CloudTint == null ? Color.white : (Color)atmo.CloudTint.ToColor32();
|
Color cloudTint = atmo.CloudTint == null ? Color.white : (Color)atmo.CloudTint.ToColor32();
|
||||||
|
|
||||||
GameObject cloudsMainGO = new GameObject("Clouds");
|
GameObject cloudsMainGO = new GameObject("Clouds");
|
||||||
cloudsMainGO.SetActive(false);
|
cloudsMainGO.SetActive(false);
|
||||||
cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform;
|
cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform;
|
||||||
|
|
||||||
GameObject cloudsTopGO = new GameObject("TopClouds");
|
MakeTopClouds(cloudsMainGO, atmo, mod);
|
||||||
cloudsTopGO.SetActive(false);
|
|
||||||
cloudsTopGO.transform.parent = cloudsMainGO.transform;
|
|
||||||
cloudsTopGO.transform.localScale = Vector3.one * atmo.Size;
|
|
||||||
|
|
||||||
MeshFilter topMF = cloudsTopGO.AddComponent<MeshFilter>();
|
|
||||||
topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh;
|
|
||||||
|
|
||||||
MeshRenderer topMR = cloudsTopGO.AddComponent<MeshRenderer>();
|
|
||||||
|
|
||||||
if (_sphereShader == null) _sphereShader = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/SphereTextureWrapper.shader");
|
|
||||||
if (_gdCloudMaterials == null) _gdCloudMaterials = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshRenderer>().sharedMaterials;
|
|
||||||
var tempArray = new Material[2];
|
|
||||||
|
|
||||||
if (atmo.UseBasicCloudShader)
|
|
||||||
{
|
|
||||||
var material = new Material(_sphereShader);
|
|
||||||
if (!atmo.ShadowsOnClouds) material.renderQueue = 2550;
|
|
||||||
material.name = atmo.ShadowsOnClouds ? "BasicShadowCloud" : "BasicCloud";
|
|
||||||
|
|
||||||
tempArray[0] = material;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var material = new Material(_gdCloudMaterials[0]);
|
|
||||||
if (!atmo.ShadowsOnClouds) material.renderQueue = 2550;
|
|
||||||
material.name = atmo.ShadowsOnClouds ? "AdvancedShadowCloud" : "AdvancedCloud";
|
|
||||||
tempArray[0] = material;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is the stencil material for the fog under the clouds
|
|
||||||
tempArray[1] = new Material(_gdCloudMaterials[1]);
|
|
||||||
topMR.sharedMaterials = tempArray;
|
|
||||||
|
|
||||||
foreach (var material in topMR.sharedMaterials)
|
|
||||||
{
|
|
||||||
material.SetColor("_Color", cloudTint);
|
|
||||||
material.SetColor("_TintColor", cloudTint);
|
|
||||||
|
|
||||||
material.SetTexture("_MainTex", image);
|
|
||||||
material.SetTexture("_RampTex", ramp);
|
|
||||||
material.SetTexture("_CapTex", cap);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!atmo.ShadowsOnClouds)
|
|
||||||
{
|
|
||||||
cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun");
|
|
||||||
}
|
|
||||||
|
|
||||||
RotateTransform topRT = cloudsTopGO.AddComponent<RotateTransform>();
|
|
||||||
// Idk why but the axis is weird
|
|
||||||
topRT._localAxis = atmo.UseBasicCloudShader ? Vector3.forward : Vector3.up;
|
|
||||||
topRT._degreesPerSecond = 10;
|
|
||||||
topRT._randomizeRotationRate = false;
|
|
||||||
|
|
||||||
GameObject cloudsBottomGO = new GameObject("BottomClouds");
|
GameObject cloudsBottomGO = new GameObject("BottomClouds");
|
||||||
cloudsBottomGO.SetActive(false);
|
cloudsBottomGO.SetActive(false);
|
||||||
@ -104,7 +34,7 @@ namespace NewHorizons.Builder.Atmosphere
|
|||||||
// If they set a colour apply it to all the materials else keep the default QM one
|
// If they set a colour apply it to all the materials else keep the default QM one
|
||||||
if (atmo.CloudTint != null)
|
if (atmo.CloudTint != null)
|
||||||
{
|
{
|
||||||
var bottomColor = atmo.CloudTint.ToColor32();
|
var bottomColor = cloudTint;
|
||||||
|
|
||||||
var bottomTSRTempArray = new Material[2];
|
var bottomTSRTempArray = new Material[2];
|
||||||
|
|
||||||
@ -170,12 +100,93 @@ namespace NewHorizons.Builder.Atmosphere
|
|||||||
cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero);
|
cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero);
|
||||||
cloudsBottomGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero);
|
cloudsBottomGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero);
|
||||||
cloudsFluidGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero);
|
cloudsFluidGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero);
|
||||||
cloudsTopGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero);
|
|
||||||
|
|
||||||
cloudsTopGO.SetActive(true);
|
|
||||||
cloudsBottomGO.SetActive(true);
|
cloudsBottomGO.SetActive(true);
|
||||||
cloudsFluidGO.SetActive(true);
|
cloudsFluidGO.SetActive(true);
|
||||||
cloudsMainGO.SetActive(true);
|
cloudsMainGO.SetActive(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod)
|
||||||
|
{
|
||||||
|
Color cloudTint = atmo.CloudTint == null ? Color.white : (Color)atmo.CloudTint.ToColor32();
|
||||||
|
|
||||||
|
Texture2D image, cap, ramp;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
image = ImageUtilities.GetTexture(mod, atmo.Cloud);
|
||||||
|
|
||||||
|
if (atmo.CloudCap == null) cap = ImageUtilities.ClearTexture(128, 128);
|
||||||
|
else cap = ImageUtilities.GetTexture(mod, atmo.CloudCap);
|
||||||
|
if (atmo.CloudRamp == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height);
|
||||||
|
else ramp = ImageUtilities.GetTexture(mod, atmo.CloudRamp);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.LogError($"Couldn't load Cloud textures, {e.Message}, {e.StackTrace}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameObject cloudsTopGO = new GameObject("TopClouds");
|
||||||
|
cloudsTopGO.SetActive(false);
|
||||||
|
cloudsTopGO.transform.parent = rootObject.transform;
|
||||||
|
cloudsTopGO.transform.localScale = Vector3.one * atmo.Size;
|
||||||
|
|
||||||
|
MeshFilter topMF = cloudsTopGO.AddComponent<MeshFilter>();
|
||||||
|
topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh;
|
||||||
|
|
||||||
|
MeshRenderer topMR = cloudsTopGO.AddComponent<MeshRenderer>();
|
||||||
|
|
||||||
|
if (_sphereShader == null) _sphereShader = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/SphereTextureWrapper.shader");
|
||||||
|
if (_gdCloudMaterials == null) _gdCloudMaterials = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshRenderer>().sharedMaterials;
|
||||||
|
var tempArray = new Material[2];
|
||||||
|
|
||||||
|
if (atmo.UseBasicCloudShader)
|
||||||
|
{
|
||||||
|
var material = new Material(_sphereShader);
|
||||||
|
if (!atmo.ShadowsOnClouds) material.renderQueue = 2550;
|
||||||
|
material.name = atmo.ShadowsOnClouds ? "BasicShadowCloud" : "BasicCloud";
|
||||||
|
|
||||||
|
tempArray[0] = material;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var material = new Material(_gdCloudMaterials[0]);
|
||||||
|
if (!atmo.ShadowsOnClouds) material.renderQueue = 2550;
|
||||||
|
material.name = atmo.ShadowsOnClouds ? "AdvancedShadowCloud" : "AdvancedCloud";
|
||||||
|
tempArray[0] = material;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is the stencil material for the fog under the clouds
|
||||||
|
tempArray[1] = new Material(_gdCloudMaterials[1]);
|
||||||
|
topMR.sharedMaterials = tempArray;
|
||||||
|
|
||||||
|
foreach (var material in topMR.sharedMaterials)
|
||||||
|
{
|
||||||
|
material.SetColor("_Color", cloudTint);
|
||||||
|
material.SetColor("_TintColor", cloudTint);
|
||||||
|
|
||||||
|
material.SetTexture("_MainTex", image);
|
||||||
|
material.SetTexture("_RampTex", ramp);
|
||||||
|
material.SetTexture("_CapTex", cap);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!atmo.ShadowsOnClouds)
|
||||||
|
{
|
||||||
|
cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun");
|
||||||
|
}
|
||||||
|
|
||||||
|
RotateTransform topRT = cloudsTopGO.AddComponent<RotateTransform>();
|
||||||
|
// Idk why but the axis is weird
|
||||||
|
topRT._localAxis = atmo.UseBasicCloudShader ? Vector3.forward : Vector3.up;
|
||||||
|
topRT._degreesPerSecond = 10;
|
||||||
|
topRT._randomizeRotationRate = false;
|
||||||
|
|
||||||
|
cloudsTopGO.transform.localPosition = Vector3.zero;
|
||||||
|
|
||||||
|
cloudsTopGO.SetActive(true);
|
||||||
|
|
||||||
|
return cloudsTopGO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ namespace NewHorizons.Builder.Body
|
|||||||
{
|
{
|
||||||
public static Shader PlanetShader;
|
public static Shader PlanetShader;
|
||||||
|
|
||||||
public static void Make(GameObject planetGO, Sector sector, HeightMapModule module, IModBehaviour mod)
|
public static void Make(GameObject planetGO, Sector sector, HeightMapModule module, IModBehaviour mod, int resolution = 51)
|
||||||
{
|
{
|
||||||
Texture2D heightMap, textureMap;
|
Texture2D heightMap, textureMap;
|
||||||
try
|
try
|
||||||
@ -39,7 +39,7 @@ namespace NewHorizons.Builder.Body
|
|||||||
cubeSphere.transform.rotation = Quaternion.Euler(90, 0, 0);
|
cubeSphere.transform.rotation = Quaternion.Euler(90, 0, 0);
|
||||||
|
|
||||||
Vector3 stretch = module.Stretch != null ? (Vector3)module.Stretch : Vector3.one;
|
Vector3 stretch = module.Stretch != null ? (Vector3)module.Stretch : Vector3.one;
|
||||||
Mesh mesh = CubeSphere.Build(51, heightMap, module.MinHeight, module.MaxHeight, stretch);
|
Mesh mesh = CubeSphere.Build(resolution, heightMap, module.MinHeight, module.MaxHeight, stretch);
|
||||||
|
|
||||||
cubeSphere.AddComponent<MeshFilter>();
|
cubeSphere.AddComponent<MeshFilter>();
|
||||||
cubeSphere.GetComponent<MeshFilter>().mesh = mesh;
|
cubeSphere.GetComponent<MeshFilter>().mesh = mesh;
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using NewHorizons.Components;
|
using NewHorizons.Builder.Atmosphere;
|
||||||
|
using NewHorizons.Components;
|
||||||
using NewHorizons.Utility;
|
using NewHorizons.Utility;
|
||||||
using OWML.Common;
|
using OWML.Common;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -30,23 +31,62 @@ namespace NewHorizons.Builder.Body
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
// 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);
|
var newProxy = new GameObject(proxyName);
|
||||||
newModel.transform.SetParent(newProxy.transform);
|
|
||||||
newModel.transform.position = Vector3.zero;
|
// We want to take the largest size I think
|
||||||
newModel.transform.localScale = 1000 * Vector3.one;
|
var realSize = body.Config.Base.SurfaceSize;
|
||||||
newModel.transform.rotation = Quaternion.identity;
|
|
||||||
|
if (body.Config.HeightMap != null)
|
||||||
|
{
|
||||||
|
HeightMapBuilder.Make(newProxy, null, body.Config.HeightMap, body.Mod, 20);
|
||||||
|
if(realSize < body.Config.HeightMap.MaxHeight) realSize = body.Config.HeightMap.MaxHeight;
|
||||||
|
}
|
||||||
|
if (body.Config.Base.GroundSize != 0)
|
||||||
|
{
|
||||||
|
GeometryBuilder.Make(newProxy, null, body.Config.Base.GroundSize);
|
||||||
|
if (realSize < body.Config.Base.GroundSize) realSize = body.Config.Base.GroundSize;
|
||||||
|
}
|
||||||
|
if (body.Config.Atmosphere != null)
|
||||||
|
{
|
||||||
|
CloudsBuilder.MakeTopClouds(newProxy, body.Config.Atmosphere, body.Mod);
|
||||||
|
if (realSize < body.Config.Atmosphere.Size) realSize = body.Config.Atmosphere.Size;
|
||||||
|
}
|
||||||
|
if (body.Config.Ring != null)
|
||||||
|
{
|
||||||
|
RingBuilder.MakeRingGraphics(newProxy, null, body.Config.Ring, body.Mod);
|
||||||
|
if (realSize < body.Config.Ring.OuterRadius) realSize = body.Config.Ring.OuterRadius;
|
||||||
|
}
|
||||||
|
if (body.Config.Star != null)
|
||||||
|
{
|
||||||
|
StarBuilder.MakeStarGraphics(newProxy, null, body.Config.Star);
|
||||||
|
if (realSize < body.Config.Star.Size) realSize = body.Config.Star.Size;
|
||||||
|
}
|
||||||
|
if(body.Config.ProcGen != null)
|
||||||
|
{
|
||||||
|
ProcGenBuilder.Make(newProxy, null, body.Config.ProcGen);
|
||||||
|
if (realSize < body.Config.ProcGen.Scale) realSize = body.Config.ProcGen.Scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove all collisions if there are any
|
||||||
|
foreach (var col in newProxy.GetComponentsInChildren<Collider>())
|
||||||
|
{
|
||||||
|
GameObject.Destroy(col);
|
||||||
|
}
|
||||||
|
// Fix render idk
|
||||||
|
foreach (var renderer in newProxy.GetComponentsInChildren<Renderer>())
|
||||||
|
{
|
||||||
|
renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
|
||||||
|
renderer.receiveShadows = false;
|
||||||
|
renderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.BlendProbes;
|
||||||
|
renderer.enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
var proxyController = newProxy.AddComponent<NHProxy>();
|
var proxyController = newProxy.AddComponent<NHProxy>();
|
||||||
proxyController.astroName = body.Config.Name;
|
proxyController.astroName = body.Config.Name;
|
||||||
proxyController._realObjectDiameter = body.Config.Base?.SurfaceSize ?? 100f;
|
proxyController._realObjectDiameter = realSize;
|
||||||
proxyController.renderer = newProxy.GetComponentInChildren<Renderer>();
|
proxyController.renderers = newProxy.GetComponentsInChildren<Renderer>();
|
||||||
}
|
proxyController.tessellatedRenderers = newProxy.GetComponentsInChildren<TessellatedRenderer>();
|
||||||
|
|
||||||
private static void MakeHeightMapProxy(NewHorizonsBody body, IModBehaviour mod)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -23,59 +23,7 @@ namespace NewHorizons.Builder.Body
|
|||||||
|
|
||||||
public static GameObject Make(GameObject planetGO, Sector sector, RingModule ring, IModBehaviour mod)
|
public static GameObject Make(GameObject planetGO, Sector sector, RingModule ring, IModBehaviour mod)
|
||||||
{
|
{
|
||||||
// Properly lit shader doesnt work yet
|
var ringGO = MakeRingGraphics(planetGO, sector, ring, mod);
|
||||||
ring.Unlit = true;
|
|
||||||
|
|
||||||
Texture2D ringTexture;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ringTexture = ImageUtilities.GetTexture(mod, ring.Texture);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logger.LogError($"Couldn't load Ring texture, {e.Message}, {e.StackTrace}");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var ringGO = new GameObject("Ring");
|
|
||||||
ringGO.transform.parent = sector?.transform ?? planetGO.transform;
|
|
||||||
ringGO.transform.position = planetGO.transform.position;
|
|
||||||
ringGO.transform.rotation = planetGO.transform.rotation;
|
|
||||||
ringGO.transform.Rotate(ringGO.transform.TransformDirection(Vector3.up), ring.LongitudeOfAscendingNode);
|
|
||||||
ringGO.transform.Rotate(ringGO.transform.TransformDirection(Vector3.left), ring.Inclination);
|
|
||||||
|
|
||||||
var ringMF = ringGO.AddComponent<MeshFilter>();
|
|
||||||
var ringMesh = ringMF.mesh;
|
|
||||||
var ringMR = ringGO.AddComponent<MeshRenderer>();
|
|
||||||
var texture = ringTexture;
|
|
||||||
|
|
||||||
if (RingShader == null) RingShader = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/Ring.shader");
|
|
||||||
if (UnlitRingShader == null) UnlitRingShader = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/UnlitTransparent.shader");
|
|
||||||
if (RingShader1Pixel == null) RingShader1Pixel = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/Ring1Pixel.shader");
|
|
||||||
if (UnlitRingShader1Pixel == null) UnlitRingShader1Pixel = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/UnlitRing1Pixel.shader");
|
|
||||||
|
|
||||||
var mat = new Material(ring.Unlit ? UnlitRingShader : RingShader);
|
|
||||||
if (texture.width == 1)
|
|
||||||
{
|
|
||||||
mat = new Material(ring.Unlit ? UnlitRingShader1Pixel : RingShader1Pixel);
|
|
||||||
mat.SetFloat("_InnerRadius", 0);
|
|
||||||
}
|
|
||||||
ringMR.receiveShadows = !ring.Unlit;
|
|
||||||
|
|
||||||
mat.mainTexture = texture;
|
|
||||||
mat.renderQueue = 3000;
|
|
||||||
ringMR.material = mat;
|
|
||||||
|
|
||||||
// Make mesh
|
|
||||||
var segments = (int)Mathf.Clamp(ring.OuterRadius, 20, 2000);
|
|
||||||
BuildRingMesh(ringMesh, segments, ring.InnerRadius, ring.OuterRadius);
|
|
||||||
|
|
||||||
if (ring.RotationSpeed != 0)
|
|
||||||
{
|
|
||||||
var rot = ringGO.AddComponent<RotateTransform>();
|
|
||||||
rot._degreesPerSecond = ring.RotationSpeed;
|
|
||||||
rot._localAxis = Vector3.down;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Funny collider thing
|
// Funny collider thing
|
||||||
var ringVolume = new GameObject("RingVolume");
|
var ringVolume = new GameObject("RingVolume");
|
||||||
@ -119,6 +67,67 @@ namespace NewHorizons.Builder.Body
|
|||||||
|
|
||||||
ringVolume.SetActive(true);
|
ringVolume.SetActive(true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return ringGO;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GameObject MakeRingGraphics(GameObject rootObject, Sector sector, RingModule ring, IModBehaviour mod)
|
||||||
|
{
|
||||||
|
// Properly lit shader doesnt work yet
|
||||||
|
ring.Unlit = true;
|
||||||
|
|
||||||
|
Texture2D ringTexture;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ringTexture = ImageUtilities.GetTexture(mod, ring.Texture);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.LogError($"Couldn't load Ring texture, {e.Message}, {e.StackTrace}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ringGO = new GameObject("Ring");
|
||||||
|
ringGO.transform.parent = sector?.transform ?? rootObject.transform;
|
||||||
|
ringGO.transform.position = rootObject.transform.position;
|
||||||
|
ringGO.transform.rotation = rootObject.transform.rotation;
|
||||||
|
ringGO.transform.Rotate(ringGO.transform.TransformDirection(Vector3.up), ring.LongitudeOfAscendingNode);
|
||||||
|
ringGO.transform.Rotate(ringGO.transform.TransformDirection(Vector3.left), ring.Inclination);
|
||||||
|
|
||||||
|
var ringMF = ringGO.AddComponent<MeshFilter>();
|
||||||
|
var ringMesh = ringMF.mesh;
|
||||||
|
var ringMR = ringGO.AddComponent<MeshRenderer>();
|
||||||
|
var texture = ringTexture;
|
||||||
|
|
||||||
|
if (RingShader == null) RingShader = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/Ring.shader");
|
||||||
|
if (UnlitRingShader == null) UnlitRingShader = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/UnlitTransparent.shader");
|
||||||
|
if (RingShader1Pixel == null) RingShader1Pixel = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/Ring1Pixel.shader");
|
||||||
|
if (UnlitRingShader1Pixel == null) UnlitRingShader1Pixel = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/UnlitRing1Pixel.shader");
|
||||||
|
|
||||||
|
var mat = new Material(ring.Unlit ? UnlitRingShader : RingShader);
|
||||||
|
if (texture.width == 1)
|
||||||
|
{
|
||||||
|
mat = new Material(ring.Unlit ? UnlitRingShader1Pixel : RingShader1Pixel);
|
||||||
|
mat.SetFloat("_InnerRadius", 0);
|
||||||
|
}
|
||||||
|
ringMR.receiveShadows = !ring.Unlit;
|
||||||
|
|
||||||
|
mat.mainTexture = texture;
|
||||||
|
mat.renderQueue = 3000;
|
||||||
|
ringMR.material = mat;
|
||||||
|
|
||||||
|
// Make mesh
|
||||||
|
var segments = (int)Mathf.Clamp(ring.OuterRadius, 20, 2000);
|
||||||
|
BuildRingMesh(ringMesh, segments, ring.InnerRadius, ring.OuterRadius);
|
||||||
|
|
||||||
|
if (ring.RotationSpeed != 0)
|
||||||
|
{
|
||||||
|
var rot = ringGO.AddComponent<RotateTransform>();
|
||||||
|
rot._degreesPerSecond = ring.RotationSpeed;
|
||||||
|
rot._localAxis = Vector3.down;
|
||||||
|
}
|
||||||
|
|
||||||
if (ring.Curve != null)
|
if (ring.Curve != null)
|
||||||
{
|
{
|
||||||
var levelController = ringGO.AddComponent<SizeController>();
|
var levelController = ringGO.AddComponent<SizeController>();
|
||||||
|
|||||||
@ -23,37 +23,7 @@ namespace NewHorizons.Builder.Body
|
|||||||
{
|
{
|
||||||
if (_colorOverTime == null) _colorOverTime = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/StarColorOverTime.png");
|
if (_colorOverTime == null) _colorOverTime = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/StarColorOverTime.png");
|
||||||
|
|
||||||
var starGO = new GameObject("Star");
|
var starGO = MakeStarGraphics(planetGO, sector, starModule);
|
||||||
starGO.transform.parent = sector?.transform ?? planetGO.transform;
|
|
||||||
|
|
||||||
var sunSurface = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Geometry_SUN/Surface"), starGO.transform);
|
|
||||||
sunSurface.transform.position = planetGO.transform.position;
|
|
||||||
sunSurface.transform.localScale = Vector3.one;
|
|
||||||
sunSurface.name = "Surface";
|
|
||||||
|
|
||||||
var sunLight = new GameObject();
|
|
||||||
sunLight.transform.parent = starGO.transform;
|
|
||||||
sunLight.transform.localPosition = Vector3.zero;
|
|
||||||
sunLight.transform.localScale = Vector3.one;
|
|
||||||
sunLight.name = "StarLight";
|
|
||||||
var light = sunLight.AddComponent<Light>();
|
|
||||||
light.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<Light>());
|
|
||||||
light.intensity *= starModule.SolarLuminosity;
|
|
||||||
light.range *= Mathf.Sqrt(starModule.SolarLuminosity);
|
|
||||||
|
|
||||||
var faceActiveCamera = sunLight.AddComponent<FaceActiveCamera>();
|
|
||||||
faceActiveCamera.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<FaceActiveCamera>());
|
|
||||||
var csmTextureCacher = sunLight.AddComponent<CSMTextureCacher>();
|
|
||||||
csmTextureCacher.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<CSMTextureCacher>());
|
|
||||||
csmTextureCacher._light = light;
|
|
||||||
var proxyShadowLight = sunLight.AddComponent<ProxyShadowLight>();
|
|
||||||
proxyShadowLight.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<ProxyShadowLight>());
|
|
||||||
proxyShadowLight._light = light;
|
|
||||||
|
|
||||||
var solarFlareEmitter = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SolarFlareEmitter"), starGO.transform);
|
|
||||||
solarFlareEmitter.transform.localPosition = Vector3.zero;
|
|
||||||
solarFlareEmitter.transform.localScale = Vector3.one;
|
|
||||||
solarFlareEmitter.name = "SolarFlareEmitter";
|
|
||||||
|
|
||||||
var sunAudio = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Audio_SUN"), starGO.transform);
|
var sunAudio = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Audio_SUN"), starGO.transform);
|
||||||
sunAudio.transform.localPosition = Vector3.zero;
|
sunAudio.transform.localPosition = Vector3.zero;
|
||||||
@ -112,9 +82,19 @@ namespace NewHorizons.Builder.Body
|
|||||||
deathVolume.GetComponent<DestructionVolume>()._shrinkBodies = false;
|
deathVolume.GetComponent<DestructionVolume>()._shrinkBodies = false;
|
||||||
deathVolume.name = "DestructionVolume";
|
deathVolume.name = "DestructionVolume";
|
||||||
|
|
||||||
TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>();
|
|
||||||
Light ambientLight = ambientLightGO.GetComponent<Light>();
|
Light ambientLight = ambientLightGO.GetComponent<Light>();
|
||||||
|
|
||||||
|
var sunLight = new GameObject();
|
||||||
|
sunLight.transform.parent = starGO.transform;
|
||||||
|
sunLight.transform.localPosition = Vector3.zero;
|
||||||
|
sunLight.transform.localScale = Vector3.one;
|
||||||
|
sunLight.name = "StarLight";
|
||||||
|
|
||||||
|
var light = sunLight.AddComponent<Light>();
|
||||||
|
light.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<Light>());
|
||||||
|
light.intensity *= starModule.SolarLuminosity;
|
||||||
|
light.range *= Mathf.Sqrt(starModule.SolarLuminosity);
|
||||||
|
|
||||||
Color lightColour = light.color;
|
Color lightColour = light.color;
|
||||||
if (starModule.LightTint != null) lightColour = starModule.LightTint.ToColor();
|
if (starModule.LightTint != null) lightColour = starModule.LightTint.ToColor();
|
||||||
if (lightColour == null && starModule.Tint != null)
|
if (lightColour == null && starModule.Tint != null)
|
||||||
@ -130,8 +110,69 @@ namespace NewHorizons.Builder.Body
|
|||||||
light.color = lightColour;
|
light.color = lightColour;
|
||||||
ambientLight.color = lightColour;
|
ambientLight.color = lightColour;
|
||||||
|
|
||||||
if(starModule.Tint != null)
|
var faceActiveCamera = sunLight.AddComponent<FaceActiveCamera>();
|
||||||
|
faceActiveCamera.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<FaceActiveCamera>());
|
||||||
|
var csmTextureCacher = sunLight.AddComponent<CSMTextureCacher>();
|
||||||
|
csmTextureCacher.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<CSMTextureCacher>());
|
||||||
|
csmTextureCacher._light = light;
|
||||||
|
var proxyShadowLight = sunLight.AddComponent<ProxyShadowLight>();
|
||||||
|
proxyShadowLight.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<ProxyShadowLight>());
|
||||||
|
proxyShadowLight._light = light;
|
||||||
|
|
||||||
|
StarController starController = null;
|
||||||
|
if (starModule.SolarLuminosity != 0)
|
||||||
{
|
{
|
||||||
|
starController = planetGO.AddComponent<StarController>();
|
||||||
|
starController.Light = light;
|
||||||
|
starController.AmbientLight = ambientLight;
|
||||||
|
starController.FaceActiveCamera = faceActiveCamera;
|
||||||
|
starController.CSMTextureCacher = csmTextureCacher;
|
||||||
|
starController.ProxyShadowLight = proxyShadowLight;
|
||||||
|
starController.Intensity = starModule.SolarLuminosity;
|
||||||
|
starController.SunColor = lightColour;
|
||||||
|
}
|
||||||
|
|
||||||
|
return starController;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector, StarModule starModule)
|
||||||
|
{
|
||||||
|
var starGO = new GameObject("Star");
|
||||||
|
starGO.transform.parent = sector?.transform ?? rootObject.transform;
|
||||||
|
|
||||||
|
var sunSurface = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Geometry_SUN/Surface"), starGO.transform);
|
||||||
|
sunSurface.transform.position = rootObject.transform.position;
|
||||||
|
sunSurface.transform.localScale = Vector3.one;
|
||||||
|
sunSurface.name = "Surface";
|
||||||
|
|
||||||
|
var solarFlareEmitter = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SolarFlareEmitter"), starGO.transform);
|
||||||
|
solarFlareEmitter.transform.localPosition = Vector3.zero;
|
||||||
|
solarFlareEmitter.transform.localScale = Vector3.one;
|
||||||
|
solarFlareEmitter.name = "SolarFlareEmitter";
|
||||||
|
|
||||||
|
if (starModule.SolarFlareTint != null)
|
||||||
|
{
|
||||||
|
solarFlareEmitter.GetComponent<SolarFlareEmitter>().tint = starModule.SolarFlareTint.ToColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
starGO.transform.position = rootObject.transform.position;
|
||||||
|
starGO.transform.localScale = starModule.Size * Vector3.one;
|
||||||
|
|
||||||
|
if (starModule.Curve != null)
|
||||||
|
{
|
||||||
|
var levelController = starGO.AddComponent<SandLevelController>();
|
||||||
|
var curve = new AnimationCurve();
|
||||||
|
foreach (var pair in starModule.Curve)
|
||||||
|
{
|
||||||
|
curve.AddKey(new Keyframe(pair.Time, starModule.Size * pair.Value));
|
||||||
|
}
|
||||||
|
levelController._scaleCurve = curve;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (starModule.Tint != null)
|
||||||
|
{
|
||||||
|
TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>();
|
||||||
|
|
||||||
var colour = starModule.Tint.ToColor();
|
var colour = starModule.Tint.ToColor();
|
||||||
|
|
||||||
var sun = GameObject.Find("Sun_Body");
|
var sun = GameObject.Find("Sun_Body");
|
||||||
@ -148,37 +189,7 @@ namespace NewHorizons.Builder.Body
|
|||||||
surface.sharedMaterial.SetTexture("_ColorRamp", ImageUtilities.LerpGreyscaleImage(_colorOverTime, adjustedColour, darkenedColor));
|
surface.sharedMaterial.SetTexture("_ColorRamp", ImageUtilities.LerpGreyscaleImage(_colorOverTime, adjustedColour, darkenedColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(starModule.SolarFlareTint != null)
|
return starGO;
|
||||||
solarFlareEmitter.GetComponent<SolarFlareEmitter>().tint = starModule.SolarFlareTint.ToColor();
|
|
||||||
|
|
||||||
starGO.transform.position = planetGO.transform.position;
|
|
||||||
starGO.transform.localScale = starModule.Size * Vector3.one;
|
|
||||||
|
|
||||||
StarController starController = null;
|
|
||||||
if (starModule.SolarLuminosity != 0)
|
|
||||||
{
|
|
||||||
starController = planetGO.AddComponent<StarController>();
|
|
||||||
starController.Light = light;
|
|
||||||
starController.AmbientLight = ambientLight;
|
|
||||||
starController.FaceActiveCamera = faceActiveCamera;
|
|
||||||
starController.CSMTextureCacher = csmTextureCacher;
|
|
||||||
starController.ProxyShadowLight = proxyShadowLight;
|
|
||||||
starController.Intensity = starModule.SolarLuminosity;
|
|
||||||
starController.SunColor = lightColour;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (starModule.Curve != null)
|
|
||||||
{
|
|
||||||
var levelController = starGO.AddComponent<SandLevelController>();
|
|
||||||
var curve = new AnimationCurve();
|
|
||||||
foreach (var pair in starModule.Curve)
|
|
||||||
{
|
|
||||||
curve.AddKey(new Keyframe(pair.Time, starModule.Size * pair.Value));
|
|
||||||
}
|
|
||||||
levelController._scaleCurve = curve;
|
|
||||||
}
|
|
||||||
|
|
||||||
return starController;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using NewHorizons.Utility;
|
using NewHorizons.Utility;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace NewHorizons.Components
|
namespace NewHorizons.Components
|
||||||
@ -6,7 +7,8 @@ namespace NewHorizons.Components
|
|||||||
public class NHProxy : ProxyPlanet
|
public class NHProxy : ProxyPlanet
|
||||||
{
|
{
|
||||||
public string astroName;
|
public string astroName;
|
||||||
public Renderer renderer;
|
public Renderer[] renderers;
|
||||||
|
public TessellatedRenderer[] tessellatedRenderers;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@ -32,7 +34,10 @@ namespace NewHorizons.Components
|
|||||||
public override void ToggleRendering(bool on)
|
public override void ToggleRendering(bool on)
|
||||||
{
|
{
|
||||||
base.ToggleRendering(on);
|
base.ToggleRendering(on);
|
||||||
renderer.enabled = on;
|
foreach (Transform child in transform)
|
||||||
|
{
|
||||||
|
child.gameObject.SetActive(on);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,6 +237,7 @@ namespace NewHorizons.Handlers
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called when updating an existing planet
|
||||||
public static GameObject UpdateBody(NewHorizonsBody body, GameObject go)
|
public static GameObject UpdateBody(NewHorizonsBody body, GameObject go)
|
||||||
{
|
{
|
||||||
Logger.Log($"Updating existing Object {go.name}");
|
Logger.Log($"Updating existing Object {go.name}");
|
||||||
@ -264,6 +265,7 @@ namespace NewHorizons.Handlers
|
|||||||
return go;
|
return go;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only called when making new planets
|
||||||
public static GameObject GenerateBody(NewHorizonsBody body, bool defaultPrimaryToSun = false)
|
public static GameObject GenerateBody(NewHorizonsBody body, bool defaultPrimaryToSun = false)
|
||||||
{
|
{
|
||||||
AstroObject primaryBody;
|
AstroObject primaryBody;
|
||||||
@ -357,6 +359,11 @@ namespace NewHorizons.Handlers
|
|||||||
AstroObjectLocator.RegisterCustomAstroObject(ao);
|
AstroObjectLocator.RegisterCustomAstroObject(ao);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() =>
|
||||||
|
{
|
||||||
|
ProxyBuilder.Make(go, body);
|
||||||
|
});
|
||||||
|
|
||||||
return go;
|
return go;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,6 +376,7 @@ namespace NewHorizons.Handlers
|
|||||||
return sphereOfInfluence;
|
return sphereOfInfluence;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// What is called both on existing planets and new planets
|
||||||
private static GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go, Sector sector, OWRigidbody rb)
|
private static GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go, Sector sector, OWRigidbody rb)
|
||||||
{
|
{
|
||||||
var sphereOfInfluence = GetSphereOfInfluence(body);
|
var sphereOfInfluence = GetSphereOfInfluence(body);
|
||||||
@ -500,11 +508,6 @@ namespace NewHorizons.Handlers
|
|||||||
CloakBuilder.Make(go, sector, rb, body.Config.Base.CloakRadius);
|
CloakBuilder.Make(go, sector, rb, body.Config.Base.CloakRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() =>
|
|
||||||
{
|
|
||||||
ProxyBuilder.Make(go, body);
|
|
||||||
});
|
|
||||||
|
|
||||||
return go;
|
return go;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -206,16 +206,16 @@ namespace NewHorizons.Handlers
|
|||||||
|
|
||||||
private static void RemoveProxy(string name)
|
private static void RemoveProxy(string name)
|
||||||
{
|
{
|
||||||
// if (name.Equals("TowerTwin")) name = "AshTwin";
|
if (name.Equals("TowerTwin")) name = "AshTwin";
|
||||||
// if (name.Equals("CaveTwin")) name = "EmberTwin";
|
if (name.Equals("CaveTwin")) name = "EmberTwin";
|
||||||
// var distantProxy = GameObject.Find(name + "_DistantProxy");
|
var distantProxy = GameObject.Find(name + "_DistantProxy");
|
||||||
// var distantProxyClone = GameObject.Find(name + "_DistantProxy(Clone)");
|
var distantProxyClone = GameObject.Find(name + "_DistantProxy(Clone)");
|
||||||
//
|
|
||||||
// if (distantProxy != null) GameObject.Destroy(distantProxy.gameObject);
|
if (distantProxy != null) GameObject.Destroy(distantProxy.gameObject);
|
||||||
// if (distantProxyClone != null) GameObject.Destroy(distantProxyClone.gameObject);
|
if (distantProxyClone != null) GameObject.Destroy(distantProxyClone.gameObject);
|
||||||
//
|
|
||||||
// if (distantProxy == null && distantProxyClone == null)
|
if (distantProxy == null && distantProxyClone == null)
|
||||||
// Logger.Log($"Couldn't find proxy for {name}");
|
Logger.Log($"Couldn't find proxy for {name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
56
NewHorizons/Patches/ProxyBodyPatches.cs
Normal file
56
NewHorizons/Patches/ProxyBodyPatches.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewHorizons.Patches
|
||||||
|
{
|
||||||
|
[HarmonyPatch]
|
||||||
|
public static class ProxyBodyPatches
|
||||||
|
{
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(ProxyBody), nameof(ProxyBody.Awake))]
|
||||||
|
public static void ProxyBody_Awake(ProxyBody __instance)
|
||||||
|
{
|
||||||
|
// Mobius rly used the wrong event name
|
||||||
|
GlobalMessenger.AddListener("EnterMapView", __instance.OnEnterMapView);
|
||||||
|
GlobalMessenger.AddListener("ExitMapView", __instance.OnExitMapView);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(ProxyBody), nameof(ProxyBody.OnDestroy))]
|
||||||
|
public static void ProxyBody_OnDestroy(ProxyBody __instance)
|
||||||
|
{
|
||||||
|
GlobalMessenger.RemoveListener("EnterMapView", __instance.OnEnterMapView);
|
||||||
|
GlobalMessenger.RemoveListener("ExitMapView", __instance.OnExitMapView);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(ProxyBody), nameof(ProxyBody.OnEnterMapView))]
|
||||||
|
public static void ProxyBody_OnEnterMapView(ProxyBody __instance)
|
||||||
|
{
|
||||||
|
// Set this to false before the method sets the rendering to false so it matches
|
||||||
|
__instance._outOfRange = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mobius why doesn't ProxyOrbiter inherit from ProxyBody
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(ProxyOrbiter), nameof(ProxyOrbiter.Awake))]
|
||||||
|
public static void ProxyOrbiter_Awake(ProxyOrbiter __instance)
|
||||||
|
{
|
||||||
|
// Mobius rly used the wrong event name
|
||||||
|
GlobalMessenger.AddListener("EnterMapView", __instance.OnEnterMapView);
|
||||||
|
GlobalMessenger.AddListener("ExitMapView", __instance.OnExitMapView);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(ProxyOrbiter), nameof(ProxyOrbiter.OnDestroy))]
|
||||||
|
public static void ProxyOrbiter_OnDestroy(ProxyOrbiter __instance)
|
||||||
|
{
|
||||||
|
GlobalMessenger.RemoveListener("EnterMapView", __instance.OnEnterMapView);
|
||||||
|
GlobalMessenger.RemoveListener("ExitMapView", __instance.OnExitMapView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,13 +20,23 @@ namespace NewHorizons.Utility
|
|||||||
Logger.Log($"Already loaded image at path: {path}");
|
Logger.Log($"Already loaded image at path: {path}");
|
||||||
return _loadedTextures[path];
|
return _loadedTextures[path];
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log($"Loading image at path: {path}");
|
Logger.Log($"Loading image at path: {path}");
|
||||||
var data = File.ReadAllBytes(path);
|
try
|
||||||
var texture = new Texture2D(2, 2);
|
{
|
||||||
texture.name = Path.GetFileNameWithoutExtension(path);
|
var data = File.ReadAllBytes(path);
|
||||||
texture.LoadImage(data);
|
var texture = new Texture2D(2, 2);
|
||||||
_loadedTextures.Add(path, texture);
|
texture.name = Path.GetFileNameWithoutExtension(path);
|
||||||
return texture;
|
texture.LoadImage(data);
|
||||||
|
_loadedTextures.Add(path, texture);
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogError($"Exception thrown while loading texture [{filename}]: {ex.Message}, {ex.StackTrace}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ClearCache()
|
public static void ClearCache()
|
||||||
@ -40,7 +50,7 @@ namespace NewHorizons.Utility
|
|||||||
}
|
}
|
||||||
_loadedTextures.Clear();
|
_loadedTextures.Clear();
|
||||||
|
|
||||||
foreach(var texture in _generatedTextures)
|
foreach (var texture in _generatedTextures)
|
||||||
{
|
{
|
||||||
if (texture == null) continue;
|
if (texture == null) continue;
|
||||||
UnityEngine.Object.Destroy(texture);
|
UnityEngine.Object.Destroy(texture);
|
||||||
@ -57,7 +67,7 @@ namespace NewHorizons.Utility
|
|||||||
var y = (int)Mathf.Floor(i / texture.height);
|
var y = (int)Mathf.Floor(i / texture.height);
|
||||||
|
|
||||||
// Needs a black border
|
// Needs a black border
|
||||||
if(x == 0 || y == 0 || x == texture.width-1 || y == texture.height-1)
|
if (x == 0 || y == 0 || x == texture.width - 1 || y == texture.height - 1)
|
||||||
{
|
{
|
||||||
pixels[i].r = 1;
|
pixels[i].r = 1;
|
||||||
pixels[i].g = 1;
|
pixels[i].g = 1;
|
||||||
@ -92,20 +102,20 @@ namespace NewHorizons.Utility
|
|||||||
texture.name = "SlideReelAtlas";
|
texture.name = "SlideReelAtlas";
|
||||||
|
|
||||||
Color[] fillPixels = new Color[size * size * 4 * 4];
|
Color[] fillPixels = new Color[size * size * 4 * 4];
|
||||||
for(int xIndex = 0; xIndex < 4; xIndex++)
|
for (int xIndex = 0; xIndex < 4; xIndex++)
|
||||||
{
|
{
|
||||||
for(int yIndex = 0; yIndex < 4; yIndex++)
|
for (int yIndex = 0; yIndex < 4; yIndex++)
|
||||||
{
|
{
|
||||||
int index = yIndex * 4 + xIndex;
|
int index = yIndex * 4 + xIndex;
|
||||||
var srcTexture = index < textures.Length ? textures[index] : null;
|
var srcTexture = index < textures.Length ? textures[index] : null;
|
||||||
|
|
||||||
for(int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
for(int j = 0; j < size; j++)
|
for (int j = 0; j < size; j++)
|
||||||
{
|
{
|
||||||
var colour = Color.black;
|
var colour = Color.black;
|
||||||
|
|
||||||
if(srcTexture)
|
if (srcTexture)
|
||||||
{
|
{
|
||||||
var srcX = i * srcTexture.width / (float)size;
|
var srcX = i * srcTexture.width / (float)size;
|
||||||
var srcY = j * srcTexture.height / (float)size;
|
var srcY = j * srcTexture.height / (float)size;
|
||||||
@ -118,11 +128,11 @@ namespace NewHorizons.Utility
|
|||||||
var x = xIndex * size + i;
|
var x = xIndex * size + i;
|
||||||
// Want it to start from the first row from the bottom then go down then modulo around idk
|
// Want it to start from the first row from the bottom then go down then modulo around idk
|
||||||
// 5 because no pos mod idk
|
// 5 because no pos mod idk
|
||||||
var y = ((5 - yIndex)%4) * size + j;
|
var y = ((5 - yIndex) % 4) * size + j;
|
||||||
|
|
||||||
var pixelIndex = x + y * (size * 4);
|
var pixelIndex = x + y * (size * 4);
|
||||||
|
|
||||||
if(pixelIndex < fillPixels.Length && pixelIndex >= 0) fillPixels[pixelIndex] = colour;
|
if (pixelIndex < fillPixels.Length && pixelIndex >= 0) fillPixels[pixelIndex] = colour;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,7 +159,7 @@ namespace NewHorizons.Utility
|
|||||||
{
|
{
|
||||||
var fillColor = new Color(0, 0, 0, 0);
|
var fillColor = new Color(0, 0, 0, 0);
|
||||||
|
|
||||||
if(pixels[x + y * texture.width].a == 1 && CloseToTransparent(pixels, texture.width, texture.height, x, y, thickness))
|
if (pixels[x + y * texture.width].a == 1 && CloseToTransparent(pixels, texture.width, texture.height, x, y, thickness))
|
||||||
{
|
{
|
||||||
fillColor = color;
|
fillColor = color;
|
||||||
}
|
}
|
||||||
@ -168,10 +178,10 @@ namespace NewHorizons.Utility
|
|||||||
private static bool CloseToTransparent(Color[] pixels, int width, int height, int x, int y, int thickness)
|
private static bool CloseToTransparent(Color[] pixels, int width, int height, int x, int y, int thickness)
|
||||||
{
|
{
|
||||||
// Check nearby
|
// Check nearby
|
||||||
var minX = Math.Max(0, x - thickness/2);
|
var minX = Math.Max(0, x - thickness / 2);
|
||||||
var minY = Math.Max(0, y - thickness/2);
|
var minY = Math.Max(0, y - thickness / 2);
|
||||||
var maxX = Math.Min(width, x + thickness/2);
|
var maxX = Math.Min(width, x + thickness / 2);
|
||||||
var maxY = Math.Min(height, y + thickness/2);
|
var maxY = Math.Min(height, y + thickness / 2);
|
||||||
|
|
||||||
for (int i = minX; i < maxX; i++)
|
for (int i = minX; i < maxX; i++)
|
||||||
{
|
{
|
||||||
@ -229,7 +239,7 @@ namespace NewHorizons.Utility
|
|||||||
tex.name = "Clear";
|
tex.name = "Clear";
|
||||||
Color fillColor = Color.clear;
|
Color fillColor = Color.clear;
|
||||||
Color[] fillPixels = new Color[tex.width * tex.height];
|
Color[] fillPixels = new Color[tex.width * tex.height];
|
||||||
for(int i = 0; i < fillPixels.Length; i++)
|
for (int i = 0; i < fillPixels.Length; i++)
|
||||||
{
|
{
|
||||||
fillPixels[i] = fillColor;
|
fillPixels[i] = fillColor;
|
||||||
}
|
}
|
||||||
@ -248,7 +258,7 @@ namespace NewHorizons.Utility
|
|||||||
Color[] fillPixels = new Color[tex.width * tex.height];
|
Color[] fillPixels = new Color[tex.width * tex.height];
|
||||||
for (int i = 0; i < tex.width; i++)
|
for (int i = 0; i < tex.width; i++)
|
||||||
{
|
{
|
||||||
for(int j = 0; j < tex.height; j++)
|
for (int j = 0; j < tex.height; j++)
|
||||||
{
|
{
|
||||||
var x = i + (src.width - width) / 2;
|
var x = i + (src.width - width) / 2;
|
||||||
var y = j + (src.height - height) / 2;
|
var y = j + (src.height - height) / 2;
|
||||||
@ -274,7 +284,7 @@ namespace NewHorizons.Utility
|
|||||||
var g = 0f;
|
var g = 0f;
|
||||||
var b = 0f;
|
var b = 0f;
|
||||||
var length = pixels.Length;
|
var length = pixels.Length;
|
||||||
for(int i = 0; i < pixels.Length; i++)
|
for (int i = 0; i < pixels.Length; i++)
|
||||||
{
|
{
|
||||||
var color = pixels[i];
|
var color = pixels[i];
|
||||||
r += (float)color.r / length;
|
r += (float)color.r / length;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user