public override void OnInspectorGUI() { GUI.changed = false; BinaryPair bPair = (BinaryPair)target; Vector3 velocity = Vector3.zero; GravityScaler.Units units = GravityEngine.Instance().units; string prompt = string.Format("Velocity ({0})", GravityScaler.VelocityUnits(units)); velocity = EditorGUILayout.Vector3Field(new GUIContent(prompt, "velocity of binary center of mass"), bPair.velocity); if (GUI.changed) { Undo.RecordObject(bPair, "EllipseBase Change"); bPair.velocity = velocity; EditorUtility.SetDirty(bPair); } base.OnInspectorGUI(); if (axisUpdated) { bPair.ApplyScale(GravityEngine.Instance().GetLengthScale()); } }
/// <summary> /// Used to determine the initial physics position of an NBody (initialPhysPosition). /// /// Used in two contexts: /// (1) When a body is added to GE (either at setup or when a body is dynamically added at run-time). /// (2) In the editor DrawGizmo calls when the orbit path is being show in a scene that is not running. /// In the case of orbit gizmos the orbit parameters will MOVE the object to the correct position in the /// orbit based on the position calculated here. /// /// If the NBody game object has an INBodyInit component (e.g from an OrbitEllipse) then /// this is used to determine it's position. There is a potential for recursion here, since that /// orbit ellipse may be on a NBody that is in turn positioned by an orbit ellipse e.g. moon/planet/sun. /// /// If the NBody has an engine ref (i.e. GE has taken charge) then update with the position from GE. /// /// </summary> /// <param name="ge"></param> public void InitPosition(GravityEngine ge) { // Not ideal that NBody knows so much about methods to run setup. Be better to delegate this eventually. // check for initial condition setup (e.g. initial conditions for elliptical orbit/binary pair) if (engineRef != null) { initialPhysPosition = ge.GetPhysicsPosition(this); } else { // If there is a Kepler sequence, use that instead of e.g. the first OrbitU INbodyInit initNbody; KeplerSequence keplerSeq = GetComponent <KeplerSequence>(); if (keplerSeq != null) { initNbody = (INbodyInit)keplerSeq; } else { initNbody = gameObject.GetComponent <INbodyInit>(); } if (initNbody != null) { initNbody.InitNBody(ge.physToWorldFactor, ge.massScale); } else { // binary pair if (transform.parent != null) { BinaryPair bp = transform.parent.GetComponent <BinaryPair>(); if (bp != null) { bp.SetupBodies(); return; } } if (ge.units != GravityScaler.Units.DIMENSIONLESS) { // value in scaled systems is taken from the NBody scaled position and not the transform initialPhysPosition = initialPos; } else { // value is taken from the transform object initialPhysPosition = transform.position; } } } }
/// <summary> /// Determine if and how many objects are orbital parents. /// e.g. Sun = 0, planet=1, moon=2 /// </summary> public void CalcOrbitDepth() { GameObject go = gameObject; do { OrbitEllipse ellipse = go.GetComponent <OrbitEllipse>(); if (ellipse != null) { go = ellipse.centerObject; orbitDepth++; continue; } OrbitUniversal orbitU = go.GetComponent <OrbitUniversal>(); if (orbitU != null) { go = orbitU.centerNbody.gameObject; orbitDepth++; continue; } OrbitHyper hyper = go.GetComponent <OrbitHyper>(); if (hyper != null) { go = hyper.centerObject; orbitDepth++; continue; } if (go.transform.parent != null) { BinaryPair bp = go.transform.parent.gameObject.GetComponent <BinaryPair>(); if (bp != null) { go = bp.gameObject; orbitDepth++; continue; } // If parent has an NBody, then it's an orbital parent, since need to inherit its velocity NBody nbody_parent = go.transform.parent.gameObject.GetComponent <NBody>(); if (nbody_parent != null) { go = nbody_parent.gameObject; orbitDepth++; continue; } } go = null; } while (go != null); }