Author Topic: Reverse tweening via code  (Read 3633 times)

rain

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 79
    • View Profile
Reverse tweening via code
« on: May 11, 2012, 12:05:58 PM »
Hi!

I have a menu bar which i instantiate via code into the game. It has a UIGrid with Button GameObjects, each button having a tween position script attached to it. These tween position scripts are disabled by default and set in a way that the buttons don't arrive at their destination in the same time, but with a delay. The method which instantiates the the menu bar (playTweens) starts the tween position scripts by iterating through the UIGrid's Button GameObjects.

I am currently trying to make these tween position scripts reversible( menu Back button ), but I have no clue on how to call the tween position scripts reversed.

Regards


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Reverse tweening via code
« Reply #1 on: May 11, 2012, 02:47:17 PM »
UITweener has a Play() function that accepts a direction as the parameter. You can play forward or back.

rain

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 79
    • View Profile
Re: Reverse tweening via code
« Reply #2 on: May 12, 2012, 07:31:16 AM »
I've already tried, it. No results. :(

Here's how i'm doing it,

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class SettingsButton : MonoBehaviour
  5. {
  6.        
  7.         public TweenPosition[] tweener;
  8.         public GameObject Settings;
  9.         GameObject Current;
  10.         public Transform GUIMAINPANEL;
  11.         // Use this for initialization
  12.         void Start ()
  13.         {
  14.                 tweener = new TweenPosition[6];        
  15.         }
  16.        
  17.         void fillTweenerArray()
  18.         {
  19.                 Transform Grid = GameObject.Find("UIGrid").transform;
  20.                 int j=0;
  21.                 for(int i=0;i<Grid.childCount;i++)
  22.                 {
  23.                         if(Grid.GetChild(i).name == "Button")
  24.                         {
  25.                                 tweener[j] = Grid.GetChild(i).GetComponent("TweenPosition") as TweenPosition;
  26.                                 j++;
  27.                         }                              
  28.                 }
  29.         }
  30.        
  31.         void playTweens(bool forward)
  32.         {
  33.                 foreach(TweenPosition tween in tweener)
  34.                 {
  35.                         tween.Play(true);
  36.                 }
  37.         }
  38.        
  39.         void OnClick()
  40.         {
  41.                 if(Current == null)
  42.                 {              
  43.                         Current = Instantiate(Settings,Vector3.zero,Quaternion.identity) as GameObject;
  44.                         Destroy(Current.GetComponent("UIPanel"));
  45.                         Current.transform.parent = GUIMAINPANEL;               
  46.                         fillTweenerArray();                    
  47.                         Current.transform.position = new Vector3(-380f,79.1f,-167.4f);
  48.                         Current.transform.localScale = new Vector3(1f,1f,1f);
  49.                         StartCoroutine(reposition(Current)); // just a yield and a sendmessage to reposition the grid
  50.                         playTweens(true);
  51.                 }
  52.                 else
  53.                 {
  54.                         playTweens(false);
  55.                 }
  56.                
  57.                        
  58.         }
  59.  
  60.        
  61.         IEnumerator reposition(GameObject Current)
  62.         {
  63.                 yield return null;
  64.                 Current.transform.FindChild("UIGrid").GetComponent("UIGrid").SendMessage("Reposition");
  65.         }
  66. }
  67.  
« Last Edit: May 12, 2012, 07:49:58 AM by rain »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Reverse tweening via code
« Reply #3 on: May 12, 2012, 04:24:46 PM »
  1.     void playTweens(bool forward)
  2.     {
  3.         foreach(TweenPosition tween in tweener)
  4.         {
  5.             tween.Play(true);
  6.         }
  7.     }

You don't see anything wrong with that? :P

rain

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 79
    • View Profile
Re: Reverse tweening via code
« Reply #4 on: May 12, 2012, 04:50:51 PM »
Mother of god, how did i not notice it? Thanks a lot :D