public void updateScale()
{
try // run on OnLoad() now, so may be nulls
{
updateMaxRFactor();
rescaleModel();
if (stretchSRB)
{
transform.GetChild(0).GetChild(1).localScale = new Vector3(radialFactor, radialFactor, radialFactor);
transform.GetChild(0).GetChild(1).localPosition = new Vector3(0f, bottomPosition * stretchFactor, 0f);
//foreach (MeshCollider c in transform.GetComponentsInChildren<MeshCollider>().ToList())
//c.convex = true;
}
if (part.attachMode == AttachModes.SRF_ATTACH && superStretch == true)
{
var diff = attach * getAttachFactor() - part.srfAttachNode.position.x;
var x = part.transform.localPosition.x;
var z = part.transform.localPosition.z;
var angle = Mathf.Atan2(x, z);
if (HighLogic.LoadedSceneIsEditor && triggerUpdate)
part.transform.Translate(diff * Mathf.Sin(angle), 0f, diff * Mathf.Cos(angle), part.parent.transform);
}
part.findAttachNode("top").position.y = topPosition * stretchFactor;
float stretchDifference = part.findAttachNode("top").position.y - topPosition;
if (HighLogic.LoadedSceneIsEditor && triggerUpdate)
{
if (part.findAttachNode("top").attachedPart != null)
{
if (topCheck)
{
topStretchPosition = stretchDifference;
topCheck = false;
}
if (part.findAttachNode("top").attachedPart == part.parent)
{
var p = EditorLogic.SortedShipList[0];
float count = 1;
if (part.symmetryCounterparts != null)
count += part.symmetryCounterparts.Count;
p.transform.Translate(0f, (stretchDifference - topStretchPosition) / count, 0f, part.transform);
part.transform.Translate(0f, -(stretchDifference - topStretchPosition), 0f);
}
else
{
part.findAttachNode("top").attachedPart.transform.Translate(0f, stretchDifference - topStretchPosition, 0f, part.transform);
}
topStretchPosition = stretchDifference;
}
else
{
topCheck = true;
}
}
part.findAttachNode("bottom").position.y = bottomPosition * stretchFactor - radialFactor * srbNozzleLength;
stretchDifference = part.findAttachNode("bottom").position.y - bottomPosition + srbNozzleLength;
if (HighLogic.LoadedSceneIsEditor && triggerUpdate)
{
if (part.findAttachNode("bottom").attachedPart != null)
{
if (bottomCheck)
{
bottomStretchPosition = stretchDifference;
bottomCheck = false;
}
if (part.findAttachNode("bottom").attachedPart == part.parent)
{
var p = EditorLogic.SortedShipList[0];
float count = 1;
if (part.symmetryCounterparts != null)
count += part.symmetryCounterparts.Count;
p.transform.Translate(0f, (stretchDifference - bottomStretchPosition) / count, 0f, part.transform);
part.transform.Translate(0f, -(stretchDifference - bottomStretchPosition), 0f);
}
else
{
part.findAttachNode("bottom").attachedPart.transform.Translate(0f, stretchDifference - bottomStretchPosition, 0f, part.transform);
}
bottomStretchPosition = stretchDifference;
}
else
{
bottomCheck = true;
}
}
if (superStretch == true)
{
part.srfAttachNode.position.x = attach * getAttachFactor();
refreshSrfAttachNodes();
// NK rescale attach nodes
part.findAttachNode("top").size = (int)Math.Round(getTopFactor() * 2f * nodeSizeScalar - 0.01);
part.findAttachNode("bottom").size = (int)Math.Round(radialFactor * 2f * nodeSizeScalar - 0.01);
}
}
catch (Exception e)
{
print("*ST* UpdateScale caught: " + e.Message);
}
}