using LuaInterface; using System; using System.Collections.Generic; using UnityEngine; public class ModelMgr : SingletonMono { private GameObject modelRoot; public GameObject ModelRoot { get { return modelRoot; } } private LuaTable luaTable; private Action, object[]> OnLoadedCompleted; private object[] param; public override void InitMgr() { modelRoot = GameObject.Find("ModelRoot"); if (modelRoot == null) { modelRoot = new GameObject("ModelRoot"); } DontDestroyOnLoad(modelRoot); } public void CreateModel(int[] ids, LuaTable table, Action, object[]> cb, params object[] param) { string assetPath = Constants.ModelPath; string[] assetNames = new string[ids.Length]; for (int i = 0; i < ids.Length; ++i) { string name = ConfigMgr.Instance.getValue(ids[i], "AvatarPrefab", "AvatarCfg"); assetNames[i] = name; } luaTable = table; OnLoadedCompleted = cb; this.param = param; ResourceMgr.Instance.LoadAsset>(OnLoadModelCompleted, assetPath, assetNames); } void OnLoadModelCompleted(List prefabs, string assetPath, params string[] assetName) { List list = new List(); for (int i = 0; i < assetName.Length; ++i) { GameObject go = GameObject.Instantiate(prefabs[i]); go.transform.SetParent(modelRoot.transform); go.transform.localPosition = Vector3.zero; list.Add(go); } if (OnLoadedCompleted != null) { if (luaTable != null) OnLoadedCompleted(luaTable, list, param); OnLoadedCompleted = null; } luaTable = null; param = null; } }