I'm trying to figure out the correct way to turn off UIAnchors at runtime. I've tried assigning null to the anchorpoints' targets as such:
_widget.updateAnchors = UIRect.AnchorUpdate.OnEnable;
_widget.rightAnchor = null;
_widget.leftAnchor = null;
But this results in an error that seems to occur in the update function. The error states:
NullReferenceException: Object reference not set to an instance of an object
UIRect.get_isAnchored () (at Assets/FromAssetStore/NGUI/Scripts/Internal/UIRect.cs:261)
TweenPosition.set_value (Vector3 value) (at Assets/FromAssetStore/NGUI/Scripts/Tweening/TweenPosition.cs:41)
TweenPosition.OnUpdate (Single factor, Boolean isFinished) (at Assets/FromAssetStore/NGUI/Scripts/Tweening/TweenPosition.cs:60)
UITweener.Sample (Single factor, Boolean isFinished) (at Assets/FromAssetStore/NGUI/Scripts/Tweening/UITweener.cs:335)
UITweener.Update () (at Assets/FromAssetStore/NGUI/Scripts/Tweening/UITweener.cs:242)
UITweener.Start () (at Assets/FromAssetStore/NGUI/Scripts/Tweening/UITweener.cs:158)
And points to the targets of the anchors being null, it seems.
The reason why I'm doing this (or trying to) is because I have a bunch of photos laid out in a grid -- I'm using a scrollview and adding horizontal rows of photos as prefabs. In order to keep the photos at a good distance from each other, regardless of screen size, I'm using anchors to get them seperated from each other at start. But the user has to be able to cause the photos to go full screen, and if they're anchored (even if it's only anchoring on enable), the tweening to a full screen size acts funny. So I'm trying to start with an anchored UITexture to get the positioning correct, but then turn them off. Here's what I'm trying to accomplish -- I've got it laid out, but it doesn't work correctly because of the anchoring issue, I think.
http://imgur.com/KPEy4aGAm I going about this in the right way? And if so, how can I turn off the anchors?
Cheers,
Simon