static int Init(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); UILuaBehaviour obj = (UILuaBehaviour)ToLua.CheckObject(L, 1, typeof(UILuaBehaviour)); LuaTable arg0 = ToLua.CheckLuaTable(L, 2); obj.Init(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
//private Dictionary<string, StaticAssetLoader> mUIPrefabLoaders = new Dictionary<string, StaticAssetLoader>(); //private List<GameObject> mUIList = new List<GameObject>(); //private Dictionary<string, GameObjectCache> mResCaches = new Dictionary<string, GameObjectCache>(); public void GetUIPrefab(string assetName, Transform parent, LuaTable luaTable, LuaFunction luaCallBack) { if (mResManager == null) { return; } string tmpAssetName = "uiprefab/" + assetName; if (AssetFileLoader.IsEditorLoadAsset) { tmpAssetName = "BuildByFile/" + tmpAssetName + ".prefab"; } StaticAssetLoader.Load(tmpAssetName, (bool isOk, Object resultObj) => { if (!isOk || resultObj == null) { Log.Error("GetUIPrefab is error:{0}", tmpAssetName); return; } GameObject go = resultObj as GameObject; if (go == null) { Log.Error("GetUIPrefab go is null:{0}", tmpAssetName); return; } go.name = assetName; go.layer = LayerMask.NameToLayer("UI"); Vector3 anchorPos = Vector3.zero; Vector2 sizeDel = Vector2.zero; Vector3 scale = Vector3.one; RectTransform rtTr = go.GetComponent <RectTransform>(); if (rtTr != null) { anchorPos = rtTr.anchoredPosition; sizeDel = rtTr.sizeDelta; scale = rtTr.localScale; } go.transform.SetParent(parent, false); if (rtTr != null) { rtTr.anchoredPosition = anchorPos; rtTr.sizeDelta = sizeDel; rtTr.localScale = scale; } UILuaBehaviour tmpBehaviour = Tools.SafeGetComponent <UILuaBehaviour>(go); tmpBehaviour.Init(luaTable); if (luaCallBack != null) { luaCallBack.BeginPCall(); luaCallBack.Push(go); luaCallBack.PCall(); luaCallBack.EndPCall(); luaCallBack.Dispose(); luaCallBack = null; } Debug.Log("CreatePanel::>> " + assetName); }); }
public void GetUIPrefab(string assetName, Transform parent, LuaTable luaTable, LuaFunction luaCallBack) { if (mResManager == null) { return; } string tmpAssetName = assetName; if (GameSetting.DevelopMode) { tmpAssetName = "UIPrefab/" + assetName; } mResManager.LoadPrefab(assetName + GameSetting.ExtName, tmpAssetName, delegate(UnityEngine.Object[] objs) { if (objs.Length == 0) { return; } GameObject prefab = objs[0] as GameObject; if (prefab == null) { return; } GameObject go = UnityEngine.GameObject.Instantiate(prefab) as GameObject; go.name = assetName; go.layer = LayerMask.NameToLayer("UI"); Vector3 anchorPos = Vector3.zero; Vector2 sizeDel = Vector2.zero; Vector3 scale = Vector3.one; RectTransform rtTr = go.GetComponent <RectTransform>(); if (rtTr != null) { anchorPos = rtTr.anchoredPosition; sizeDel = rtTr.sizeDelta; scale = rtTr.localScale; } go.transform.SetParent(parent, false); if (rtTr != null) { rtTr.anchoredPosition = anchorPos; rtTr.sizeDelta = sizeDel; rtTr.localScale = scale; } UILuaBehaviour tmpBehaviour = go.AddComponent <UILuaBehaviour>(); tmpBehaviour.Init(luaTable); if (luaCallBack != null) { luaCallBack.BeginPCall(); luaCallBack.Push(go); luaCallBack.PCall(); luaCallBack.EndPCall(); luaCallBack.Dispose(); luaCallBack = null; } Debug.Log("CreatePanel::>> " + assetName + " " + prefab); //mUIList.Add(go); }); }