public void SetBounds(AABB newBounds, bool autoAdjust = true) { var boundsSize = newBounds.Size; stairsWidth = GeometryUtility.CleanLength(boundsSize.x); stairsHeight = GeometryUtility.CleanLength(boundsSize.y); stairsDepth = GeometryUtility.CleanLength(boundsSize.z); if (float.IsInfinity(stairsWidth) || float.IsNaN(stairsWidth)) { stairsWidth = 1.0f; } if (float.IsInfinity(stairsDepth) || float.IsNaN(stairsDepth)) { stairsDepth = stepDepth; } if (float.IsInfinity(stairsHeight) || float.IsNaN(stairsHeight)) { stairsHeight = stepHeight; } stairsWidth = Mathf.Max(0, stairsWidth); stairsDepth = Mathf.Max(0, stairsDepth); stairsHeight = Mathf.Max(0, stairsHeight); if (autoAdjust) { if (!bounds.IsEmpty()) { float offsetY = (newBounds.MaxY - bounds.MaxY) + (bounds.MinY - newBounds.MinY); float offsetZ = (newBounds.MaxZ - bounds.MaxZ) + (bounds.MinZ - newBounds.MinZ); if (offsetY != 0) // scaling in height direction { if (offsetY > 0) // growing { if (extraDepth > 0) { extraDepth = stairsDepth - ((Mathf.Max(0, stairsHeight - extraHeight) / stepHeight) * stepDepth); } else { extraDepth -= offsetY; extraHeight += offsetY; } } else // shrinking { extraHeight += offsetY; extraDepth = stairsDepth - ((Mathf.Max(0, stairsHeight - extraHeight) / stepHeight) * stepDepth); } } if (offsetZ != 0) // scaling in depth direction { if (offsetZ > 0) // growing { if (extraHeight > 0) { extraHeight = stairsHeight - ((Mathf.Max(0, stairsDepth - extraDepth) / stepDepth) * stepHeight); } else { extraDepth += offsetZ; if (extraDepth < 0) { extraDepth = 0; } extraHeight -= offsetZ; } } else // shrinking { if (extraDepth > 0) { extraDepth = Mathf.Max(0, extraDepth + offsetZ); } extraHeight = stairsHeight - ((Mathf.Max(0, stairsDepth - extraDepth) / stepDepth) * stepHeight); } extraDepth = stairsDepth - ((Mathf.Max(0, stairsHeight - extraHeight) / stepHeight) * stepDepth); } if (extraDepth < 0) { extraDepth = 0; } if (extraHeight < 0) { extraHeight = 0; } } else { extraDepth = Mathf.Max(0, stairsDepth - (totalSteps * stepDepth)); extraHeight = 0; } CalcTotalSteps(); } bounds = newBounds; }