1

有没有办法我们可以在运行时游戏对象下制作运行时按钮?我能够使用 UIToolkit 中的所有组件/材料继承运行时游戏对象。

这是我的代码:

    public class loadImage : MonoBehaviour
{

    public UIToolkit duplicate_kit;
    public Material material;
    public UIButton b1, b2;
    public MeshFilter meshFilter;
    public MeshRenderer meshRenderer;
    public Mesh _mesh;


    void initKit()
    {

        Material duplicateMaterial = new Material (material.shader);
        duplicateMaterial.CopyPropertiesFromMaterial(material);
        material = duplicateMaterial;

        GameObject loadImageToolkit = new GameObject("duplicate_toolkit");
        loadImageToolkit.transform.parent = GameObject.Find("UI").transform;
        loadImageToolkit.layer = LayerMask.NameToLayer("UILayer");


        duplicate_kit = loadImageToolkit.AddComponent<UIToolkit>() ;
        duplicate_kit.texturePackerConfigName = "friendsImageSheet";
        duplicate_kit.material = duplicateMaterial;

        meshRenderer = loadImageToolkit.AddComponent<MeshRenderer>();
        meshRenderer.renderer.material = duplicateMaterial;

        meshFilter = loadImageToolkit.AddComponent<MeshFilter>();
        _mesh = meshFilter.mesh;


    }

    void Start()
    {
         initKit();

//       b1 = UIButton.create( duplicate_kit, "FriendsAvatar.png","FriendsAvatar.png",0,0); 
//       b1.pixelsFromTopLeft ( 60, 0 );
//       StartCoroutine(getImage(b1));


         b2 = UIButton.create( duplicate_kit, "FriendsAvatar.png", "FriendsAvatar.png" , 0,0 );
         b2.pixelsFromTopLeft( 120, 0 );
         StartCoroutine(getImage(b2));


         b1 = UIButton.create( (UIToolkit)GameObject.Find("duplicate_toolkit").GetComponent(typeof(UIToolkit)), "FriendsAvatar.png","FriendsAvatar.png",0,0);   
         b1.pixelsFromTopLeft ( 120, 0 );
         StartCoroutine(getImage(b1));

    }

    IEnumerator getImage(UIButton uib)
    {      
        WWW imageRequest = new WWW("https://graph.facebook.com/xxxxxxxxx/picture?type=small"); 
        yield return imageRequest;
        Texture tex = imageRequest.texture;

        uib.manager.renderer.material.mainTextureScale = new Vector2(18.0f,20.05f);
        uib.manager.renderer.material.mainTexture = tex;
    }

}

主要目标是 b2 按钮应该出现在 duplicate_toolkit(Game Object) 下

就像是 :

重复工具包

用户界面按钮

在此处输入图像描述

4

1 回答 1

0

我没有使用 UITokit,但通常你在 Unity 中通过连接Transform组件来做到这一点:

b2.transform.parent = duplicate_toolkit.transform;
于 2012-10-18T07:45:49.230 回答