And I've run into yet another problem trying to implement tweens.
I've got a "ticker" on the bottom, with headlines form left to right. what's supposed to happen is it adds a new item off screen to the left, then tweens all the headlines to the right based on the new items width (putting the new item in the bottom left corner).
This only works for the FIRST item, though, as every other item just jumps to the new position.
On a related note, is there a way to force the anchor resizing? the headline background/button is supposed to be the width of the label which works, but when I'm adding the item and tweening everything, the headline background width hasn't resized according to its anchors yet, so the width is wrong (uses the default prefab size). I got it to work by looking at the label's width and manually adding the sum of spacing around it, but that's not ideal.
(int width = 40 + 6 + uipLine.Label.width + 10;//icon+spacing+label+spacing)
void AddActiveHeadline(Headline headline)
{
Debug.Log("Adding Headline:" + headline.Title);
//create GUI element
UIPHeadlineButton uipLine = UIPHeadlineButton.Create(this.TickerBar, headline);
//get width for positioning, tweens
int width = uipLine.Background.width;//TODO returns INCORRECT WIDTH, not yet resized according to anchors
//move new headline to bottomleft, off screen by width
Vector3 offPos = uipLine.transform.localPosition;
offPos.x -= width;
uipLine.transform.localPosition = offPos;//move offscreen by width
//add to active headlines
this.ActiveHeadlines.Add(uipLine);
//slide headlines
Debug.Log("Tweening Headlines");
foreach (UIPHeadlineButton hdln in ActiveHeadlines)
{
hdln.TweenPos.SetStartToCurrentValue();
//get "to" pos
Vector3 pos = hdln.transform.localPosition;
pos.x += width;
hdln.TweenPos.to = pos;
//play
hdln.TweenPos.PlayForward();
}
}
EDIT: I've tried this with a for loop instead in case that was the problem, but same issue: only the first tween executes, and the other items just "jump" to the "to" position.
I also noticed a strange thing... If I click on the object in the inspector and activate the tween component, it stays active for as long as the tween *would* take to play, then jump to the end position and turns off. so it's acting like it's playing, but it's not actually animating out the tween.
for (int i = ActiveHeadlines.Count-1; i>=0; i--)
{
UIPHeadlineButton hdln = ActiveHeadlines [i];
hdln.TweenPos.SetStartToCurrentValue();
//get "to" pos
Vector3 pos = hdln.transform.localPosition;
pos.x += width;
hdln.TweenPos.to = pos;
//play
hdln.TweenPos.PlayForward();
}