Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - edb

Pages: 1 2 [3]
31
Support / Position sprite differently when in portrait vs. landscape
« on: November 19, 2014, 12:41:09 am »
I'm working on a mobile game that allows you to play in portrait or landscape.  I'd like to position a sprite in a different place when it's in portrait mode.  Is there anything in 2d Toolkit that could position a sprite in a different place depending on portrait vs. landscape?

My backup plan is to have a PostionStuff() function that gets called when a change from portrait <--> landscape is detected, but first wanted to see if tk2d had some nifty trick.

32
Support / Re: Use 2d Toolkit Sprite Collection for everything in game?
« on: October 28, 2014, 07:13:51 pm »
Thanks - will investigate.

33
Support / Re: Proper way to code my own tween for UI Item
« on: October 28, 2014, 07:12:02 pm »
Also my previous modifications were a bit wonky - this works better:

Code: [Select]
using UnityEngine;
using System.Collections;

/// <summary>
/// Will move and scale uiItem up and down, on press events
/// </summary>
[AddComponentMenu("2D Toolkit/UI/tk2dUITweenItem")]
public class tk2dUITweenItem : tk2dUIBaseItemControl
{
    private Vector3 onUpScale; //keeps track of original scale
    private Vector3 onUpMove; //keeps track of original position

    /// <summary>
    /// What it should scale to onDown event
    /// </summary>
    public Vector3 onDownScale = new Vector3(1, 1, 1);

/// <summary>
/// How much it should move/offset onDown event
/// </summary>
public Vector3 onDownOffsetAmt = new Vector3(0.0f, -3.5f, 0);

    /// <summary>
    /// How long the tween (scaling) should last in seconds. If set to 0 no tween is used, happens instantly.
    /// </summary>
    public float tweenDuration = 0.06f;

    /// <summary>
    /// If button can be held down (will not be scale back to original until up/release)
    /// Can not be toggled at run-time
    /// </summary>
    public bool canButtonBeHeldDown = true; //can not be toggled at runtime

    /// <summary>
    /// If using canButtonBeHeldDown, if the scale back to original should happen onRelease event instead of onUp event
    /// </summary>
    [SerializeField]
    private bool useOnReleaseInsteadOfOnUp = false;

    public bool UseOnReleaseInsteadOfOnUp
    {
        get { return useOnReleaseInsteadOfOnUp; }
    }

    private bool internalTweenInProgress = false;

    private Vector3 tweenTargetScale = Vector3.one;
    private Vector3 tweenStartingScale = Vector3.one;

     private Vector3 tweenTargetMove = Vector3.one;
     private Vector3 tweenStartingMove = Vector3.one;


    private float tweenTimeElapsed = 0;

//------------------------------------------------------------
void Awake()
       {
           onUpScale = transform.localScale;
   onUpMove = transform.localPosition;
}
//------------------------------------------------------------

//------------------------------------------------------------
void OnEnable()
       {
        if (uiItem)
        {
            uiItem.OnDown += ButtonDown;
            if (canButtonBeHeldDown)
            {
                if (useOnReleaseInsteadOfOnUp)
                {
                    uiItem.OnRelease += ButtonUp;
                }
                else
                {
                    uiItem.OnUp += ButtonUp;
                }
            }
        }
        internalTweenInProgress = false;
        tweenTimeElapsed = 0;

        transform.localScale = onUpScale;
transform.localPosition = onUpMove;
}
//------------------------------------------------------------

//------------------------------------------------------------
void OnDisable()
       {
        if (uiItem)
        {
            uiItem.OnDown -= ButtonDown;
            if (canButtonBeHeldDown)
            {
                if (useOnReleaseInsteadOfOnUp)
                {
                    uiItem.OnRelease -= ButtonUp;
                }
                else
                {
                    uiItem.OnUp -= ButtonUp;
                }
            }
        }
    }
   //------------------------------------------------------------

   //------------------------------------------------------------
   private void ButtonDown()
    {
        if (tweenDuration <= 0)
        {
            transform.localScale = onDownScale;
    transform.localPosition = onUpMove + onDownOffsetAmt;
}
        else
        {
            transform.localScale = onUpScale;
    transform.localPosition = onUpMove;

            tweenTargetScale = onDownScale;
            tweenStartingScale = transform.localScale;

    tweenTargetMove = onUpMove + onDownOffsetAmt;
    tweenStartingMove = transform.localPosition;


            if (!internalTweenInProgress)
            {
                StartCoroutine(ScaleAndMoveTween());
internalTweenInProgress = true;
            }
        }
    }
//------------------------------------------------------------

//------------------------------------------------------------
private void ButtonUp()
    {
        if (tweenDuration <= 0)
        {
             transform.localScale = onUpScale;
     transform.localPosition = onUpMove;
}
        else
        {
            tweenTargetScale = onUpScale;
            tweenStartingScale = transform.localScale;

    tweenTargetMove = onUpMove;
    tweenStartingMove = transform.localPosition;

            if (!internalTweenInProgress)
            {
StartCoroutine(ScaleAndMoveTween());
internalTweenInProgress = true;
            }     
        }
    }
//------------------------------------------------------------

//------------------------------------------------------------
private IEnumerator ScaleAndMoveTween()
    {
        tweenTimeElapsed = 0;
        while (tweenTimeElapsed < tweenDuration)
        {
             transform.localScale = Vector3.Lerp(tweenStartingScale,tweenTargetScale,tweenTimeElapsed / tweenDuration);
     transform.localPosition = Vector3.Lerp(tweenStartingMove,tweenTargetMove,tweenTimeElapsed / tweenDuration);
     yield return null;
            tweenTimeElapsed += tk2dUITime.deltaTime;
        }
           transform.localScale = tweenTargetScale;
   transform.localPosition = tweenTargetMove;
    internalTweenInProgress = false;

        //if button is not held down bounce it back
        if (!canButtonBeHeldDown)
        {
            if (tweenDuration <= 0)
            {
                transform.localScale = onUpScale;
transform.localPosition = onUpMove;
    }
            else
            {
                tweenTargetScale = onUpScale;
tweenTargetMove = onUpMove;
tweenStartingScale = transform.localScale;
tweenStartingMove = transform.localPosition;
StartCoroutine(ScaleAndMoveTween());
                internalTweenInProgress = true;
            }
        }
    }
//------------------------------------------------------------

//------------------------------------------------------------
/// <summary>
    /// Internal do not use
    /// </summary>
    public void InternalSetUseOnReleaseInsteadOfOnUp(bool state)
    {
        useOnReleaseInsteadOfOnUp = state;
    }
//------------------------------------------------------------

}

34
Support / Re: Proper way to code my own tween for UI Item
« on: October 28, 2014, 06:41:54 pm »
I tried out the script again after cleaning the build (by deleting the contents of the library folder) and it's working without errors!

For whoever's info - I also added this line to tk2dUITweenItemEditor.cs:

Code: [Select]
btnClickScaler.onDownOffsetAmt = EditorGUILayout.Vector3Field("On Down Offset Amt", btnClickScaler.onDownOffsetAmt);

35
Support / Re: Use 2d Toolkit Sprite Collection for everything in game?
« on: October 28, 2014, 05:39:17 pm »
Any suggestions (or info you can point me towards) for how to load the load the platform-appropriate size texture for a particle when a scene starts?

36
Support / Use 2d Toolkit Sprite Collection for everything in game?
« on: October 28, 2014, 05:19:27 pm »
I'm liking the platform specific 1x 2x 4x stuff a bunch - it's working great with sprites and fonts.

The game I'm working on targets PC, iOS and Android, so the runtime loading of the appropriate
1x 2x 4x image files is very useful.
 
So I'm wondering if I can get everything that uses a texture in the game to use a texture from
a 2d Toolkit SpriteCollection.

For instance, I've got some Unity particle systems in the game that are using regular Unity textures.
It'd be great if the particle system could instead use 2d Toolkit textures and load the appropriate 1x 2x 4x texture.

Possible?

37
Support / Re: Proper way to code my own tween for UI Item
« on: October 27, 2014, 03:39:51 pm »
I'm using Unity 4.5.5, by the way...

38
Support / Re: Proper way to code my own tween for UI Item
« on: October 27, 2014, 02:37:22 pm »
Here's the code where I modified the UITweenItem script to also support move offsets:

Code: [Select]
using UnityEngine;
using System.Collections;

/// <summary>
/// Will scale uiItem up and down, on press events
/// </summary>
[AddComponentMenu("2D Toolkit/UI/tk2dUITweenItem")]
public class tk2dUITweenItem : tk2dUIBaseItemControl
{
    private Vector3 onUpScale; //keeps track of original scale
    private Vector3 onUpMove; //keeps track of original position

    /// <summary>
    /// What it should scsale to onDown event
    /// </summary>
    public Vector3 onDownScale = new Vector3(.9f, .9f, .9f);

    /// <summary>
    /// What it should move to onDown event
    /// </summary>
    public Vector3 onDownOffsetAmt = new Vector3(5.0f, -5.0f, 0);

    /// <summary>
    /// How long the tween (scaling) should last in seconds. If set to 0 no tween is used, happens instantly.
    /// </summary>
    public float tweenDuration = .1f;

    /// <summary>
    /// If button can be held down (will not be scale back to original until up/release)
    /// Can not be toggled at run-time
    /// </summary>
    public bool canButtonBeHeldDown = true; //can not be toggled at runtime

    /// <summary>
    /// If using canButtonBeHeldDown, if the scale back to original should happen onRelease event instead of onUp event
    /// </summary>
    [SerializeField]
    private bool useOnReleaseInsteadOfOnUp = false;

    public bool UseOnReleaseInsteadOfOnUp
    {
        get { return useOnReleaseInsteadOfOnUp; }
    }

    private bool internalTweenInProgress = false;

    private Vector3 tweenTargetScale = Vector3.one;
    private Vector3 tweenStartingScale = Vector3.one;

    private Vector3 tweenTargetMove = Vector3.one;
    private Vector3 tweenStartingMove = Vector3.one;


    private float tweenTimeElapsed = 0;

    //------------------------------------------------------------
    void Awake()
    {
        onUpScale = transform.localScale;
onUpMove = transform.localPosition;
     }
    //------------------------------------------------------------

   //------------------------------------------------------------
   void OnEnable()
    {
        if (uiItem)
        {
            uiItem.OnDown += ButtonDown;
            if (canButtonBeHeldDown)
            {
                if (useOnReleaseInsteadOfOnUp)
                {
                    uiItem.OnRelease += ButtonUp;
                }
                else
                {
                    uiItem.OnUp += ButtonUp;
                }
            }
        }
        internalTweenInProgress = false;
        tweenTimeElapsed = 0;

        transform.localScale = onUpScale;
transform.localPosition = onUpMove;
     }
    //------------------------------------------------------------

    //------------------------------------------------------------
    void OnDisable()
    {
        if (uiItem)
        {
            uiItem.OnDown -= ButtonDown;
            if (canButtonBeHeldDown)
            {
                if (useOnReleaseInsteadOfOnUp)
                {
                    uiItem.OnRelease -= ButtonUp;
                }
                else
                {
                    uiItem.OnUp -= ButtonUp;
                }
            }
        }
    }
   //------------------------------------------------------------

   //------------------------------------------------------------
   private void ButtonDown()
    {
        if (tweenDuration <= 0)
        {
            transform.localScale = onDownScale;
    transform.localPosition = onUpMove + onDownOffsetAmt;
}
        else
        {
            transform.localScale = onUpScale;
    transform.localPosition = onUpMove;

            tweenTargetScale = onDownScale;
            tweenStartingScale = transform.localScale;

    tweenTargetMove = onUpMove + onDownOffsetAmt;
    tweenStartingMove = transform.localPosition;


            if (!internalTweenInProgress)
            {
                StartCoroutine(ScaleTween());
        StartCoroutine(MoveTween());
internalTweenInProgress = true;
            }
        }
    }
   //------------------------------------------------------------

   //------------------------------------------------------------
   private void ButtonUp()
    {
        if (tweenDuration <= 0)
        {
            transform.localScale = onUpScale;
    transform.localPosition = onUpMove;
}
        else
        {
            tweenTargetScale = onUpScale;
            tweenStartingScale = transform.localScale;

    tweenTargetMove = onUpMove;
    tweenStartingMove = transform.localPosition;

            if (!internalTweenInProgress)
            {
                StartCoroutine(ScaleTween());
StartCoroutine(MoveTween());
internalTweenInProgress = true;
            }     
        }
    }
    //------------------------------------------------------------

    //------------------------------------------------------------
    private IEnumerator ScaleTween()
    {
        tweenTimeElapsed = 0;
        while (tweenTimeElapsed < tweenDuration)
        {
            transform.localScale = Vector3.Lerp(tweenStartingScale,tweenTargetScale,tweenTimeElapsed / tweenDuration);
            yield return null;
            tweenTimeElapsed += tk2dUITime.deltaTime;
        }
        transform.localScale = tweenTargetScale;
        internalTweenInProgress = false;

        //if button is not held down bounce it back
        if (!canButtonBeHeldDown)
        {
            if (tweenDuration <= 0)
            {
                transform.localScale = onUpScale;
            }
            else
            {
                tweenTargetScale = onUpScale;
                tweenStartingScale = transform.localScale;
                StartCoroutine(ScaleTween());
                internalTweenInProgress = true;
            }
        }
    }
    //------------------------------------------------------------
    //------------------------------------------------------------
    private IEnumerator MoveTween()
    {
tweenTimeElapsed = 0;
while (tweenTimeElapsed < tweenDuration)
{
//transform.localScale = Vector3.Lerp(tweenStartingScale,tweenTargetScale,tweenTimeElapsed / tweenDuration);
transform.localPosition = Vector3.Lerp(tweenStartingMove,tweenTargetMove,tweenTimeElapsed / tweenDuration);
yield return null;
tweenTimeElapsed += tk2dUITime.deltaTime;
}
  //transform.localScale = tweenTargetScale;
  transform.localPosition = tweenTargetMove;
internalTweenInProgress = false;

//if button is not held down bounce it back
if (!canButtonBeHeldDown)
{
if (tweenDuration <= 0)
  {
//transform.localScale = onUpScale;
  transform.localPosition = onUpMove;
}
else
{
//tweenTargetScale = onUpScale;
tweenTargetMove = onUpMove;
//tweenStartingScale = transform.localScale;
tweenStartingMove = transform.localPosition;
StartCoroutine(MoveTween());
internalTweenInProgress = true;
}
}
}
//------------------------------------------------------------


//------------------------------------------------------------
/// <summary>
        /// Internal do not use
       /// </summary>
        public void InternalSetUseOnReleaseInsteadOfOnUp(bool state)
       {
            useOnReleaseInsteadOfOnUp = state;
        }
//------------------------------------------------------------

}



That's all I'm doing...maybe there's something else somewhere I need to change?

39
Support / Proper way to code my own tween for UI Item
« on: October 26, 2014, 09:37:45 pm »
I'm trying to code my own tween for when a button is clicked.  I want it to move down in Y instead of scale, so I can't use the UITweenItem script.  So I'm writing my own -  I modified UITweenItem to also support moves, and it works, but just one time, and then I keep getting the error in the attached screenshot.  I also tried duplicating the the UITweenItem, renaming it UITweenItem_Move, then modifying it for moves, but I also get the same error.

Any thoughts?

Pages: 1 2 [3]