IEnumerator combineMesh(GameObject[] meshes, int index, string combiner, Transform parent, System.Action <GameObject> action)
    {
        meshbaker.AddDeleteGameObjects(meshes, null, false);
        meshbaker.Apply();
        yield return(new WaitForEndOfFrame());

        int deleteSteps = 10;

        for (int i = 0; i < meshes.Length; i += deleteSteps)
        {
            for (int j = 0; j < deleteSteps; j++)
            {
                if (i + j < meshes.Length)
                {
                    Destroy(meshes [i + j]);
                }
            }
            yield return(new WaitForEndOfFrame());
        }

        GameObject meshObjectChild = GameObject.Find(combiner).transform.GetChild(0).gameObject;
        GameObject generatedObj    = GameObject.Instantiate(meshObjectChild);

        generatedObj.GetComponent <MeshFilter> ().mesh     = meshObjectChild.GetComponent <MeshFilter> ().mesh;
        generatedObj.AddComponent <MeshCollider> ().convex = false;
        generatedObj.name             = meshes.Length + " combined meshes";
        generatedObj.transform.parent = parent;
        meshbaker.DestroyMesh();
        action(generatedObj);
    }
Beispiel #2
0
    IEnumerator combineMesh(GameObject[] meshes, int iteration, string roomId, Transform parent, System.Action <GameObject> action)
    {
        meshbaker.AddDeleteGameObjects(meshes, null, false);
        meshbaker.Apply();
        yield return(new WaitForEndOfFrame());

        int deleteSteps = 10;

        for (int i = 0; i < meshes.Length; i += deleteSteps)
        {
            for (int j = 0; j < deleteSteps; j++)
            {
                if (i + j < meshes.Length)
                {
                    Destroy(meshes [i + j]);
                }
            }
            yield return(new WaitForEndOfFrame());
        }

        //room-N0 merge iteration 1
        // CombinedMesh-room-N0-mesh
        string searchName = "CombinedMesh-" + roomId + "-mesh";

        print(searchName);
        GameObject meshObject = GameObject.Find(searchName);
        //meshObject.name = threadId;

        GameObject meshObjectChild = meshObject.transform.GetChild(0).gameObject;
        GameObject generatedObj    = GameObject.Instantiate(meshObjectChild);

        generatedObj.GetComponent <MeshFilter> ().mesh     = meshObjectChild.GetComponent <MeshFilter> ().mesh;
        generatedObj.AddComponent <MeshCollider> ().convex = false;

        Destroy(meshObject);
        generatedObj.name             = meshes.Length + " combined meshes";
        generatedObj.transform.parent = parent;
        meshbaker.DestroyMesh();
        action(generatedObj);
    }