Author Topic: Tweening multiple gameobjects with one tween event  (Read 19560 times)

PiWizard

  • Guest
Tweening multiple gameobjects with one tween event
« on: August 16, 2012, 08:24:27 PM »
I am trying to make it so that I have one button, but two gameobjects get tweened from the same event.

The two gameobjects are on two different panels.

What is the easiest way to accomplish something like this? I assume adding UIButton Tween script twice with two different targets is not the solution ;)

Thanks

PiWizard

  • Guest
Re: Tweening multiple gameobjects with one tween event
« Reply #1 on: August 16, 2012, 09:14:38 PM »
Looks like you can use just multiple UIButton Tweens, it is a tad ugly since I will have one with a lot of different UIButton Tweens, any suggestions on cleaning it up? I will have 4 "buttons" which affect eachother.

Button 1 stretches, causes Button 2, 3, 4 to shift to the side, clicking button 2 shrinks 1, expands 2, leaves 3, 4 where they are... etc (They are verticle button/panels).

The other question is, I have a UIStretch on these vertical game objects (TiledSprites) so that they take up 1 full height. The problem is, when I do a TweenStretch the Y has to be set to a concrete number. Is there a way to make it so that TweenStretch only effects one axis? Like X and no Y?

X = 100, Y = -, Z = - so only X stretches ever.

Thanks

simon129

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 20
    • View Profile
Re: Tweening multiple gameobjects with one tween event
« Reply #2 on: August 16, 2012, 10:16:34 PM »
Using UITweener.tweenGroup property ?

It can trigger multiple tweens

PiWizard

  • Guest
Re: Tweening multiple gameobjects with one tween event
« Reply #3 on: August 17, 2012, 01:15:47 AM »
That just triggers multiple tweens on the same target. If I have 3 different tween targets (different game objects) it seems like I need several different ButtonTweens in order to target them all.

I just started using tweens so I might be wrong in that assumption.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweening multiple gameobjects with one tween event
« Reply #4 on: August 17, 2012, 09:32:16 AM »
UIButtonTween.includeChildren can be used here. Set the group, target the parent object, and have includeChildren checked.

PiWizard

  • Guest
Re: Tweening multiple gameobjects with one tween event
« Reply #5 on: August 17, 2012, 05:07:38 PM »
Hey Aren,

That helps a little bit but still includes a lot of ButtonTween's as well as I just figured out a new problem.

http://imgur.com/uRhbW

That is my example UI.

It starts off in (1) where all of the panels are shrunk down to just buttons. The user clicks b, it expands and panels c and d shift to the right.

When the user selects c next, c expands and b shrinks back down at the same time.

Do you see where I am going with this? In order for this to work it seems like each panel grouping needs:
TweenGroup:
(0) Stretch the panel background outwards (TweenScale)
(0) Shift the panel to the midpoint where it needs to go (TweenPosition)

Panels b,c,d need:
(1) Shift the panel to the right most position it can be

UIButtonTween to target tweengroup 0
And panel a requires:
UIButtonTween to target tweengroup 1 on b, c, d
UIButtonTween to reverse the TweenScale on all of the panels (since it doesn't know which one is open)

That is at most 5 UIButtonTweens.

But, I just found out a consequence of this solution is this:
If B is open and you select C, than because the TweenPosition has a start position it resets itself back to the start point (In (1)) and scales from there and shifts from there. So, I probably need to add even more tween scripts.

I feel like I am doing something wrong in this scenario. Am I missing something? I am going to end up with a lot of UIButtonTweens like this as well as because I can't just tell the object to go from where it is to X position, it resets itself.

Is there a way to specify that I want this tween to just tween the object from where it is currently, to position X? Instead of there having to be a start position? Same with scale, do I need to have a Y and Z scale? I just want to scale in one direction.

This question and/or description might be complicated. Sorry.

EDIT: While I am sure I could programmatically do this I want to avoid adding code to do this as it becomes hard to scale things like that, and I want to try to do as much of the UI in this way as possible. Thanks again.
« Last Edit: August 17, 2012, 05:11:32 PM by PiWizard »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweening multiple gameobjects with one tween event
« Reply #6 on: August 17, 2012, 06:59:20 PM »
Write a custom class to this attached to the parent. It should have a reference to the "current selection". Have each child notify the parent when they're clicked on, and inside the notification function, if (newObject != currentSelection), tween currentSelection back and newObject forward. Set currentSelection to be the new object. Done.

PiWizard

  • Guest
Re: Tweening multiple gameobjects with one tween event
« Reply #7 on: August 17, 2012, 07:15:57 PM »
Yeah. Was hoping to avoid that ;)

Alright will need to try that thanks

goodtimeshaxor

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Tweening multiple gameobjects with one tween event
« Reply #8 on: August 18, 2012, 01:47:44 PM »
My problem is related to this so I thought I'd reply instead of making a new post.

I have tried using "Include Children" but the issue for me is that the children are Anchored. I have already added Tween scripts to the panels within the Anchors but "Include Children" doesn't seem to reach that far.

Do I have to use multiple "UIButtonTween" scripts or is there a better solution?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweening multiple gameobjects with one tween event
« Reply #9 on: August 18, 2012, 05:47:45 PM »
Why are you anchoring children? What are they anchored to? Regardless though, "include children" should notify everyone in the hierarchy.

goodtimeshaxor

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Tweening multiple gameobjects with one tween event
« Reply #10 on: August 18, 2012, 07:14:35 PM »
Why are you anchoring children? What are they anchored to? Regardless though, "include children" should notify everyone in the hierarchy.

This is how my scene is setup:

UIRoot
-Camera
--Level Select (Empty Game Object) *Want this go and all children to Tween
---Anchor - Bottom Left
----Panel
-----Button
---Anchor - Left
----Panel
-----Button

I want a button in another 2nd tier empty game object to trigger the tween animation in all the objects under "Level Select". It doesn't seem to get passed the Anchors even though all the Tween Scripts are in the same "Group". Any additional thoughts? Am I doing something wrong here?
« Last Edit: August 18, 2012, 07:23:15 PM by goodtimeshaxor »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweening multiple gameobjects with one tween event
« Reply #11 on: August 18, 2012, 07:31:08 PM »
Only reason it wont work is if your game objects are disabled

goodtimeshaxor

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Tweening multiple gameobjects with one tween event
« Reply #12 on: August 18, 2012, 07:47:02 PM »
Only reason it wont work is if your game objects are disabled

All game objects and children under "Level Select" are indeed enabled before, at, and after the time the button is clicked. I'll continue messing with this and seeing what I can do. Any other ideas are greatly appreciated as is all the help you've already contributed!

EDIT: Found the issue. I was being stupid. Thanks
« Last Edit: August 18, 2012, 08:38:51 PM by goodtimeshaxor »

PiWizard

  • Guest
Re: Tweening multiple gameobjects with one tween event
« Reply #13 on: August 18, 2012, 08:48:08 PM »
Hey Aren,

I found a better way to do it which makes it a lot smoother. And, it was thanks to one of your examples ;)

Quest log! I forgot about it, UITable, horizontal, update table. I only need one tweenscale now and no tween positions.

Thanks for the great examples :D

PabloAM

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 58
    • View Profile
Re: Tweening multiple gameobjects with one tween event
« Reply #14 on: March 28, 2013, 11:43:59 AM »
Could be possible store the tw in a variable of type "TweenPostition"?

Something like this:
  1. TweenPosition AniPos3;
  2.  
  3. UITweener[] tweens = GetComponents<UITweener>();
  4.                 foreach (UITweener tw in tweens){
  5.                         if (tw.tweenGroup == 3)
  6.                         {
  7.                                 if(tw.GetType().ToString() == "TweenPosition")
  8.                                 {
  9.                                         AniPos3 = tw;
  10.                                        
  11.                                         //THIS DOESN´T WORKS (UPDATED NOW WORKS :D with the casting, Read at bottom)
  12.                                         AniPos3.from = transform.localPosition;
  13.                                        
  14.                                 }
  15.  

FIXED !!!

Just add a casting to the type of Tween:

  1. AniPos3 = (TweenPosition)tw ;

I hope helps someone! :D

Thanks!