private static void ProcessCombine(TempLoad tl, Texture2D texture, Rect[] rect) { lock (lockCombine) { int i, count, j = 0, k = 0, count1; Rect rt; TexInfo ti; Mesh mesh; Vector2[] uvs; for (i = 0, count = tl.meshList.Count; i < count; i++) { rt = rect[i]; ti = tl.texInfo[i]; mesh = tl.meshList[i]; uvs = mesh.uv; count1 = uvs.Length; } try { texture.Compress(false); if (rect == null) { Debug.LogError("rect is null"); return; } Vector2 v2; Vector2 nuv; for (i = 0, count = tl.meshList.Count; i < count; i++) { rt = rect[i]; ti = tl.texInfo[i]; mesh = tl.meshList[i]; uvs = mesh.uv; count1 = uvs.Length; for (j = 0; j < count1; j++) { v2 = uvs[j]; nuv = new Vector2(rt.xMin + v2.x * ti.w / texture.width, rt.yMin + v2.y * ti.h / texture.height); uvs[j] = nuv; } mesh.uv = uvs; } SkinnedMeshRenderer r = tl.root.GetComponent <SkinnedMeshRenderer>(); r.sharedMesh = new Mesh(); r.sharedMesh.CombineMeshes(tl.combineInstances.ToArray(), true, false); r.bones = tl.bones.ToArray(); Material material = new Material("xx"); material.mainTexture = texture; r.materials = new Material[] { material }; CombineObj co = new CombineObj(); co.obj = tl.root; co.combine = true; if (!combinedDic2.ContainsKey(tl.plus)) { Dictionary <int, List <CombineObj> > dic = new Dictionary <int, List <CombineObj> >(); List <CombineObj> list = new List <CombineObj>(); list.Add(co); dic.Add(tl.sub, list); combinedDic2.Add(tl.plus, dic); } else { Dictionary <int, List <CombineObj> > dic = combinedDic2[tl.plus]; if (dic.ContainsKey(tl.sub)) { dic[tl.sub].Add(co); } else { List <CombineObj> list = new List <CombineObj>(); list.Add(co); dic.Add(tl.sub, list); } } //add first, then avoid to del if (tl.endCombine != null) { tl.endCombine(tl.root, tl.plus, tl.sub, tl.endParam); } //Mesh mesh; for (i = 0, count = tl.meshList.Count; i < count; i++) { Object.Destroy(tl.meshList[i]); } for (i = 0, count = tl.texName.Length; i < count; i++) { ResLoader.RemoveAssetCacheByName(tl.texName[i]); } } catch (System.Exception e) { for (i = 0, count = tl.meshList.Count; i < count; i++) { Object.Destroy(tl.meshList[i]); } for (i = 0, count = tl.texName.Length; i < count; i++) { ResLoader.RemoveAssetCacheByName(tl.texName[i]); } if (tl.endCombine != null) { tl.endCombine(null, tl.plus, tl.sub, tl.endParam); } Debug.LogError("process 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 ProcessCombine(TempLoad_NPT tl) { lock (lockCombine) { try { SkinnedMeshRenderer r = tl.root.GetComponent <SkinnedMeshRenderer>(); r.sharedMesh = new Mesh(); r.sharedMesh.CombineMeshes(tl.combineInstances.ToArray(), false, false); r.bones = tl.bones.ToArray(); r.materials = tl.materials.ToArray(); CombineObj co = new CombineObj(); co.obj = tl.root; co.combine = true; if (!combinedDic2.ContainsKey(tl.plus)) { Dictionary <int, List <CombineObj> > dic = new Dictionary <int, List <CombineObj> >(); List <CombineObj> list = new List <CombineObj>(); CombineObj rootObj = new CombineObj(); rootObj.combine = true; rootObj.obj = (GameObject)Object.Instantiate(co.obj); rootObj.obj.SetActive(false); list.Add(rootObj); co.combine = false; list.Add(co); dic.Add(tl.sub, list); combinedDic2.Add(tl.plus, dic); } else { Dictionary <int, List <CombineObj> > dic = combinedDic2[tl.plus]; if (dic.ContainsKey(tl.sub)) { dic[tl.sub].Add(co); } else { List <CombineObj> list = new List <CombineObj>(); CombineObj rootObj = new CombineObj(); rootObj.combine = true; rootObj.obj = (GameObject)Object.Instantiate(co.obj); rootObj.obj.SetActive(false); list.Add(rootObj); co.combine = false; list.Add(co); dic.Add(tl.sub, list); } } //add first, then avoid to del if (tl.endCombine != null) { tl.endCombine(tl.root, tl.plus, tl.sub, tl.endParam); } } catch (System.Exception e) { if (tl.endCombine != null) { tl.endCombine(null, tl.plus, tl.sub, tl.endParam); } Debug.LogError("process combine error->" + e.ToString()); } } }