2

回电没有被解雇,看不出有什么问题,我买了 5 美元的样品包,据我所知,我正确地遵循了他们的模式。我以前成功使用过这个。

因此,在下面的此类中,特定按钮已被按下或被取消选择。在这种情况下,我专门调试选定的补间,但都不能正常工作。InstantSelectionSpritesUp() 函数工作正常,它手动进入并将颜色 alpha 设置回 1。这工作正常,所以我已将其注释掉,现在正在尝试补间。补间不起作用。通过 Debug.Log 我知道 SetAsSelected() 和 FadeSelectionSpritesUp() 实际上正在被调用。虽然没有调用 UpdateIconAlpha() 和 UpdateBGAlpha,因为没有日志打印到控制台。StopTweens() 存在是因为当您在同一个 GameObject 上调用新的补间时,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

4

0 回答 0