Esempio n. 1
0
    public static GameObject SimpleCombine(GameObject source, GameObject target)
    {
        CombinedMesh combinedMesh = new CombinedMesh(source.transform, null, null);

        combinedMesh.DoCombine(true);
        target = combinedMesh.CreateNewGo(false, target);
        target.AddComponent <MeshInfo>();
        Debug.Log("Combine:" + source + "->" + target);
        return(target);
    }
Esempio n. 2
0
    public static GameObject Combine(GameObject source)
    {
        DateTime     start        = DateTime.Now;
        int          count        = 0;
        GameObject   goNew        = CombineMaterials(source, out count);//按材质合并
        CombinedMesh combinedMesh = new CombinedMesh(goNew.transform, null, null);

        combinedMesh.DoCombine(false);
        GameObject target = combinedMesh.CreateNewGo(false, null);

        target.name = source.name + "_Combined";
        goNew.transform.SetParent(target.transform);
        GameObject.DestroyImmediate(goNew);
        Debug.LogError(string.Format("CombinedMesh 用时:{0}ms,数量:{1}", (DateTime.Now - start).TotalMilliseconds, count));
        return(target);
    }
Esempio n. 3
0
    public static GameObject CombineMaterials(GameObject go, out int count)
    {
        DateTime   start = DateTime.Now;
        GameObject goNew = new GameObject();

        goNew.name = go.name + "_Combined";
        goNew.transform.SetParent(go.transform.parent);
        //int count=0;
        Dictionary <Material, List <MeshFilter> > mat2Filters = GetMatFilters(go, out count);

        foreach (var item in mat2Filters)
        {
            Material          material = item.Key;
            List <MeshFilter> list     = item.Value;

            CombinedMesh combinedMesh = new CombinedMesh(go.transform, list, material);
            combinedMesh.DoCombine(true);
            GameObject matGo = combinedMesh.CreateNewGo(false, null);
            matGo.name = material.name;
            matGo.transform.SetParent(goNew.transform);
        }
        Debug.LogError(string.Format("CombineMaterials 用时:{0},Mat数量:{1},Mesh数量:{2}", (DateTime.Now - start), mat2Filters.Count, count));
        return(goNew);
    }