您好,登錄后才能下訂單哦!
有些時候需要動態改變Left , Right , Bottom ,Top的值.有這樣需求的游戲非常的多,比如:需要移位一個Panel零時加入另一個Panel(操作工具)面板.
舉個例子 , 游戲中 , 對每個玩家的操作都有時間限制 . 這樣,對各個玩家的時間提醒,就可以用一個鬧鐘類,只需要改變它的Anchors和坐標就行了
舉個栗子:
/// <summary> /// 設置鬧鐘位置 /// </summary> /// <param name="_userID">用戶座位ID</param> public void SetAlarmClockPos( ushort _chairID ) { if (this.chairID != _chairID) { if (this._sprite == null) this._sprite = gameObject.GetComponent<UISprite>(); this.chairID = _chairID; ushort _pos = Defines.SwapViewID(this.chairID); this._sprite.GetComponent<UIWidget>().enabled = false; switch (_pos) { case 0://我自己 this.gameObject.transform.localPosition = new Vector3(-375, -384, 0); this._sprite.leftAnchor.relative = 1; this._sprite.leftAnchor.absolute = -339; this._sprite.rightAnchor.relative = 1; this._sprite.rightAnchor.absolute = -277; this._sprite.bottomAnchor.relative = 0; this._sprite.bottomAnchor.absolute = 12; this._sprite.topAnchor.relative = 0; this._sprite.topAnchor.absolute = 94; break; case 1://左上 this.gameObject.transform.localPosition = new Vector3(-412, 387, 0); this._sprite.leftAnchor.relative = 1; this._sprite.leftAnchor.absolute = -302; this._sprite.rightAnchor.relative = 1; this._sprite.rightAnchor.absolute = -240; this._sprite.bottomAnchor.relative = 1; this._sprite.bottomAnchor.absolute = -91; this._sprite.topAnchor.relative = 1; this._sprite.topAnchor.absolute = -9; break; case 2://右上 this.gameObject.transform.localPosition = new Vector3( -412 , 387 , 0 ); this._sprite.leftAnchor.relative = 0; this._sprite.leftAnchor.absolute = 240; this._sprite.rightAnchor.relative = 0; this._sprite.rightAnchor.absolute = 302; this._sprite.bottomAnchor.relative = 1; this._sprite.bottomAnchor.absolute = -91; this._sprite.topAnchor.relative = 1; this._sprite.topAnchor.absolute = -9; break; default: if (gameObject.activeSelf) gameObject.SetActive(false); this.Stop(); break; } this._sprite.GetComponent<UIWidget>().enabled = true; } }
在操作Anchors時 , 一定要記住:
this._sprite.GetComponent<UIWidget>().enabled = false;
將Widget設為不可用.
另外 : 設置其坐標
在這里需要指出的是 : relative , absolute
relative : 指出的是相對于那邊停靠
記住 : 左 -> 中 - > 右 / 下->中->上 一次是 0 , 0,5 , 1
關于absolute 這是 后面的值(相對的)
再將Widget設為可用.
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。