UGUI工厂
发布日期:2021-06-30 19:38:48 浏览次数:2 分类:技术文章

本文共 8072 字,大约阅读时间需要 26 分钟。

为了方便用代码创建UGUI,封装了一个工厂类,写了一点,后续有空再添加没有添加的组件的封装

代码如下:

using UnityEngine;using UnityEngine.UI;using System.Collections;using System.Collections.Generic;using System;public class UGUIFactory{    public static GameObject CreateImage(GameObject parent, string name, string sprName, Vector3 pos)    {        GameObject go = AddChild(parent, name);        go.transform.localPosition = pos;        go.transform.localScale = Vector2.one;        var image = go.AddComponent();        image.sprite = getSpriteByName(sprName);        var rectTrans = go.GetComponent
(); image.SetNativeSize(); return go; } public static GameObject CreateImage(GameObject parent, string name, string sprName,Vector3 pos,Vector2 size) { GameObject go = AddChild(parent, name); go.transform.localPosition = pos; var image = go.AddComponent
(); image.sprite = getSpriteByName(sprName); var rectTrans = go.GetComponent
(); rectTrans.sizeDelta = size; return go; } public static GameObject CreateImageButton(GameObject parent,string name,string sprName,Vector3 pos,Vector2 size,System.Action
onClick) { GameObject go = CreateImage(parent, name, sprName, pos, size); var btn = go.AddComponent

转载地址:https://linxinfa.blog.csdn.net/article/details/51932982 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:UGUI如何在UI与UI直接穿插粒子特效和模型
下一篇:C#文件读写常用接口

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月05日 08时48分29秒