private void OnTriggerExit(Collider col) { OrbitalData current = localUps[col]; current.rb.useGravity = true; localUps.Remove(col); }
public OrbitalData Add(Vector3 acceleration, float step) { var newOrbital = new OrbitalData(Orbital); newOrbital.Velocity = Velocity + acceleration * step; newOrbital.Position = Position + newOrbital.Velocity * step; return(newOrbital); }
/// <summary> /// Instantiate an orbiatl with scale and color /// </summary> /// <param name="n">Shell [1, 7] </param> /// <param name="l">SPDF [0, 3] </param> /// <param name="ml">obital [-3, 3] </param> /// <param name="ms">spin [-1 1]</param> public GameObject CreateOrbital(int electronCount, int n, int l, int ml, int ms) { GameObject obj; //orbital has been added, assign reference if (ms == 1) { obj = orbitalMap[electronCount - (2 * l + 1)].obj; // 2L + 1 => 1,3,5,7 orbitalMap[electronCount] = new OrbitalData(obj, n, l, ml, ms); return(obj); } GameObject orbitalPrefab = null; float scale = n; switch (l) { case 0: orbitalPrefab = sOrbitals[ml]; scale = 1f * n; break; case 1: orbitalPrefab = pOrbitals[ml + 1]; scale = 1.33f * n; break; case 2: orbitalPrefab = dOrbitals[ml + 2]; scale = 1.5f * n; break; case 3: orbitalPrefab = fOrbitals[ml + 3]; scale = 2.0f * n - 1; break; } obj = Instantiate(orbitalPrefab, Vector3.zero, Quaternion.identity, root); obj.transform.localPosition = Vector3.zero; obj.transform.localScale = Vector3.one * scale; Renderer[] renderers = obj.GetComponentsInChildren <Renderer>(); //get all the renderers foreach (Renderer r in renderers) { switch (Settings.MATERIAL) { case SettingsMaterial.Solid: r.material = mat_solid; break; case SettingsMaterial.Transparent: r.material = mat_transparent; break; } } obj.SetActive(false); orbitalMap[electronCount] = new OrbitalData(obj, n, l, ml, ms); //assign to array return(obj); }
public static EllipticalOrbitalPositionComponent CreateUnpoweredBody(EntityId parentId, double semiMajorAxis, double eccentricity, double longitutdeOfPeriapsis, double meanAnomaly, bool isRetrograde) { var orbitalData = new OrbitalData { ParentId = parentId, SemiMajorAxis = semiMajorAxis, Eccentricity = eccentricity, LongitudeOfPeriapsis = longitutdeOfPeriapsis, MeanAnomalyAtTimeZero = meanAnomaly, IsRetrograde = isRetrograde, }; return(new EllipticalOrbitalPositionComponent(new Point(), orbitalData)); }
IEnumerator LoadData() { using (WWW www = new WWW(localpath)) { yield return(www); JsonData = www.text; } OrbitalData orbitData = OrbitalData.FromJson(JsonData); orbitalDataUnity = new OrbitalDataUnity(orbitData); Debug.Log("generating satellites"); GenerateSatellites(); Debug.Log("setting current scale value to " + ScaleStartValue + "Units = " + orbitalDataUnity.Info.Units); CurrentScale = ScaleValue; DataLoaded = true; }
/// <summary> /// Constructor that takes a link to an Json_TN and an Base_TN_NodeType. /// </summary> /// <param name="gameDataNodeToLink">The node to link to.</param> /// <param name="nodeType">The node Type for the new linked node.</param> public SolarSystem_TN(Json_TN gameDataNodeToLink, Base_TN_NodeType nodeType) : base(gameDataNodeToLink, nodeType: nodeType) { // Set up this end of the cross-link. LinkedGameDataNode = gameDataNodeToLink ?? throw new NullReferenceException("gameDataNodeToLink was null."); // Cast the LinkedGameDataNode.JData field in to a JObject. JObject _linkedGameDataJson = (JObject)LinkedGameDataNode.JData ?? throw new NullReferenceException("_linkedGameDataJson was null."); // If we're working with a linked blueprint node, translate the StructureID to GUID JToken tmpTkn = _linkedGameDataJson["StructureID"]; if (tmpTkn != null) { Debug.Print("Got here for some reason!"); // Set the node's Name to the StructureID of the object. Name = (string)_linkedGameDataJson["StructureID"]; // Set the GUID to the StructureID GUID = (long)_linkedGameDataJson["StructureID"]; throw new Exception("Got here for some reason!"); } else { switch (nodeType) { case Base_TN_NodeType.Ship: if (string.IsNullOrEmpty((string)_linkedGameDataJson["Name"])) { // The ship has no name - most non-player vessels fall in to this category. Name = (string)_linkedGameDataJson["Registration"]; } else { // The ship has a name, append it on to the end of the registration Name = (string)_linkedGameDataJson["Registration"] + " " + (string)_linkedGameDataJson["Name"]; } break; default: Name = ((string)_linkedGameDataJson["Name"]).Trim(); break; } // Can't use these presently as it messes with the TreeView's Path system, // which annoyingly uses the TreeNode's Text field rather than the Name field // in path generation, which would have allowed the Text property to be used like // a DisplayName property. // Text_Prefix = ((string)_linkedGameDataJson["Name"]).Trim(); // Text_Suffix = ((string)_linkedGameDataJson["GUID"]).Trim(); // Set the GUID GUID = (long)_linkedGameDataJson["GUID"]; } JToken tempToken = null; switch (nodeType) { case Base_TN_NodeType.Star: case Base_TN_NodeType.Planet: case Base_TN_NodeType.Moon: // It's a Celestial Body - the orbital data is not in an OrbitalData sub-object, but directly // as properties of this JObject. OrbitData = new OrbitalData(_linkedGameDataJson); break; case Base_TN_NodeType.Player: // It's a player - doesn't have orbital data but may have a parent GUID if in a ship/module. // Ensure OrbitData is null. // OrbitData = new OrbitalData(); tempToken = _linkedGameDataJson["ParentGUID"]; if (tempToken != null) { OrbitData.ParentGUID = (long)_linkedGameDataJson["ParentGUID"]; } else { // Set the parent GUID to -1 (the Solar System) as we currently can't place players who // are outside ships or modules. OrbitData.ParentGUID = -1; } break; case Base_TN_NodeType.Ship: // Ships also need to set the docking info if present. OrbitData = new OrbitalData((JObject)_linkedGameDataJson["OrbitData"]); DockedToShipGUID = (long?)_linkedGameDataJson["DockedToShipGUID"]; DockedPortID = (int?)_linkedGameDataJson["DockedPortID"]; DockedToPortID = (int?)_linkedGameDataJson["DockedToPortID"]; break; default: // It's a regular orbital object with it's parameters in an OrbitData sub-object. OrbitData = new OrbitalData((JObject)_linkedGameDataJson["OrbitData"]); break; } }
private void OnTriggerStay(Collider col) { if (col.CompareTag("StaticObject")) { return; } if (col.CompareTag("PhysicsShape")) { return; } if (col.CompareTag("ForceField")) { return; } if (col.CompareTag("OrbitalField")) { return; } else { Vector3 up; Rigidbody targetRb; Transform target; Vector3 lookAt; //if we don't know this collider //add it into the dict with its calculated up val if (!localUps.ContainsKey(col)) { targetRb = col.GetComponent <Rigidbody>(); target = col.transform; lookAt = thisTransform.position - target.position; up = Quaternion.AngleAxis(90f, Vector3.forward) * lookAt; localUps.Add(col, new OrbitalData(up, targetRb, target)); } else //otherwise just grab the precalculated values { OrbitalData current = localUps[col]; targetRb = current.rb; target = current.thisTransform; lookAt = thisTransform.position - target.position; up = current.up; } Vector3 dir = Vector3.Cross(lookAt, up).normalized; targetRb.AddForce(dir * satelliteSpeed, ForceMode.VelocityChange); if (targetRb.velocity.magnitude > maxSpeed) { targetRb.velocity = dir * maxSpeed; //Debug.Log("Reached max force!"); } else { //Debug.Log("Adding force to body!"); } targetRb.useGravity = false; #if UNITY_EDITOR if (debugPaths) { Debug.DrawRay(target.position, up.normalized * 30f, Color.red, 0.5f); Debug.DrawRay(target.position, lookAt.normalized * 30f, Color.yellow, 0.5f); Debug.DrawRay(target.position, dir.normalized * 30f, Color.green, 0.5f); } #endif } }
private void Update() { //get the number of electrons in the Atom int electronCount = atom.ElectronCount; //check if changed if (electronCount != currentElectronCount) { OrbitalData data = orbitalMap[currentElectronCount]; if (Settings.ORBITALS_ALL) { //Add in Orbitals while (electronCount > currentElectronCount) { currentElectronCount++; data = orbitalMap[currentElectronCount]; //active andOr recolor if (data.ms == -1) { data.obj.SetActive(true); } AdjustColor(data.obj, data.l, data.ms); } //Remove Orbitals while (electronCount < currentElectronCount) { //deactive or recolor if (data.ms == -1) { data.obj.SetActive(false); } else if (electronCount > 0) { AdjustColor(data.obj, data.l, -1); //revert color } currentElectronCount--; data = orbitalMap[currentElectronCount]; } } else // (Only show current orbital) { //deactivate the current if (currentElectronCount != 0) { data.obj.SetActive(false); } //activate the new and recolor data = orbitalMap[electronCount]; if (electronCount > 0) { data.obj.SetActive(true); } AdjustColor(data.obj, data.l, data.ms); } //unpdate the orbital data currentOrbital = data.obj; currentElectronCount = electronCount; OnUpdate?.Invoke(data.n, data.l, data.ml, data.ms); //Adjust the display AdjustScale(); AdjustAxis(); } }