Spiral Circus wroteJust thinking about rolling my own custom bounding box culler. Is there a way to access the "largest possible bounding box" through SkeletonAnimation.cs ?
I'm asking to prevent myself from leaving open the same edge case where animations the animation itself could take the mesh off screen, but shouldn't be culled because it's about to come back on screen in a few frames.
I don't know of any way of telling what the largest possible bounding box is.
What I do is add a buffer-distance to the bounding box when deciding whether or not the animations should be culled, and then based on my knowledge of the character's extents I set that buffer. So if a character doesn't move much, the buffer distance can be small, but if the character has a spear that he stabs out really far, I'd make the buffer larger in that direction
Here is the code, if you want to implement it I suggest understanding what it does and then re-writing it to fit your needs.
"renderer" is set to the mesh renderer
"SHOULD_BE_UPDATED" is just a bool that gets set to false initially and then tests to see if the thing is close enough to the camera's view to update it or not. So I use the value of SHOULD_BE_UPDATED to enable/disable the animation.
public void UpdateOffscreenTest() {
SHOULD_BE_UPDATED = false;
//Check if its within regular view based on the renderer
if (renderer.isVisible == true) { SHOULD_BE_UPDATED = true; return;}
//Check if its outside the camera's view + buffer distance
if(CameraController.Instance != null) {
if (renderer.bounds.max.x + cullBufferDistance < CameraController.Instance.cameraRect.xMin) { return; }
if (renderer.bounds.min.x - cullBufferDistance > CameraController.Instance.cameraRect.xMax) { return; }
if (renderer.bounds.max.y + cullBufferDistance < CameraController.Instance.cameraRect.yMin) { return; }
if (renderer.bounds.min.y - cullBufferDistance > CameraController.Instance.cameraRect.yMax) { return; }
}
//We now know that its within the camera's view + buffer distance
SHOULD_BE_UPDATED = true;
}
Note: instead of using a singular "cullBufferDistance", you could further customize it into: maxX, minX, maxY, minY for each of the direction checks
Note 2: Should have mentioned it earlier, but the purpose of this is to have a buffer area thats outside of the camera's view where the Spine Animation will start animating again before the Spine Animation comes within the cameras view
Note 3: This is how my cameraRect is set. It is called every frame on my camera object:
public void UpdateMainCameraRect() {
float height = Camera.main.orthographicSize * 2.0f;
float width = height * Screen.width / Screen.height;
cameraRect.Set(Camera.main.transform.position.x - width / 2f,
Camera.main.transform.position.y - height / 2f,
width,
height);
}
Note 4: All of this is assuming your Unity project is 2D π