public static UISprite CreateSpriteBy(RX_Card card, UISprite parent, float x)
{
float y = card.PositionY;
int depthNum = (int)x;
if (parent.tag != "cbottom")
{
float temp = x;
x = y;
y = temp;
depthNum = -depthNum;
}
//crate NGUI gameObject; can create gameObject -----3
UISprite sprite = NGUITools.AddChild <UISprite>(parent.gameObject);
//add (widget size)'s collider
//(if we want to add an interact function to the NGUI gameObjce,we must add collider fist!)
NGUITools.AddWidgetCollider(sprite.gameObject);
//only add Component(button) to interact, not create gameObject -----1
UIButton button = NGUITools.AddMissingComponent <UIButton>(sprite.gameObject);
sprite.depth = depthNum + 300;
sprite.atlas = RX_Resources.DefaultResources.Card_atlas;
sprite.spriteName = card.ToString();
sprite.SetRect(x, y, 52f, 70f); //the card's size changed to original 's 25%
button.onClick.Add(new EventDelegate(() =>
{
card.IsPop = !card.IsPop;
if (parent.tag == "cleft")
{
sprite.SetRect(card.PositionY, y, 52f, 70f);
}
else if (parent.tag == "cright")
{
sprite.SetRect(card.PositionY * (-1), y, 52f, 70f);
}
else
{
sprite.SetRect(x, card.PositionY, 52f, 70f);
}
}));
sprite.name = card.ToString();
//add to the sprite pool for destroy
Sprite_pool.Add(sprite);
return(sprite);
}