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); }
public static UISprite CreateSpriteBy(RX_Card card,UISprite parent,int pp,RX_SEAT_POSITION pos) { //创建精灵对象,通过NGUITools.AddChild函数 UISprite sprite = NGUITools.AddChild<UISprite> (parent.gameObject); //为图片对象添加碰撞器... NGUITools.AddWidgetCollider (sprite.gameObject); //为一个NGUI的游戏控件,添加缺失的组件 UIButton button = NGUITools.AddMissingComponent<UIButton> (sprite.gameObject); sprite.depth = pp + 300; sprite.atlas = RX_Resources.DefaultResources.CardAtlas; sprite.spriteName = card.ToString (); Rect sprite_rect = GetRect (pp,card.PositionY, pos); //设置NGUI控件在屏幕上的显示位置和大小 sprite.SetRect (sprite_rect.x, sprite_rect.y, sprite_rect.width, sprite_rect.heitht); button.onClick.Add (new EventDelegate (() => { card.IsPop = !card.IsPop; Rect sr = GetRect (pp,card.PositionY, pos); sprite.SetRect(sr.x,sr.y,sr.width,sr.heitht); })); return sprite; }
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; }