public static void CreateCharacterAsset(string name, CCACallback callback, System.Object param, bool pack = true) { if (callback == null) { return; } if (string.IsNullOrEmpty(name)) { return; } CharacterAsset ca = null; int index = -1; if (strToID.TryGetValue(name, out index)) { if (index >= 0) { assetArr.TryGetValue(index, out ca); if (ca != null) { if (callback != null) { callback(ca, param); } return; } } } ResLoader.LoadByName(name, OnLoad, new LoadInfo() { name = name, callback = callback, param = param, pack = pack }, true); }
private static void OnLoad(UnityEngine.Object asset, System.Object param) { if (param == null) { return; } LoadInfo li = (LoadInfo)param; if (asset == null) { Debug.LogError("load character failed->" + li.name); return; } CharacterAsset ca = null; int index = -1; if (strToID.TryGetValue(li.name, out index)) { if (index >= 0) { assetArr.TryGetValue(index, out ca); if (ca != null) { if (li.callback != null) { li.callback(ca, li.param); } return; } } } ca = new CharacterAsset(asset, li.name, li.pack); assetArr.Add(ca.id, ca); if (li.callback != null) { li.callback(ca, li.param); } }
private static void _Combine(CombineInfo combineInfo) { List <Mesh> meshList = new List <Mesh>(); try { CharacterAsset item = null; int i, j, k, count, count1, count2; List <CombineInstance> combineInstances = new List <CombineInstance>(); List <Transform> bones = new List <Transform>(); Transform[] transforms = combineInfo.root.GetComponentsInChildren <Transform>(); TexInfo[] texInfo = new TexInfo[combineInfo.items.Count]; SkinnedMeshRenderer smr = null; CombineInstance ci; string[] strs = null; string str = null; Transform transform; count2 = transforms.Length; count = (short)combineInfo.items.Count; for (i = 0; i < count; i++) { item = combineInfo.items[i]; smr = item.GetSkinnedMeshRenderer(); if (smr == null) { return; } Mesh mesh = Mesh.Instantiate(smr.sharedMesh) as Mesh; for (j = 0, count1 = smr.sharedMesh.subMeshCount; j < count1; j++) { ci = new CombineInstance(); ci.mesh = mesh; ci.subMeshIndex = j; combineInstances.Add(ci); } strs = item.GetBoneNames(); for (j = 0, count1 = strs.Length; j < count1; j++) { str = strs[j]; for (k = 0; k < count2; k++) { transform = transforms[k]; if (transform.name != str) { continue; } bones.Add(transform); break; } } meshList.Add(mesh); Object.Destroy(smr.gameObject); } TempLoad tl = null; string[] strArr = new string[count]; string destName; string path; int size; bool encrypt; Example.VersionFile.Type fileType; for (i = 0; i < count; i++) { item = combineInfo.items[i]; strs = item.GetTexNames(); tl = new TempLoad(); tl.texInfo = texInfo; tl.index = (short)i; tl.combineInstances = combineInstances; tl.bones = bones; tl.meshList = meshList; tl.endCombine = combineInfo.endCombine; tl.endParam = combineInfo.endParam; tl.root = combineInfo.root; tl.over = false; tl.plus = combineInfo.plus; tl.sub = combineInfo.sub; tl.autoTemp = combineInfo.autoTemp; tl.texName = strArr; tl.light = combineInfo.light; GameUtils.stringBuilder.Remove(0, GameUtils.stringBuilder.Length); GameUtils.stringBuilder.Append(strs[0]); ResUpdate.GetLoadDetails(GameUtils.stringBuilder.ToString(), out destName, out path, out size, out encrypt, out fileType); strArr[i] = GameUtils.stringBuilder.ToString(); ResLoader.LoadByPath(strArr[i], destName, path, fileType, size, OnLoad, tl, combineInfo.autoTemp); } } catch (System.Exception e) { for (int i = 0; i < meshList.Count; i++) { Object.Destroy(meshList[i]); } if (combineInfo != null && combineInfo.endCombine != null) { combineInfo.endCombine(null, -1, -1, combineInfo.endParam); } Debug.LogError("combine error->" + e.ToString()); } }
public static void Combine(List <CharacterAsset> items, GameObject root, EndCombine endCombine, System.Object endParam, bool autoTemp, bool light, bool packTex) { lock (lockClone) { try { int plus = 0; int sub = 0; int i, iid; CharacterAsset item = null; int count = (short)items.Count; for (i = 0; i < count; i++) { item = items[i]; iid = item.id; plus += iid; if (sub == 0) { sub = iid; } else { sub -= iid; } } if (combinedDic2.ContainsKey(plus)) { Dictionary <int, List <CombineObj> > dic = combinedDic2[plus]; if (dic.ContainsKey(sub)) { List <CombineObj> list = dic[sub]; if (list.Count > 0) { try { if (!list[0].obj) { for (int m = 1; m < list.Count; m++) { if (list[m] == null || !list[m].obj) { list.RemoveAt(m); m--; } } } else { GameObject go = (GameObject)Object.Instantiate(list[0].obj); if (!go.activeSelf) { go.SetActive(true); } CombineObj co = new CombineObj(); co.obj = go; co.combine = false; list.Add(co); //add first, then avoid to del in callback if (endCombine != null) { endCombine(go, plus, sub, endParam); } Object.Destroy(root); items.Clear(); return; } } catch (System.Exception e) { Debug.LogError("combine body failed 3->" + e.ToString() + "^" + list.Count); } } } } CombineInfo ci = new CombineInfo(); ci.items = items; ci.root = root; ci.endCombine = endCombine; ci.endParam = endParam; ci.plus = plus; ci.sub = sub; ci.autoTemp = autoTemp; ci.light = light; ci.packTex = packTex; combineQueue.Enqueue(ci); } catch (System.Exception e) { Debug.LogError("combine error->" + e.ToString()); } } }
private static void _Combine_NPT(CombineInfo combineInfo) { List <Mesh> meshList = new List <Mesh>(); try { CharacterAsset item = null; int i, j, k, count, count1, count2; List <CombineInstance> combineInstances = new List <CombineInstance>(); List <Transform> bones = new List <Transform>(); List <Material> materials = new List <Material>(); Transform[] transforms = combineInfo.root.GetComponentsInChildren <Transform>(); SkinnedMeshRenderer smr = null; CombineInstance ci; string[] strs = null; string str = null; Transform transform; count2 = transforms.Length; count = combineInfo.items.Count; for (i = 0; i < count; i++) { item = combineInfo.items[i]; smr = item.GetSkinnedMeshRenderer(); if (smr == null) { return; } materials.AddRange(smr.materials); Mesh mesh = Mesh.Instantiate(smr.sharedMesh) as Mesh; for (j = 0, count1 = smr.sharedMesh.subMeshCount; j < count1; j++) { ci = new CombineInstance(); ci.mesh = mesh; ci.subMeshIndex = j; combineInstances.Add(ci); } strs = item.GetBoneNames(); for (j = 0, count1 = strs.Length; j < count1; j++) { str = strs[j]; for (k = 0; k < count2; k++) { transform = transforms[k]; if (transform.name != str) { continue; } bones.Add(transform); break; } } meshList.Add(mesh); Object.Destroy(smr.gameObject); } TempLoad_NPT tl = new TempLoad_NPT(); tl.combineInstances = combineInstances; tl.bones = bones; tl.meshList = meshList; tl.materials = materials; tl.endCombine = combineInfo.endCombine; tl.endParam = combineInfo.endParam; tl.root = combineInfo.root; tl.plus = combineInfo.plus; tl.sub = combineInfo.sub; tl.light = combineInfo.light; ProcessCombine(tl); } catch (System.Exception e) { if (combineInfo != null && combineInfo.endCombine != null) { combineInfo.endCombine(null, -1, -1, combineInfo.endParam); } Debug.LogError("combine error->" + e.ToString() + "\r\n" + e.StackTrace); } }