diff --git a/NewHorizons/AssetBundle/shader b/NewHorizons/AssetBundle/shader index 148eca35..7f913501 100644 Binary files a/NewHorizons/AssetBundle/shader and b/NewHorizons/AssetBundle/shader differ diff --git a/NewHorizons/AssetBundle/shader.manifest b/NewHorizons/AssetBundle/shader.manifest index cb6d8e25..29c8e572 100644 --- a/NewHorizons/AssetBundle/shader.manifest +++ b/NewHorizons/AssetBundle/shader.manifest @@ -1,9 +1,9 @@ ManifestFileVersion: 0 -CRC: 3597037522 +CRC: 2524157958 Hashes: AssetFileHash: serializedVersion: 2 - Hash: 33678ea445c06b269454371064cc3a5c + Hash: 882ab688c937b5592f590a313cfc0529 TypeTreeHash: serializedVersion: 2 Hash: 6370d3f9de9eca57f523bce048404a46 @@ -14,5 +14,7 @@ ClassTypes: Assets: - Assets/Shaders/SphereTextureWrapper.shader - Assets/Shaders/Ring.shader +- Assets/Shaders/UnlitRing1Pixel.shader - Assets/Shaders/UnlitTransparent.shader +- Assets/Shaders/Ring1Pixel.shader Dependencies: [] diff --git a/NewHorizons/Builder/Body/RingBuilder.cs b/NewHorizons/Builder/Body/RingBuilder.cs index af987b42..e62d92c9 100644 --- a/NewHorizons/Builder/Body/RingBuilder.cs +++ b/NewHorizons/Builder/Body/RingBuilder.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; +using NewHorizons.Utility; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.Body @@ -13,10 +14,15 @@ namespace NewHorizons.Builder.Body static class RingBuilder { public static Shader RingShader; - public static Shader UnlitShader; + public static Shader RingShader1Pixel; + public static Shader UnlitRingShader; + public static Shader UnlitRingShader1Pixel; public static GameObject Make(GameObject body, RingModule ring, IModAssets assets) { + // Properly lit shader doesnt work yet + ring.Unlit = true; + Texture2D ringTexture; try { @@ -41,20 +47,84 @@ namespace NewHorizons.Builder.Body var texture = ringTexture; if (RingShader == null) RingShader = Main.ShaderBundle.LoadAsset("Assets/Shaders/Ring.shader"); - if (UnlitShader == null) UnlitShader = Main.ShaderBundle.LoadAsset("Assets/Shaders/UnlitTransparent.shader"); + if (UnlitRingShader == null) UnlitRingShader = Main.ShaderBundle.LoadAsset("Assets/Shaders/UnlitTransparent.shader"); + if (RingShader1Pixel == null) RingShader1Pixel = Main.ShaderBundle.LoadAsset("Assets/Shaders/Ring1Pixel.shader"); + if (UnlitRingShader1Pixel == null) UnlitRingShader1Pixel = Main.ShaderBundle.LoadAsset("Assets/Shaders/UnlitRing1Pixel.shader"); + + bool doubleSided = false; + var mat = new Material(ring.Unlit ? UnlitRingShader : RingShader); + if(texture.width == 1) + { + mat = new Material(ring.Unlit ? UnlitRingShader1Pixel : RingShader1Pixel); + mat.SetFloat("_InnerRadius", 0); + doubleSided = true; + } + ringMR.receiveShadows = !ring.Unlit; - var mat = new Material(ring.Unlit ? UnlitShader : RingShader); mat.mainTexture = texture; mat.renderQueue = 2895; ringMR.material = mat; // Make mesh - var segments = (int)Mathf.Clamp(ring.OuterRadius, 20, 2000); + var segments = (int)Mathf.Clamp(ring.OuterRadius, 20, 2000); + + //BuildQuadMesh(ringMesh, ring.OuterRadius * 2); + //BuildCircleMesh(ringMesh, segments, ring.OuterRadius); + //ringGO.AddComponent(); + BuildRingMesh(ringMesh, segments, ring.InnerRadius, ring.OuterRadius); + if(ring.RotationSpeed != 0) + { + var rot = ringGO.AddComponent(); + rot._degreesPerSecond = ring.RotationSpeed; + rot._localAxis = Vector3.down; + } + return ringGO; } + public static void BuildQuadMesh(Mesh mesh, float width) + { + Vector3[] vertices; + int[] tri; + Vector3[] normals; + Vector2[] uv; + + vertices = new Vector3[4]; + tri = new int[6]; + normals = new Vector3[4]; + uv = new Vector2[4]; + + vertices[0] = new Vector3(-width / 2, 0, -width / 2); + vertices[1] = new Vector3(width / 2, 0, -width / 2); + vertices[2] = new Vector3(-width / 2, 0, width / 2); + vertices[3] = new Vector3(width / 2, 0, width / 2); + + tri[0] = 0; + tri[1] = 2; + tri[2] = 1; + + tri[3] = 2; + tri[4] = 3; + tri[5] = 1; + + normals[0] = Vector3.up; + normals[1] = Vector3.up; + normals[2] = Vector3.up; + normals[3] = Vector3.up; + + uv[0] = new Vector2(0, 0); + uv[1] = new Vector2(1, 0); + uv[2] = new Vector2(0, 1); + uv[3] = new Vector2(1, 1); + + mesh.vertices = vertices; + mesh.triangles = tri; + mesh.normals = normals; + mesh.uv = uv; + } + // Thank you https://github.com/boardtobits/planet-ring-mesh/blob/master/PlanetRing.cs public static void BuildRingMesh(Mesh ringMesh, int segments, float innerRadius, float outerRadius) { @@ -72,8 +142,10 @@ namespace NewHorizons.Builder.Body vertices[i * 2] = vertices[i * 2 + halfway] = new Vector3(x, 0f, z) * outerRadius; vertices[i * 2 + 1] = vertices[i * 2 + 1 + halfway] = new Vector3(x, 0f, z) * innerRadius; - uv[i * 2] = uv[i * 2 + halfway] = new Vector2(progress, 0f); - uv[i * 2 + 1] = uv[i * 2 + 1 + halfway] = new Vector2(progress, 1f); + //uv[i * 2] = uv[i * 2 + halfway] = new Vector2(progress, 0f); + //uv[i * 2 + 1] = uv[i * 2 + 1 + halfway] = new Vector2(progress, 1f); + uv[i * 2] = uv[i * 2 + halfway] = (new Vector2(x, z) / 2f) + Vector2.one * 0.5f; + uv[i * 2 + 1] = uv[i * 2 + 1 + halfway] = new Vector2(0.5f, 0.5f); if (i != segments) { @@ -95,5 +167,40 @@ namespace NewHorizons.Builder.Body ringMesh.uv = uv; ringMesh.RecalculateNormals(); } - } + + public static void BuildCircleMesh(Mesh mesh, int segments, float outerRadius) + { + float angleStep = 360.0f / (float)segments; + List vertexList = new List(); + List triangleList = new List(); + List uv = new List(); + Quaternion quaternion = Quaternion.Euler(0.0f, angleStep, 0f); + // Make first triangle. + vertexList.Add(new Vector3(0.0f, 0.0f, 0.0f)); // 1. Circle center. + vertexList.Add(new Vector3(0.0f, 0f, outerRadius)); // 2. First vertex on circle outline (radius = 0.5f) + vertexList.Add(quaternion * vertexList[1]); // 3. First vertex on circle outline rotated by angle) + // Add triangle indices. + uv.Add(new Vector2(0.5f, 0.5f)); + uv.Add(new Vector2(0.5f, 1f)); + uv.Add(quaternion * uv[1]); + + triangleList.Add(0); + triangleList.Add(1); + triangleList.Add(2); + for (int i = 0; i < segments - 1; i++) + { + triangleList.Add(0); // Index of circle center. + triangleList.Add(vertexList.Count - 1); + triangleList.Add(vertexList.Count); + vertexList.Add(quaternion * vertexList[vertexList.Count - 1]); + uv.Add(quaternion * (uv[uv.Count - 1] - Vector2.one * 0.5f) + Vector3.one * 0.5f); + } + + mesh.vertices = vertexList.ToArray(); + mesh.triangles = triangleList.ToArray(); + mesh.uv = uv.ToArray(); + mesh.RecalculateNormals(); + + } + } } diff --git a/NewHorizons/Components/ShipLogStarChartMode.cs b/NewHorizons/Components/ShipLogStarChartMode.cs index 25a2b5d4..aa64f160 100644 --- a/NewHorizons/Components/ShipLogStarChartMode.cs +++ b/NewHorizons/Components/ShipLogStarChartMode.cs @@ -247,7 +247,7 @@ namespace NewHorizons.Components public string GetTargetStarSystem() { - return _target.name; + return _target?.name; } } } diff --git a/NewHorizons/Components/ShipWarpController.cs b/NewHorizons/Components/ShipWarpController.cs new file mode 100644 index 00000000..16b39f65 --- /dev/null +++ b/NewHorizons/Components/ShipWarpController.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NewHorizons.Components +{ + public class ShipWarpController : MonoBehaviour + { + private SingularityController _singularityController; + private OWAudioSource _oneShotSource; + + public void Start() + { + GameObject singularityGO = GameObject.Instantiate(GameObject.Find("TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_TT/Prefab_NOM_WarpTransmitter (1)/BlackHole/BlackHoleSingularity"), GameObject.Find("Ship_Body").transform); + singularityGO.transform.localPosition = new Vector3(0f, 0f, 5f); + singularityGO.transform.localScale = Vector3.one * 10f; + _singularityController = singularityGO.GetComponent(); + + _oneShotSource = singularityGO.AddComponent(); + } + + public void WarpIn() + { + _oneShotSource.PlayOneShot(global::AudioType.VesselSingularityCollapse, 1f); + } + + public void WarpOut() + { + _oneShotSource.PlayOneShot(global::AudioType.VesselSingularityCreate, 1f); + _singularityController.Create(); + } + } +} diff --git a/NewHorizons/External/RingModule.cs b/NewHorizons/External/RingModule.cs index bcb35531..91b22c33 100644 --- a/NewHorizons/External/RingModule.cs +++ b/NewHorizons/External/RingModule.cs @@ -13,6 +13,7 @@ namespace NewHorizons.External public float Inclination { get; set; } public float LongitudeOfAscendingNode { get; set; } public string Texture { get; set; } - public bool Unlit { get; set; } = true; + public bool Unlit { get; set; } = false; + public float RotationSpeed { get; set; } = 0f; } } diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 13cd3cdd..27015f96 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -37,9 +37,9 @@ namespace NewHorizons private string _currentStarSystem = "SolarSystem"; private bool _isChangingStarSystem = false; - private bool _warpIn = false; + private bool _isWarping = false; - private SingularityController shipSingularity; + private ShipWarpController _shipWarpController; public override object GetApi() { @@ -195,13 +195,10 @@ namespace NewHorizons var map = GameObject.FindObjectOfType(); if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f; - GameObject singularityGO = GameObject.Instantiate(GameObject.Find("TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_TT/Prefab_NOM_WarpTransmitter (1)/BlackHole/BlackHoleSingularity"), GameObject.Find("Ship_Body").transform); - singularityGO.transform.localPosition = new Vector3(0f, 0f, 5f); - singularityGO.transform.localScale = Vector3.one * 10f; - shipSingularity = singularityGO.GetComponent(); + _shipWarpController = GameObject.Find("Ship_Body").AddComponent(); - if(_warpIn) Instance.ModHelper.Events.Unity.FireInNUpdates(() => WarpInShip(), 3); - _warpIn = false; + if(_isWarping) Instance.ModHelper.Events.Unity.FireInNUpdates(() => _shipWarpController.WarpIn(), 3); + _isWarping = false; } #region TitleScreen @@ -546,12 +543,12 @@ namespace NewHorizons #endregion Body generation #region Change star system - public void ChangeCurrentStarSystem(string newStarSystem, bool warpIn = false) + public void ChangeCurrentStarSystem(string newStarSystem, bool warp = false) { - shipSingularity.Create(); + _shipWarpController.WarpOut(); _currentStarSystem = newStarSystem; _isChangingStarSystem = true; - _warpIn = warpIn; + _isWarping = warp; Locator.GetDeathManager().KillPlayer(DeathType.Meditation); LoadManager.LoadSceneAsync(OWScene.SolarSystem, true, LoadManager.FadeType.ToBlack, 0.1f, true); } @@ -561,13 +558,6 @@ namespace NewHorizons // We reset the solar system on death (unless we just killed the player) if (!_isChangingStarSystem) _currentStarSystem = "SolarSystem"; } - - private void WarpInShip() - { - var ship = GameObject.Find("Ship_Body"); - Teleportation.teleportPlayerToShip(); - ship.GetComponent().OnPressInteract(); - } #endregion Change star system } diff --git a/NewHorizons/Utility/Patches.cs b/NewHorizons/Utility/Patches.cs index d071e567..46fd29bc 100644 --- a/NewHorizons/Utility/Patches.cs +++ b/NewHorizons/Utility/Patches.cs @@ -392,7 +392,10 @@ namespace NewHorizons.Utility { var targetSystem = ShipLogBuilder.ShipLogStarChartMode.GetTargetStarSystem(); if (targetSystem != null) + { Main.Instance.ChangeCurrentStarSystem(targetSystem, true); + return false; + } } return true; }