U3D同结构面板Prefab同代码(名称不同)如何快速替换UI

本文介绍了一种在UI框架下进行标准Prefab与需替换Prefab之间的转换步骤,包括更改名称、检查UI组件一致性等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UI框架下可用

标准Prefab(已换好)

需换Prefab(未换好)

1、标准P和需换P都拉到Hierarchy窗口中

2、在Hierarchy窗口把标准P的名称改为需换P的名称

3、在Project窗口中把需换P的名称更改为其他(作为副本p)

4、在Hierarchy窗口中把刚刚换成 需换P名称 的 标准P 拉到需换P的同目录下

5、在Hierarchy窗口中检查需换P的UI Name Table、UI Event Table、UI Variable Table三个组件与副本p是否一致,UI Name Table可能需要重新拖一遍

using UnityEngine; using System; using System.Collections; using XLua; namespace LuaFramework { [LuaCallCSharp] public class ResourceManager : Manager { public static ResourceManager _instance; public LuaFunction onDestroy; private WWW _www; private LuaFunction onProgress; void Awake() { _instance = this; } // 修复1: 使用传统属性语法替代表达式体属性 public static ResourceManager Instance { get { return _instance; } } public void CreatUIObject(string UIPath, string objname, LuaFunction callBack = null) { #if UNITY_EDITOR if (!AppConst.UpdateMode) { string path = "datingui_" + AppConst.UIVersion.ToString() + "/" + UIPath + objname; UnityEngine.Object prefab = Resources.Load(path, typeof(GameObject)); if (prefab != null) { GameObject obj = Instantiate(prefab) as GameObject; obj.transform.localScale = Vector3.one; obj.transform.localPosition = Vector3.zero; if (callBack != null) { callBack.Call(obj); } } else { if (callBack != null) { callBack.Call(null); } } } else { StartCoroutine(LoadObj(AppConst.FrameworkRoot + "/datingui_" + AppConst.UIVersion + "/" + UIPath + objname + ".u3d", objname, callBack)); } #else StartCoroutine(LoadObj(AppConst.FrameworkRoot + "/datingui_" + AppConst.UIVersion + "/" + UIPath + objname + ".u3d", objname, callBack)); #endif } public void CreatGameObject(string GameName, string path, string objname, LuaFunction callBack = null) { #if UNITY_EDITOR if (!AppConst.UpdateMode) { GameObject obj = Instantiate(Resources.Load<GameObject>("gameui" + AppConst.UIVersion + "/" + GameName + "/" + path + objname)); if (obj != null) { obj.transform.localScale = Vector3.one; obj.transform.localPosition = Vector3.zero; } if (callBack != null) { callBack.Call(obj); } } else { string path_ = AppConst.FrameworkRoot + "/gameui" + AppConst.UIVersion + "/" + GameName + "/" + path + objname + ".u3d"; StartCoroutine(LoadObj(path_, objname, callBack)); } #else string path_ = AppConst.FrameworkRoot + "/gameui"+AppConst.UIVersion +"/" + GameName + "/" + path + objname + ".u3d"; StartCoroutine(LoadObj(path_, objname, callBack)); #endif } public void setProgressUpdate(LuaFunction callback) { onProgress = callback; } public void resetProgressUpdate() { onProgress = null; _www = null; } float jindus = 0.0f; void Update() { #if UNITY_ANDROID if (_www != null && onProgress != null) { onProgress.Call(_www.progress); } #else if (onProgress != null) { onProgress.Call(jindus); } #endif } IEnumerator LoadObj(string bundlePath, string ObjName, LuaFunction callBack = null) { AssetBundle built = null; #if UNITY_ANDROID string path_2 = "file:///" + bundlePath; WWW www = new WWW(@path_2); if (onProgress != null) { _www = www; } yield return www; if (www.error == null) { built = www.assetBundle; } else { Debug.Log("www error: " + www.error + " at path: " + path_2); } #else string path_ = bundlePath; byte[] data = null; if (System.IO.File.Exists(path_)) { System.IO.FileStream file_ = new System.IO.FileStream(path_, System.IO.FileMode.Open, System.IO.FileAccess.Read); data = new byte[file_.Length]; int redline = 0; int allnum = 0; while (true) { byte[] reddata = new byte[1024000]; redline = file_.Read(reddata, 0, reddata.Length); if (redline <= 0) { jindus = 1.0f; break; } else { System.Array.Copy(reddata, 0, data, allnum, redline); allnum += redline; jindus = (float)allnum / (float)data.Length; } yield return null; } file_.Close(); file_.Dispose(); } if (data != null) { built = AssetBundle.LoadFromMemory(data); } #endif GameObject obj = null; if (built != null) { UnityEngine.Object asset = built.LoadAsset(ObjName); if (asset != null) { obj = Instantiate(asset) as GameObject; if (obj != null) { obj.transform.localScale = Vector3.one; obj.transform.localPosition = Vector3.zero; } } built.Unload(false); } if (callBack != null) { callBack.Call(obj); } #if UNITY_ANDROID www.Dispose(); #endif yield break; } void OnDestroy() { if (onDestroy != null) { onDestroy.Call(); } } } }帮我检查一下优化代码UNITY5.3.8里面使用
最新发布
07-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值