【问题标题】:Setting UIpanel size from script从脚本设置 UIpanel 大小
【发布时间】:2014-02-04 18:57:02
【问题描述】:

我正在尝试使用 Unity 的 NGUI 插件重新创建我的游戏,到目前为止我非常喜欢它,但在这个方面我一无所知。

我有一个名为 games 的 UIPanel,我想以编程方式更改它的大小,但不知道如何进入参数...

我试过这样,但没有运气:

GameObject.Find("Games").UIPanel.size.x = 300;

也试过这个,但没有运气:

GameObject.Find("Games").GetComponent("UIPanel").clipping.size.x = 300;

这不起作用,我不知道该怎么做...感谢任何帮助:-)

【问题讨论】:

    标签: c# unity3d unityscript ngui


    【解决方案1】:

    尝试设置 clipRange 属性。

    GameObject.Find("Games").GetComponent("UIPanel").clipRange = new Vector4(x, y, z , w); 
    

    【讨论】:

      【解决方案2】:

      您可以尝试以下两种方法之一。

      首先是通过设置UIRect角的绝对值(UIPanel继承自UIRect)

      mPanel.localCorners[0].Set(0.5f, 0.5f, 1f); //this is bottom_left corner
      

      您也可以使用 worldCorners 代替 localCorners。 如果面板被锚定,另一个选项是调整锚值。

      mPanel.leftAnchor.absolute = 200;
      

      【讨论】:

        【解决方案3】:

        不建议手动设置baseClipRange(由于文档原因),但您可以通过invoke clipOffset setter 生成完整的剪辑更新(它执行必要的内部操作)。

        当我想用移动的UIWidget 剪辑UIPanel 时,我也这样做了。

        // Set clipping region to some widget dimension.
        panel.baseClipRegion = new Vector4(
            clippingWidget.cachedTransform.localPosition.x,
            clippingWidget.cachedTransform.localPosition.y,
            clippingWidget.width,
            clippingWidget.height
            );
        
        // Invoke culling.
        panel.clipOffset += Vector2.one; 
        panel.clipOffset -= Vector2.one;
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-07-01
          • 2016-10-15
          • 2021-08-13
          • 1970-01-01
          • 1970-01-01
          • 2014-06-22
          相关资源
          最近更新 更多