Unity3D 5.0 + iTween + NGUI ::麻烦使用iTween.ValueTo

时间:2015-04-03 07:35:53

标签: unity3d itween

回叫没有被解雇,看不出有什么问题,我买了5美元的样品,据我所知,我正在按照他们的模式正确行事。我成功之前已经使用过这个。

因此,在下面的这个类中,已按下或正在取消选择某个特定按钮。在这种情况下,我专门调试所选的补间,但都无法正常工作。 InstantSelectionSpritesUp()函数工作正常,它手动到达并将颜色alpha设置为1.这很好,所以我已经注释掉了,现在正在尝试补间。补间不起作用。通过Debug.Log,我知道实际上正在调用SetAsSelected()和FadeSelectionSpritesUp()。但是没有调用UpdateIconAlpha()和UpdateBGAlpha,因为没有日志打印到控制台。 StopTweens()就在那里,因为当您在同一个GameObject上调用新的补间时,iTween不会自动销毁预先存在的补间。我已经对此进行了评论,没有任何变化,所以这不是问题。我如何格式化iTween调用是不对的。

public class NavigationButton : MonoBehaviour{
// this is the super class for all of the navigation buttons

public UISprite bgDeselected;
public UISprite bgSelected;
public UISprite iconDeselected;
public UISprite iconSelected;

protected bool isCurrentlySelected = false;
protected float fadeTime = 0.5f;
protected Color alphaZero = new Color( 1.0f, 1.0f, 1.0f, 0.0f );
protected Color alphaOne = new Color( 1.0f, 1.0f, 1.0f, 1.0f );

// ----------------------------------------------------------------------------------------------------------------------------

void Start()
{
    // make the selected state of the button zero instantly so the user doesn't see it at all on app load
    InstantSelectionSpritesDown();
}

// ----------------------------------------------------------------------------------------------------------------------------

public void SetAsSelected()
{
    Debug.Log ( this.gameObject.name + ":SetAsSelected()" );

    // this funcion is called because this button has been pressed
    // we want this button to now show as being selected
    FadeSelectionSpritesUp();
    //InstantSelectionSpritesUp();

    isCurrentlySelected = true;
}

public void SetAsDeselected()
{
    Debug.Log ( this.gameObject.name + ":SetAsDeselected()" );

    // this funcion is called because the button another button in the nav has been pressed
    // we want this button to now show as being not selected
    //FadeSelectionSpritesDown();
    InstantSelectionSpritesDown();

    isCurrentlySelected = false;
}

// ----------------------------------------------------------------------------------------------------------------------------

protected void FadeSelectionSpritesDown()
{
    Debug.Log ( this.gameObject.name + ":FadeSelectionSpritesDown() :: iconSelected.gameObject:"+iconSelected.gameObject+" :: bgSelected.gameObject:"+bgSelected.gameObject  );
    //StopTweens();??

    // this function fades the alpha of the BG and Icon sprites down to 0% alpha
    iTween.ValueTo( iconSelected.gameObject ,iTween.Hash( "from", 1.0f, "to", 0.0f, "time", fadeTime, "onUpdate", "UpdateIconAlpha"));
    iTween.ValueTo( bgSelected.gameObject ,iTween.Hash( "from", 1.0f, "to", 0.0f, "time", fadeTime, "onUpdate", "UpdateBGAlpha"));
}

protected void FadeSelectionSpritesUp()
{
    Debug.Log ( this.gameObject.name + ":FadeSelectionSpritesUp() :: iconSelected.gameObject:"+iconSelected.gameObject+" :: bgSelected.gameObject:"+bgSelected.gameObject  );
    StopTweens();

    // this function fades the alpha of the BG and Icon sprites up to 100%
    iTween.ValueTo( iconSelected.gameObject ,iTween.Hash( "from", 0.0f, "to", 1.0f, "time", fadeTime, "onUpdate", "UpdateIconAlpha"));
    iTween.ValueTo( bgSelected.gameObject ,iTween.Hash( "from", 0.0f, "to", 1.0f, "time", fadeTime, "onUpdate", "UpdateBGAlpha"));
}

// ----------------------------------------------------------------------------------------------------------------------------

protected void StopTweens()
{
    // iTween doesn't destroy tweens that are already going if a new tween is added to the same object, so we need to destroy existing tweens manually
    iTween.Stop(iconSelected.gameObject);
    iTween.Stop(bgSelected.gameObject);
}

protected void UpdateIconAlpha( float alphaAsFloat )
{
    Debug.Log ( this.gameObject.name + ":UpdateIconAlpha() :: alphaAsFloat:"+alphaAsFloat+" :: bgSelected.gameObject:"+iconSelected  );
    iconSelected.color = new Color( alphaOne.r, alphaOne.g, alphaOne.b, alphaAsFloat );
}

protected void UpdateBGAlpha( float alphaAsFloat )
{
    Debug.Log ( this.gameObject.name + ":UpdateBGAlpha() :: alphaAsFloat:"+alphaAsFloat+" :: bgSelected.gameObject:"+bgSelected  );
    bgSelected.color = new Color( alphaOne.r, alphaOne.g, alphaOne.b, alphaAsFloat );
}

// ----------------------------------------------------------------------------------------------------------------------------

protected void InstantSelectionSpritesDown()
{
    // this function instantly sets the alpha of the BG and Icon sprites to 0% alpha
    iconSelected.color = alphaZero;
    bgSelected.color = alphaZero;
}

protected void InstantSelectionSpritesUp()
{
    // this function instantly sets the alpha of the BG and Icon sprites to 100% alpha
    iconSelected.color = alphaOne;
    bgSelected.color = alphaOne;
}}

有什么想法吗?

谢谢! 德拉

RebelFuture.com OpenSourceRebellion.com

0 个答案:

没有答案