|
Post by noblerobot on May 3, 2018 2:49:25 GMT
My team is making a 2D platformer made up of what we call "blocks," which are just discrete sections of levels. These blocks are empty GameObjects which contain everything in that section as child GameObjects. Our workflow is to design these blocks independently, and then put them together into a level. We sometimes rearrange them within or between different levels in the game.
So, the problem is that we can't easily use Camera Boundary triggers this way. We don't want to make the boundaries "relative," because for our use-case when we adjust a trigger we don't want the boundaries to move with it (it's is easy to forget to re-adjust them while working). However, doing it the other way isn't useful either because the boundaries use absolute position, which doesn't change when we adjust the transform of the trigger's parent object, which we do a lot.
Anyway, it could be an bool to select "boundries use localPosition", or honestly, it could just be the default behavior of the script. I hope this makes sense. Thanks!
(Another note: it's hard to write classes that extend the components in this asset because so many methods and variables are not marked as protected/private/public/etc. so they are "internal" and thus impossible to override in an extended class without editing the core script files.)
|
|
|
Post by noblerobot on May 3, 2018 3:56:22 GMT
Okay, below is my solution, which I put in a file in my project called "ProCamera2DTriggerBoundriesExtended.cs" which extends "ProCamera2DTriggerBoundries.cs".
public float UseLocalPosition = false;
// EDITED THIS PARENT CLASS TO ADD "protected virtual" protected override void GetTargetBoundaries() { if (AreBoundariesRelative) { _targetTopBoundary = Vector3V(transform.position) + TopBoundary; _targetBottomBoundary = Vector3V(transform.position) + BottomBoundary; _targetLeftBoundary = Vector3H(transform.position) + LeftBoundary; _targetRightBoundary = Vector3H(transform.position) + RightBoundary; } else if (UseLocalPosition) { _targetTopBoundary = Vector3V(transform.root.position) + TopBoundary; _targetBottomBoundary = Vector3V(transform.root.position) + BottomBoundary; _targetLeftBoundary = Vector3H(transform.root.position) + LeftBoundary; _targetRightBoundary = Vector3H(transform.root.position) + RightBoundary; } else { _targetTopBoundary = TopBoundary; _targetBottomBoundary = BottomBoundary; _targetLeftBoundary = LeftBoundary; _targetRightBoundary = RightBoundary; } }
// EDITED THIS PARENT CLASS TO ADD "protected virtual" override protected IEnumerator Transition() { [ ... ] var position = UseLocalPosition ? transform.root.position : Vector3.zero; position = AreBoundariesRelative ? transform.position : position;
var topBoundary = position.y + TopBoundary; var bottomBoundary = position.y + BottomBoundary; var leftBoundary = position.x + LeftBoundary; var rightBoundary = position.x + RightBoundary; const float epsilon = 0.01f;
[ ... ]
}
There are probably limits to this implementation. It offsets the boundries only by the trigger GameObject's root parent, even if the object is many levels down in the hierarchy. This is perfect for our use case (we have a number of nested GameObjects which we use mostly as "folders" and are all positioned [0,0]), but a real solution might require accounting for the transform of every parent in a potential chain of hierarchy. Also, I suppose "use localTransform" is not a good name for this feature. Maybe "relative to parent transform" ?
|
|
|
Post by Luís Pedro Fonseca on May 3, 2018 8:39:16 GMT
Hi noblerobot, Thanks for describing your problem and solution! I'll try to incorporate this feature into the package on an upcoming release. You're right, I could have done a better job at making the methods and variables easier to extend. I'll try to improve that aspect in the upcoming releases. Cheers!
|
|
|
Post by noblerobot on May 3, 2018 11:52:44 GMT
Wonderful. Thanks for the quick response. You certainly live up to your reputation! I adore using (and hacking away at) this tool.
|
|