资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

UnityNGUI的Anchors编程-创新互联

Unity NGUI的Anchors编程

为昭平等地区用户提供了全套网页设计制作服务,及昭平网站建设行业解决方案。主营业务为成都网站制作、做网站、外贸营销网站建设、昭平网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

有些时候需要动态改变Left , Right , Bottom ,Top的值.有这样需求的游戏非常的多,比如:需要移位一个Panel零时加入另一个Panel(操作工具)面板.

举个例子 , 游戏中 , 对每个玩家的操作都有时间限制 . 这样,对各个玩家的时间提醒,就可以用一个闹钟类,只需要改变它的Anchors和坐标就行了

举个栗子:

    /// 
    /// 设置闹钟位置
    /// 
    /// 用户座位ID
    public void SetAlarmClockPos( ushort _chairID )
    {
        if (this.chairID != _chairID)
        {
            if (this._sprite == null) this._sprite = gameObject.GetComponent();
            this.chairID = _chairID;
            ushort _pos = Defines.SwapViewID(this.chairID);
            this._sprite.GetComponent().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().enabled = true;
        }
    }

在操作Anchors时 , 一定要记住:

 this._sprite.GetComponent().enabled = false;

将Widget设为不可用.

另外 : 设置其坐标

在这里需要指出的是 : relative , absolute

relative : 指出的是相对于那边停靠

记住 : 左 -> 中 - > 右 / 下->中->上 一次是 0 , 0,5 , 1

关于absolute 这是 后面的值(相对的)

再将Widget设为可用.

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享标题:UnityNGUI的Anchors编程-创新互联
网站路径:http://cdkjz.cn/article/pgcsj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220