/// <summary> /// add a child satelite to this object and set it up /// </summary> /// <param name="sateliteController"></param> void addSatelite(AstrologicalObjectController sateliteController) { /// parent this to the child satelite and add it's pivot astrologicalObjectData.satelites.Add(sateliteController.astrologicalObjectData); // create the pivot, make sure it's in the same place as this, the parent GameObject satelitePivot = new GameObject($"{sateliteController.gameObject.name}'s orbital pivot"); satelitePivot.transform.position = transform.position; satelitePivot.transform.parent = transform; // set the satelite's controller's parent to the new pivot sateliteController.gameObject.transform.parent = satelitePivot.transform; sateliteController.orbitalPivot = satelitePivot; /// move the satelite into the inital position for it's orbital axis sateliteController.gameObject.transform.position = satelitePivot.transform.position + satelitePivot.transform.forward * sateliteController.astrologicalObjectData.distanceFromParent * StarMap.AstrologicalUnit; satelitePivot.transform.rotation = Quaternion.FromToRotation(sateliteController.astrologicalObjectData.orbitalAxis, sateliteController.astrologicalObjectData.orbitalAxis + sateliteController.astrologicalObjectData.orbitalAxis); satelitePivot.transform.Rotate(sateliteController.astrologicalObjectData.orbitalAxis, sateliteController.astrologicalObjectData.initialOrbitDegree); sateliteController.astrologicalObjectData.parent = satelitePivot?.transform.parent.gameObject.GetComponentInParent <AstrologicalObjectController>()?.astrologicalObjectData; sateliteController.isInitializedAsChild = true; }
// Start is called before the first frame update void Start() { if (astrologicalObjectData.scale != 0) { transform.localScale = new Vector3(astrologicalObjectData.scale, astrologicalObjectData.scale, astrologicalObjectData.scale); } for (int index = 0; index < transform.childCount; index++) { Transform child = transform.GetChild(index); AstrologicalObjectController childController = child.gameObject.GetComponent <AstrologicalObjectController>(); if (childController != null && !childController.isInitializedAsChild) { addSatelite(childController); index--; } } }