private void SetupFairing() { // If we are duplicating in the editor or reinitializing, there will be some leftovers // Easier to just get rid of them rather than try to rebuild the hierarchy GameObject oldFairing = part.FindModelTransform(FAIRING_ROOT_TRANSFORM_NAME)?.gameObject; if (oldFairing != null) { oldFairing.transform.parent = null; Destroy(oldFairing); } fairingRoot = new GameObject(FAIRING_ROOT_TRANSFORM_NAME); fairingRoot.transform.NestToParent(modelRoot.transform); ResolvedModelData currentCapObjectPrefab = capObjectPrefab; slices.Clear(); for (int i = 0; i < numSlices; i++) { GameObject sliceRoot = new GameObject("FairingSlice"); sliceRoot.transform.NestToParent(fairingRoot.transform); sliceRoot.transform.localRotation = Quaternion.AngleAxis(360f / numSlices * i, axis); slices.Add(new FairingSlice(sliceRoot, coneObjectPrefab, currentCapObjectPrefab, wallObjectPrefab, wallBaseObjectPrefab, SegmentOffset, scale)); currentCapObjectPrefab = null; } UpdateSegments(); UpdateTransparency(); NotifyModelUpdate(); UpdateOpen(); UpdateCargoBay(); part.ModifyCoM(); }
public FairingSlice(GameObject sliceRoot, ResolvedModelData conePrefab, ResolvedModelData capPrefab, ResolvedModelData wallPrefab, ResolvedModelData wallBasePrefab, Vector3 segmentOffset, float scale) { SliceRootObject = sliceRoot ?? throw new ArgumentNullException(nameof(sliceRoot)); this.conePrefab = conePrefab ?? throw new ArgumentNullException(nameof(conePrefab)); this.capPrefab = capPrefab; this.wallPrefab = wallPrefab; this.wallBasePrefab = wallBasePrefab; this.segmentOffset = segmentOffset; this.scale = scale; subRootObject = new GameObject("FairingSlice-Sub"); subRootObject.transform.NestToParent(SliceRootObject.transform); coneObject = new GameObject("FairingCone"); coneObject.transform.NestToParent(subRootObject.transform); GameObject mainConeObject = UnityEngine.Object.Instantiate(conePrefab.gameObject, coneObject.transform); mainConeObject.transform.localPosition = conePrefab.rootOffset; mainConeObject.transform.localScale *= scale; mainConeObject.gameObject.SetActive(true); if (capPrefab != null) { GameObject coneCapObject = UnityEngine.Object.Instantiate(capPrefab.gameObject, coneObject.transform); coneCapObject.transform.localPosition = capPrefab.rootOffset; coneCapObject.transform.localScale *= scale; coneCapObject.gameObject.SetActive(true); } if (wallBasePrefab != null) { GameObject wallBaseObject = UnityEngine.Object.Instantiate(wallBasePrefab.gameObject, subRootObject.transform); wallBaseObject.transform.localPosition = wallBasePrefab.rootOffset; wallBaseObject.transform.localScale *= scale; wallBaseObject.gameObject.SetActive(true); } }
private bool FindTransforms() { bool result = true; modelRoot = part.gameObject.transform.Find("model").gameObject; if (modelRoot == null) { this.LogError("Root transform could not be found!"); return(false); } if (wallBaseData != null) { try { wallBaseObjectPrefab = wallBaseData.Resolve(modelRoot); } catch (ModelData.ResolveException ex) { this.LogException(ex); result = false; } } if (wallData != null) { try { wallObjectPrefab = wallData.Resolve(modelRoot); } catch (ModelData.ResolveException ex) { this.LogException(ex); result = false; } } if (capData != null) { try { capObjectPrefab = capData.Resolve(modelRoot); } catch (ModelData.ResolveException ex) { this.LogException(ex); result = false; } } if (coneData == null) { this.LogError("coneData is null, cannot find transform!"); result = false; } else if (coneData.enabled == false) { this.LogError("coneData has enabled = false, this is illegal!"); result = false; } else { try { coneObjectPrefab = coneData.Resolve(modelRoot); } catch (ModelData.ResolveException ex) { this.LogException(ex); result = false; } } return(result); }