diff --git a/version2/Assets/Editor/MakeLayers.cs b/version2/Assets/Editor/MakeLayers.cs index fe3dc036..9e93f6ad 100644 --- a/version2/Assets/Editor/MakeLayers.cs +++ b/version2/Assets/Editor/MakeLayers.cs @@ -3,16 +3,16 @@ using UnityEditor; [InitializeOnLoad] -public class Tags { +public static class MakeLayers { // STARTUP - static Tags() { + static MakeLayers() { CreateLayer(); } // Creates a new layer - static void CreateLayer() { + private static void CreateLayer() { SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]); SerializedProperty it = tagManager.GetIterator(); @@ -24,17 +24,17 @@ static void CreateLayer() { it.stringValue = "Camera Layer "+(a-7); } } + } - for(int i=0;i<32;i++) { - for(int b=0;b<32;b++) { - if(b != i && b != 0) - Physics.IgnoreLayerCollision (b, i, true);//Physics.GetIgnoreLayerCollision (b,i)); - else if (b == 0) - Physics.IgnoreLayerCollision (b, i, false); - } + for(int i=0;i<32;i++) { + for(int b=0;b<32;b++) { + if(b != i && b != 0) + Physics.IgnoreLayerCollision (b, i, true);//Physics.GetIgnoreLayerCollision (b,i)); + else if (b == 0) + Physics.IgnoreLayerCollision (b, i, false); } } tagManager.ApplyModifiedProperties(); } -} \ No newline at end of file +} diff --git a/version2/Assets/Scripts/tests/BodyElements.cs b/version2/Assets/Scripts/tests/BodyElements.cs index ab13dbda..ab8c4a40 100644 --- a/version2/Assets/Scripts/tests/BodyElements.cs +++ b/version2/Assets/Scripts/tests/BodyElements.cs @@ -1,6 +1,5 @@ using UnityEngine; using System; -using System.Collections; using System.Collections.Generic; using Elements; diff --git a/version2/Assets/Scripts/tests/CreateCameras.cs b/version2/Assets/Scripts/tests/CreateCameras.cs index 02537c6b..8c4dfc57 100644 --- a/version2/Assets/Scripts/tests/CreateCameras.cs +++ b/version2/Assets/Scripts/tests/CreateCameras.cs @@ -1,21 +1,14 @@ using UnityEngine; -using System.Collections; -using System.Collections.Generic; -using Elements; -using SimpleJSON; -using BodyElements; -using ImportData; -using System.IO; -using CustomMath; +[DisallowMultipleComponent] public class CreateCameras : MonoBehaviour { - int camDepth = 20; + [SerializeField] private int camDepth = 20; void Awake () { for (int i=1; i<19; i++) { Camera cam = new GameObject().AddComponent(); cam.depth = camDepth - i; - cam.transform.parent = transform; + cam.transform.SetParent(transform, true); cam.transform.position = new Vector3(0f,0f,0f); cam.name = "Camera "+i; cam.farClipPlane = 20000f; @@ -24,7 +17,7 @@ void Awake () { cam.clearFlags = CameraClearFlags.Depth; // Add as a camera layer else cam.clearFlags = CameraClearFlags.Nothing; // Background layer - cam.camera.cullingMask = 1 << i+7; + cam.cullingMask = 1 << i+7; cam.gameObject.layer = i+7; cam.tag = "MainCamera"; Rigidbody _cameraRigidbody = cam.gameObject.AddComponent(); diff --git a/version2/Assets/Scripts/tests/CreateElements.cs b/version2/Assets/Scripts/tests/CreateElements.cs index c5968845..d55f462a 100644 --- a/version2/Assets/Scripts/tests/CreateElements.cs +++ b/version2/Assets/Scripts/tests/CreateElements.cs @@ -1,6 +1,4 @@ using UnityEngine; -using System.Collections; -using Elements; public class CreateElements : MonoBehaviour { diff --git a/version2/Assets/Scripts/tests/CreateSolarSystems.cs b/version2/Assets/Scripts/tests/CreateSolarSystems.cs index 841d35ff..a23ec252 100644 --- a/version2/Assets/Scripts/tests/CreateSolarSystems.cs +++ b/version2/Assets/Scripts/tests/CreateSolarSystems.cs @@ -1,13 +1,12 @@ using UnityEngine; using System; -using System.Collections; using System.Collections.Generic; -using Elements; -using SimpleJSON; +using System.Globalization; using BodyElements; -using ImportData; -using System.IO; using CustomMath; +using Elements; +using ImportData; +using SimpleJSON; [System.Serializable] @@ -23,6 +22,7 @@ public class PlanetList { public string name; public Planet key; public GameObject value; + public Vector3d positionInOrbit; } @@ -31,9 +31,11 @@ public class MoonList { public string name; public Moon key; public GameObject value; + public Vector3d positionInOrbit; } +[DisallowMultipleComponent] public class CreateSolarSystems : MonoBehaviour { public List stars = new List(); @@ -44,8 +46,7 @@ public class CreateSolarSystems : MonoBehaviour { string JSONData; // Holds the data.json file data void Awake () { - JSONData = Data.data.ReadToEnd (); // Read from the data.json file - Data.data.Close (); + JSONData = Data.LoadJson(); // Read from the data.json file importedData = JSON.Parse(JSONData); // Parse the data into a formatted string variable @@ -57,12 +58,12 @@ void Awake () { _star.Name = importedData ["star"] [iteratorA] ["name"]; _star.RightAscension = importedData ["star"] [iteratorA] ["rightAscension"]; _star.Declination = importedData ["star"] [iteratorA] ["declination"]; - _star.Mass = new Element ("Stellar Mass", double.Parse(importedData ["star"] [iteratorA]["stellarMass"]), "Kg", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); - _star.Radius = new Element ("Stellar Radius", double.Parse(importedData ["star"] [iteratorA] ["stellarRadius"]), "meter", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); + _star.Mass = new Element ("Stellar Mass", ParseDouble(importedData ["star"] [iteratorA]["stellarMass"]), "Kg", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); + _star.Radius = new Element ("Stellar Radius", ParseDouble(importedData ["star"] [iteratorA] ["stellarRadius"]), "meter", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); //_star.Radius.Value *= 100d; // An example of how to multiply by Stellar Radii - _star.Distance = new Element("Distance", double.Parse(importedData ["star"] [iteratorA] ["distance"]), "meter", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); - _star.Luminosity = new Element("Optical Magnitude", double.Parse(importedData ["star"] [iteratorA] ["opticalMagnitude"]), "lum", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); - _star.Temperature = new Element("Temperature", double.Parse(importedData ["star"] [iteratorA] ["temperature"]), "celcius", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); + _star.Distance = new Element("Distance", ParseDouble(importedData ["star"] [iteratorA] ["distance"]), "meter", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); + _star.Luminosity = new Element("Optical Magnitude", ParseDouble(importedData ["star"] [iteratorA] ["opticalMagnitude"]), "lum", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); + _star.Temperature = new Element("Temperature", ParseDouble(importedData ["star"] [iteratorA] ["temperature"]), "celcius", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); _star.Distance.ToM(); @@ -93,10 +94,13 @@ void Awake () { // Generate Planets - for (int iteratorB=0; iteratorB < importedData["star"][iteratorA]["planets"].Count; iteratorB++) { + JSONNode planetDataList = importedData["star"][iteratorA]["planets"]; + for (int iteratorB=0; iteratorB < planetDataList.Count; iteratorB++) { + JSONNode planetData = planetDataList[iteratorB]; Planet _planet = new Planet(); - _planet.Name = importedData["star"][iteratorA]["planets"][iteratorB]["name"]; - _planet.DateLastUpdated = importedData["star"][iteratorA]["planets"][iteratorB]["dateLastUpdate"]; + _planet.Name = planetData["name"]; + _planet.DateLastUpdated = GetString(planetData, "dateLastUpdate", _star.DateLastUpdated); + SetOrbitElements(_planet, planetData, "Planet"); GameObject _planetSystem = new GameObject("Planetary System: "+_planet.Name); _star.ChildPlanets.Add (_planetSystem); @@ -106,12 +110,16 @@ void Awake () { _planets_.name = _planet.Name; _planets_.key = _planet; _planets_.value = _planetSystem; + _planets_.positionInOrbit = CalculateOrbitPosition(_planet, iteratorB, planetDataList.Count); planets.Add (_planets_); - for (int iteratorC=0; iteratorC < importedData["star"][iteratorA]["planets"][iteratorB]["moons"].Count; iteratorC++) { + JSONNode moonDataList = planetData["moons"]; + for (int iteratorC=0; iteratorC < moonDataList.Count; iteratorC++) { + JSONNode moonData = moonDataList[iteratorC]; Moon _moon = new Moon(); - _moon.Name = importedData["star"][iteratorA]["planets"][iteratorB]["moons"][iteratorC]["name"]; - _moon.DateLastUpdated = importedData["star"][iteratorA]["planets"][iteratorB]["moons"][iteratorC]["dateLastUpdate"]; + _moon.Name = moonData["name"]; + _moon.DateLastUpdated = GetString(moonData, "dateLastUpdate", _planet.DateLastUpdated); + SetOrbitElements(_moon, moonData, "Moon"); GameObject _moonSystem = new GameObject("Moon System: "+_moon.Name); _planet.ChildMoons.Add(_moonSystem); @@ -123,6 +131,7 @@ void Awake () { _moons_.name = _moon.Name; _moons_.key = _moon; _moons_.value = _moonSystem; + _moons_.positionInOrbit = CalculateOrbitPosition(_moon, iteratorC, moonDataList.Count); moons.Add (_moons_); } } @@ -130,6 +139,96 @@ void Awake () { } + + private static string GetString(JSONNode source, string key, string fallback) { + JSONNode node = source[key]; + if (HasJsonValue(node)) + return node.Value; + return string.IsNullOrEmpty(fallback) ? "Unknown" : fallback; + } + + private static void SetOrbitElements(OrbitElement orbitElement, JSONNode source, string bodyType) { + string lastUpdated = string.IsNullOrEmpty(orbitElement.DateLastUpdated) ? "Unknown" : orbitElement.DateLastUpdated; + + orbitElement.SemiMajorAxis = CreateElement(source, "semiMajorAxis", bodyType + " Semi-major Axis", "au", lastUpdated); + orbitElement.Eccentricity = CreateElement(source, "eccentricity", bodyType + " Eccentricity", "ratio", lastUpdated); + orbitElement.Inclination = CreateElement(source, "inclination", bodyType + " Inclination", "degree", lastUpdated); + orbitElement.ArgumentOfPariapsis = CreateElement(source, "argumentOfPariapsis", bodyType + " Argument of Pariapsis", "degree", lastUpdated); + orbitElement.Longitude = CreateElement(source, "longitude", bodyType + " Longitude of Ascending Node", "degree", lastUpdated); + orbitElement.MeanAnomaly = CreateElement(source, "meanAnomaly", bodyType + " Mean Anomaly", "degree", lastUpdated); + orbitElement.Period = CreateElement(source, "orbitalPeriod", bodyType + " Orbital Period", "day", lastUpdated); + orbitElement.EccentricAnomaly = CreateElement(source, "eccentricAnomaly", bodyType + " Eccentric Anomaly", "degree", lastUpdated); + orbitElement.TrueAnomaly = CreateElement(source, "trueAnomaly", bodyType + " True Anomaly", "degree", lastUpdated); + } + + private static Element CreateElement(JSONNode source, string key, string name, string measurement, string lastUpdated) { + JSONNode node = source[key]; + if (!HasJsonValue(node)) + return null; + + return new Element(name, ParseDouble(node), measurement, 0.0d, "SI", "StarTography 1.0", lastUpdated); + } + + private static bool HasJsonValue(JSONNode node) { + return node != null && !string.IsNullOrEmpty(node.Value); + } + + private static double ParseDouble(JSONNode node) { + return double.Parse(node.Value, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture); + } + + private static Vector3d CalculateOrbitPosition(OrbitElement orbitElement, int siblingIndex, int siblingCount) { + if (orbitElement == null || orbitElement.SemiMajorAxis == null) + return new Vector3d(); + + double semiMajorAxis = Maths.InMM(orbitElement.SemiMajorAxis); + double eccentricity = ClampEccentricity(GetElementValue(orbitElement.Eccentricity, 0d)); + double inclination = GetElementValue(orbitElement.Inclination, 0d) * Maths.Deg2Rad; + double longitude = GetElementValue(orbitElement.Longitude, 0d) * Maths.Deg2Rad; + double argumentOfPariapsis = GetElementValue(orbitElement.ArgumentOfPariapsis, 0d) * Maths.Deg2Rad; + double trueAnomaly = GetOrbitAngleDegrees(orbitElement, siblingIndex, siblingCount) * Maths.Deg2Rad; + + double orbitalRadius = semiMajorAxis * (1d - (eccentricity * eccentricity)) / (1d + (eccentricity * Math.Cos(trueAnomaly))); + double angleInOrbit = argumentOfPariapsis + trueAnomaly; + + double cosLongitude = Math.Cos(longitude); + double sinLongitude = Math.Sin(longitude); + double cosInclination = Math.Cos(inclination); + double sinInclination = Math.Sin(inclination); + double cosAngle = Math.Cos(angleInOrbit); + double sinAngle = Math.Sin(angleInOrbit); + + return new Vector3d( + orbitalRadius * ((cosLongitude * cosAngle) - (sinLongitude * sinAngle * cosInclination)), + orbitalRadius * ((sinLongitude * cosAngle) + (cosLongitude * sinAngle * cosInclination)), + orbitalRadius * (sinAngle * sinInclination) + ); + } + + private static double GetOrbitAngleDegrees(OrbitElement orbitElement, int siblingIndex, int siblingCount) { + if (orbitElement.TrueAnomaly != null) + return orbitElement.TrueAnomaly.Value; + if (orbitElement.MeanAnomaly != null) + return orbitElement.MeanAnomaly.Value; + if (orbitElement.EccentricAnomaly != null) + return orbitElement.EccentricAnomaly.Value; + if (siblingCount <= 0) + return 0d; + + return (360d * siblingIndex) / siblingCount; + } + + private static double GetElementValue(Element element, double fallback) { + return element == null ? fallback : element.Value; + } + + private static double ClampEccentricity(double eccentricity) { + if (double.IsNaN(eccentricity)) + return 0d; + + return Math.Min(Math.Max(eccentricity, 0d), 0.999999d); + } + void Start() { @@ -138,15 +237,15 @@ void Start() { star.value.transform.position = star.positionInSpace; GameObject _starGameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); // Create the Star object _starGameObject.name = "Star: "+star.name; - _starGameObject.transform.parent = star.value.transform; - _starGameObject.transform.position = star.value.transform.position; + _starGameObject.transform.SetParent(star.value.transform, false); + _starGameObject.transform.localPosition = Vector3.zero; SphereCollider sphereCollider = _starGameObject.GetComponent(); sphereCollider.isTrigger = false; sphereCollider.radius = 1f; GameObject _starDistanceColliders = new GameObject("Star: "+star.name+": Distance Colliders"); - _starDistanceColliders.transform.parent = star.value.transform; - _starDistanceColliders.transform.position = star.value.transform.position; + _starDistanceColliders.transform.SetParent(star.value.transform, false); + _starDistanceColliders.transform.localPosition = Vector3.zero; Element _starSize = new Element("Radius of the Star", star.key.Radius.Value, "stellarRadius", 0.0d, "si", "Allen's Astrophysical Quantities 4th Edition", star.key.DateLastUpdated); Debug.Log ("Before: "+_starSize.Name+" "+_starSize.Value+" "+_starSize.Measurement); @@ -166,8 +265,8 @@ void Start() { colliderRadiusScale = 10f * Mathf.Exp ((i-3)/2f); GameObject _starDistanceCollider = new GameObject("Star: "+star.name+": Distance Collider "+i); - _starDistanceCollider.transform.parent = _starDistanceColliders.transform; - _starDistanceCollider.transform.position = star.value.transform.position; + _starDistanceCollider.transform.SetParent(_starDistanceColliders.transform, false); + _starDistanceCollider.transform.localPosition = Vector3.zero; _starDistanceCollider.transform.localScale = new Vector3(1f,1f,1f); Rigidbody _sphereRigidbody = _starDistanceCollider.AddComponent(); _sphereRigidbody.useGravity = false; @@ -180,12 +279,12 @@ void Start() { // Prepare the planetary system parent foreach (PlanetList planet in planets) { - planet.value.transform.parent = planet.key.ParentStar.transform; - planet.value.transform.position = planet.key.ParentStar.transform.position; + planet.value.transform.SetParent(planet.key.ParentStar.transform, false); + planet.value.transform.localPosition = planet.positionInOrbit; GameObject _planetGameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); // Create the Planet object _planetGameObject.name = "Planet: "+planet.name; - _planetGameObject.transform.parent = planet.value.transform; - _planetGameObject.transform.position = planet.value.transform.position; + _planetGameObject.transform.SetParent(planet.value.transform, false); + _planetGameObject.transform.localPosition = Vector3.zero; SphereCollider sphereCollider = _planetGameObject.GetComponent(); sphereCollider.isTrigger = false; sphereCollider.radius = 1f; @@ -194,12 +293,12 @@ void Start() { // Prepare the moon system parent foreach (MoonList moon in moons) { - moon.value.transform.parent = moon.key.ParentPlanet.transform; - moon.value.transform.position = moon.key.ParentPlanet.transform.position; + moon.value.transform.SetParent(moon.key.ParentPlanet.transform, false); + moon.value.transform.localPosition = moon.positionInOrbit; GameObject _moonGameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); // Create the Moon object _moonGameObject.name = "Moon: "+moon.name; - _moonGameObject.transform.parent = moon.value.transform; - _moonGameObject.transform.position = moon.value.transform.position; + _moonGameObject.transform.SetParent(moon.value.transform, false); + _moonGameObject.transform.localPosition = Vector3.zero; SphereCollider sphereCollider = _moonGameObject.GetComponent(); sphereCollider.isTrigger = false; sphereCollider.radius = 1f; diff --git a/version2/Assets/Scripts/tests/Elements.cs b/version2/Assets/Scripts/tests/Elements.cs index ad536bfe..ae9d1fe5 100644 --- a/version2/Assets/Scripts/tests/Elements.cs +++ b/version2/Assets/Scripts/tests/Elements.cs @@ -1,6 +1,7 @@ using UnityEngine; using System; using System.Collections; +using System.Globalization; using CustomMath; using System.Linq; @@ -36,29 +37,29 @@ public RightAscension(string HourMinSec) { * '00:42.5' * '00 42 30' */ - string[] _words = new string[] { "" }; - double[] _values = new double[4]; - - if (HourMinSec.Split (new char[] { 'h', 'm', 's' }).Length == 4) { - _words = HourMinSec.Split (new char[] { 'h', 'm', 's' }); - } else if(HourMinSec.Split (new char[] { 'h', '.', 'm' }).Length == 4) { - _words = HourMinSec.Split (new char[] { 'h', '.', 'm' }); - _words[2] = ((Convert.ToDouble(_words[2])/10) * 60).ToString(); // Convert fraction of minute to seconds - } else if(HourMinSec.Split (new char[] { ':', '.' }).Length == 3) { - _words = HourMinSec.Split (new char[] { ':', '.' }); - _words[2] = ((Convert.ToDouble(_words[2])/10) * 60).ToString(); // Convert fraction of minute to seconds - } else if(HourMinSec.Split (new char[] { ' ' }).Length == 3) { - _words = HourMinSec.Split (new char[] { ' ' }); - } + string cleaned = HourMinSec.Trim().ToLowerInvariant(); + cleaned = cleaned.Replace("h", " ").Replace("m", " ").Replace("s", " ").Replace(":", " "); + string[] parts = cleaned.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + + double hours = 0d; + double minutes = 0d; + double seconds = 0d; - for (int i=0; i<_words.Length; i++) { - if(_words[i] != "") - _values [i] = Convert.ToDouble (_words [i]); + if (parts.Length > 0) + hours = Convert.ToDouble(parts[0], CultureInfo.InvariantCulture); + + if (parts.Length > 1) { + double minuteValue = Convert.ToDouble(parts[1], CultureInfo.InvariantCulture); + minutes = Math.Truncate(minuteValue); + seconds += Math.Abs(minuteValue - minutes) * 60d; } - this.Hours = _values[0]; - this.Minutes = _values[1]; - this.Seconds = _values[2]; + if (parts.Length > 2) + seconds += Convert.ToDouble(parts[2], CultureInfo.InvariantCulture); + + this.Hours = hours; + this.Minutes = minutes; + this.Seconds = seconds; } } @@ -90,30 +91,31 @@ public Declination(string Deg_DegMin_DegSec) { * '+41:12' * '+41 12 00' */ - string[] _words = new string[] { "" }; - double[] _values = new double[3]; - - if (Deg_DegMin_DegSec.Split (new char[] {'+','d','m','s'} ).Length == 5) { - _words = Deg_DegMin_DegSec.Split (new char[] {'+','d','m','s'} ); - } else if(Deg_DegMin_DegSec.Split (new char[] {'+','d','m'} ).Length == 4) { - _words = Deg_DegMin_DegSec.Split (new char[] {'+','d','m'} ); - } else if(Deg_DegMin_DegSec.Split (new char[] {'+',':'} ).Length == 3) { - _words = Deg_DegMin_DegSec.Split (new char[] {'+',':'} ); - } else if(Deg_DegMin_DegSec.Split (new char[] {'+',' '} ).Length == 4) { - _words = Deg_DegMin_DegSec.Split (new char[] {'+',' '} ); + string cleaned = Deg_DegMin_DegSec.Trim().ToLowerInvariant(); + int sign = cleaned.StartsWith("-") ? -1 : 1; + cleaned = cleaned.TrimStart('+', '-'); + cleaned = cleaned.Replace("d", " ").Replace("m", " ").Replace("s", " ").Replace(":", " "); + string[] parts = cleaned.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + + double degrees = 0d; + double degreeMinutes = 0d; + double degreeSeconds = 0d; + + if (parts.Length > 0) + degrees = Convert.ToDouble(parts[0], CultureInfo.InvariantCulture); + + if (parts.Length > 1) { + double minuteValue = Convert.ToDouble(parts[1], CultureInfo.InvariantCulture); + degreeMinutes = Math.Truncate(minuteValue); + degreeSeconds += Math.Abs(minuteValue - degreeMinutes) * 60d; } - int b = 0; - for (int i=0; i<_words.Length; i++) { - if(_words[i] != "" && _words[i] != " " && _words[i] != null) { // Check that it's not an empty value - _values[b] = Convert.ToDouble (_words [i]); // Convert to a double and add to the array - b++; - } - } + if (parts.Length > 2) + degreeSeconds += Convert.ToDouble(parts[2], CultureInfo.InvariantCulture); - this.Degrees = _values[0]; - this.DegreeMinutes = _values[1]; - this.DegreeSeconds = _values[2]; + this.Degrees = sign * Math.Abs(degrees); + this.DegreeMinutes = degreeMinutes; + this.DegreeSeconds = degreeSeconds; } } @@ -223,8 +225,8 @@ double SetMeasurementTo(double value, string measurement) { value *= Maths.zetameter; else if (measurement == "yottameter") value *= Maths.yottameter; - else if (measurement == "yottameter") - value *= Maths.yottameter; + else if (measurement == "au" || measurement == "astronomicalUnit") + value *= Maths.au; /* Size, Radius & Mass Conversion */ } else if(Maths.othersArray.Contains (measurement)) { @@ -251,13 +253,13 @@ double SetMeasurementTo(double value, string measurement) { value *= Maths.second; else if (measurement == "minute") value *= Maths.minute; - else if (measurement == "sidrealMinute") + else if (measurement == "sidrealMinute" || measurement == "siderealMinute") value *= Maths.siderealMinute; else if (measurement == "hour") value *= Maths.hour; else if (measurement == "day") value *= Maths.day; - else if (measurement == "sidrealDay") + else if (measurement == "sidrealDay" || measurement == "siderealDay") value *= Maths.siderealDay; else if (measurement == "year") value *= Maths.year; @@ -307,6 +309,10 @@ public virtual void ToYM() { this.Value = SetMeasurementTo (this.Value, this.Measurement) / Maths.yottameter; this.Measurement = "yottameter"; } + public virtual void ToAU() { + this.Value = SetMeasurementTo (this.Value, this.Measurement) / Maths.au; + this.Measurement = "au"; + } /* Time Conversions */ public virtual void ToSecond() { this.Value = SetMeasurementTo (this.Value, this.Measurement) / Maths.second; @@ -439,12 +445,16 @@ public static double Distance(Vector3d first, Vector3d second) { // Comparison of two Vector3d variables. Checks their values instead of checking if it's the same reference public static bool operator == (Vector3d first, Vector3d second) { + if (ReferenceEquals(first, second)) + return true; + if (ReferenceEquals(first, null) || ReferenceEquals(second, null)) + return false; return (first.x == second.x && first.y == second.y && first.z == second.z); } // Comparison of two Vector3d variables. Checks their values instead of checking if it's the same reference public static bool operator !=(Vector3d first, Vector3d second) { - return (first.x != second.x || first.y != second.y || first.z != second.z); + return !(first == second); } // Calculate the length of the Vector3d variable (from 0,0,0) @@ -452,6 +462,19 @@ public double Length() { return System.Math.Sqrt(this.x*this.x + this.y*this.y + this.z*this.z); } + + public override bool Equals(object obj) { + Vector3d other = obj as Vector3d; + if (ReferenceEquals(other, null)) + return false; + + return this == other; + } + + public override int GetHashCode() { + return HashCode.Combine(x, y, z); + } + // Allow direct casting of Type. // vector3 = (Vector3)vector3d public static implicit operator Vector3(Vector3d convert) { diff --git a/version2/Assets/Scripts/tests/ImportData.cs b/version2/Assets/Scripts/tests/ImportData.cs index ae262e08..09140a01 100644 --- a/version2/Assets/Scripts/tests/ImportData.cs +++ b/version2/Assets/Scripts/tests/ImportData.cs @@ -1,7 +1,6 @@ -using UnityEngine; -using System.Collections; -using System.IO; +using System.IO; using SimpleJSON; +using UnityEngine; namespace ImportData @@ -9,14 +8,17 @@ namespace ImportData public class Data { - static string fileName = "Assets/Scripts/data.json"; - public static StreamReader data = File.OpenText(fileName); + private static readonly string FileName = Path.Combine(Application.dataPath, "Scripts/data.json"); public static JSONNode importedData; [HideInInspector] public string JSONData; // Holds the data.json file data public int numberOfStars; + public static string LoadJson() { + return File.ReadAllText(FileName); + } + /*void Awake () { StreamReader data = File.OpenText(fileName); @@ -37,4 +39,4 @@ public class Data { }*/ } -} \ No newline at end of file +} diff --git a/version2/Assets/Scripts/tests/Maths.cs b/version2/Assets/Scripts/tests/Maths.cs index 382bf35c..8652de05 100644 --- a/version2/Assets/Scripts/tests/Maths.cs +++ b/version2/Assets/Scripts/tests/Maths.cs @@ -1,15 +1,11 @@ using UnityEngine; using System; -using System.Collections; using Elements; -using BodyElements; using System.Linq; namespace CustomMath { - - [System.Serializable] // Show it in the Inspector - public class Maths + public static class Maths { /************************************************************ @@ -64,6 +60,9 @@ public static Element GetMeasurementIn(Element element) { } else if (_element.Measurement == "yottameter") { _element.Value *= yottameter; _measurement = "yottameter"; + } else if (_element.Measurement == "au" || _element.Measurement == "astronomicalUnit") { + _element.Value *= au; + _measurement = "meter"; } /* Time Conversion */ @@ -211,7 +210,7 @@ public static double InMillennium(Element element) { * We statically assign the size of each scale so that we can * quickly access the different scale sizes */ - public static string[] distanceArray = new string[]{"meter", "kilometer", "megameter", "gigameter", "terameter", "petameter", "exameter", "zetameter", "yottameter"}; + public static string[] distanceArray = new string[]{"meter", "kilometer", "megameter", "gigameter", "terameter", "petameter", "exameter", "zetameter", "yottameter", "au", "astronomicalUnit"}; public const double meter = 1d; public const double layer1 = 0.001d; public const double kilometer = 1000d; @@ -271,7 +270,7 @@ public static double InMillennium(Element element) { public static double RightAscensionToDegrees(RightAscension rightAscension) { - return (rightAscension.Hours * 15d) + (rightAscension.Minutes * 0.25d) + (rightAscension.Seconds * 0.004166d); + return (rightAscension.Hours * 15d) + (rightAscension.Minutes * 0.25d) + (rightAscension.Seconds * (1d / 240d)); } public static double DeclinationToDegrees(Declination declination) { return (Math.Abs (declination.Degrees) + (declination.DegreeMinutes / 60d) + (declination.DegreeSeconds / 3600d)) * Math.Sign (declination.Degrees); @@ -286,9 +285,9 @@ public static Vector3d SphericalToCartesianCoords(double distance, RightAscensio // Convert to cartesian values // We divide by megameter so we have the base conversion. Ex: 13,000,000meter = 13u - double _x = (distance/megameter) * Math.Sin(Maths.Deg2Rad * _declinationDegrees) * Math.Cos(Maths.Deg2Rad * _rightAscensionDegrees); - double _y = (distance/megameter) * Math.Sin(Maths.Deg2Rad * _declinationDegrees) * Math.Sin(Maths.Deg2Rad * _rightAscensionDegrees); - double _z = (distance/megameter) * Math.Cos(Maths.Deg2Rad * _declinationDegrees); + double _x = (distance/megameter) * Math.Cos(Maths.Deg2Rad * _declinationDegrees) * Math.Cos(Maths.Deg2Rad * _rightAscensionDegrees); + double _y = (distance/megameter) * Math.Cos(Maths.Deg2Rad * _declinationDegrees) * Math.Sin(Maths.Deg2Rad * _rightAscensionDegrees); + double _z = (distance/megameter) * Math.Sin(Maths.Deg2Rad * _declinationDegrees); return new Vector3d (_x, _y, _z ); } diff --git a/version2/Assets/Scripts/tests/SystemScaleState.cs b/version2/Assets/Scripts/tests/SystemScaleState.cs index 258db9e3..2bed8f71 100644 --- a/version2/Assets/Scripts/tests/SystemScaleState.cs +++ b/version2/Assets/Scripts/tests/SystemScaleState.cs @@ -3,6 +3,7 @@ using System.Collections; using CustomMath; +[DisallowMultipleComponent] public class SystemScaleState : MonoBehaviour { public enum State { ScaleNull, ScaleLayer1, ScaleLayer2, ScaleLayer3, ScaleLayer4, ScaleLayer5, ScaleLayer6, ScaleLayer7, ScaleLayer8, ScaleLayer9, ScaleLayer10, ScaleLayer11, ScaleLayer12, ScaleLayer13, ScaleLayer14, ScaleLayer15, ScaleLayer16, ScaleLayer17, ScaleLayer18 } diff --git a/version2/Packages/manifest.json b/version2/Packages/manifest.json new file mode 100644 index 00000000..2a101301 --- /dev/null +++ b/version2/Packages/manifest.json @@ -0,0 +1,37 @@ +{ + "dependencies": { + "com.unity.multiplayer.center": "1.0.0", + "com.unity.modules.accessibility": "1.0.0", + "com.unity.modules.ai": "1.0.0", + "com.unity.modules.androidjni": "1.0.0", + "com.unity.modules.animation": "1.0.0", + "com.unity.modules.assetbundle": "1.0.0", + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.cloth": "1.0.0", + "com.unity.modules.director": "1.0.0", + "com.unity.modules.imageconversion": "1.0.0", + "com.unity.modules.imgui": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.particlesystem": "1.0.0", + "com.unity.modules.physics": "1.0.0", + "com.unity.modules.physics2d": "1.0.0", + "com.unity.modules.screencapture": "1.0.0", + "com.unity.modules.terrain": "1.0.0", + "com.unity.modules.terrainphysics": "1.0.0", + "com.unity.modules.tilemap": "1.0.0", + "com.unity.modules.ui": "1.0.0", + "com.unity.modules.uielements": "1.0.0", + "com.unity.modules.umbra": "1.0.0", + "com.unity.modules.unityanalytics": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.unitywebrequestassetbundle": "1.0.0", + "com.unity.modules.unitywebrequestaudio": "1.0.0", + "com.unity.modules.unitywebrequesttexture": "1.0.0", + "com.unity.modules.unitywebrequestwww": "1.0.0", + "com.unity.modules.vehicles": "1.0.0", + "com.unity.modules.video": "1.0.0", + "com.unity.modules.vr": "1.0.0", + "com.unity.modules.wind": "1.0.0", + "com.unity.modules.xr": "1.0.0" + } +} diff --git a/version2/Packages/packages-lock.json b/version2/Packages/packages-lock.json new file mode 100644 index 00000000..d0360bfe --- /dev/null +++ b/version2/Packages/packages-lock.json @@ -0,0 +1,268 @@ +{ + "dependencies": { + "com.unity.multiplayer.center": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.uielements": "1.0.0" + } + }, + "com.unity.modules.accessibility": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.ai": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.androidjni": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.animation": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.assetbundle": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.audio": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.cloth": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0" + } + }, + "com.unity.modules.director": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.animation": "1.0.0" + } + }, + "com.unity.modules.hierarchycore": { + "version": "1.0.0", + "depth": 1, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.imageconversion": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.imgui": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.jsonserialize": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.particlesystem": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.physics": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.physics2d": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.screencapture": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.imageconversion": "1.0.0" + } + }, + "com.unity.modules.subsystems": { + "version": "1.0.0", + "depth": 1, + "source": "builtin", + "dependencies": { + "com.unity.modules.jsonserialize": "1.0.0" + } + }, + "com.unity.modules.terrain": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.terrainphysics": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0", + "com.unity.modules.terrain": "1.0.0" + } + }, + "com.unity.modules.tilemap": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics2d": "1.0.0" + } + }, + "com.unity.modules.ui": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.uielements": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.ui": "1.0.0", + "com.unity.modules.imgui": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.hierarchycore": "1.0.0" + } + }, + "com.unity.modules.umbra": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.unityanalytics": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0" + } + }, + "com.unity.modules.unitywebrequest": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.unitywebrequestassetbundle": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.assetbundle": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0" + } + }, + "com.unity.modules.unitywebrequestaudio": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.audio": "1.0.0" + } + }, + "com.unity.modules.unitywebrequesttexture": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.imageconversion": "1.0.0" + } + }, + "com.unity.modules.unitywebrequestwww": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.unitywebrequestassetbundle": "1.0.0", + "com.unity.modules.unitywebrequestaudio": "1.0.0", + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.assetbundle": "1.0.0", + "com.unity.modules.imageconversion": "1.0.0" + } + }, + "com.unity.modules.vehicles": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0" + } + }, + "com.unity.modules.video": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.ui": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0" + } + }, + "com.unity.modules.vr": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.physics": "1.0.0", + "com.unity.modules.xr": "1.0.0" + } + }, + "com.unity.modules.wind": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.xr": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.subsystems": "1.0.0" + } + } + } +} diff --git a/version2/ProjectSettings/DynamicsManager.asset b/version2/ProjectSettings/DynamicsManager.asset index 5262bcf6..f9eb8fbd 100644 Binary files a/version2/ProjectSettings/DynamicsManager.asset and b/version2/ProjectSettings/DynamicsManager.asset differ diff --git a/version2/ProjectSettings/GraphicsSettings.asset b/version2/ProjectSettings/GraphicsSettings.asset index f14fb856..f9b6bb6c 100644 Binary files a/version2/ProjectSettings/GraphicsSettings.asset and b/version2/ProjectSettings/GraphicsSettings.asset differ