示例#1
0
    void LateUpdate()
    {
        //Apply changes after this and other scripts have made changes
        //Only to vertecies, tangents and normals
        //Only want to call this once per frame since it is slow
        meshbaker.UpdateGameObjects(objsToMove, false);
        Vector2[] uvs2 = m.uv;
        for (int i = 0; i < uvs2.Length; i++)
        {
            uvs2[i] = Mathf.Sin(Time.time) * uvs[i];
        }
        m.uv = uvs2;
        meshbaker.UpdateGameObjects(new GameObject[] { objWithChangingUVs }, true, true, true, true, true, false, false, false, false);
        meshbaker.Apply(false, true, true, true, true, false, false, false, false, false);

        // now multi mesh baker
        multiMeshBaker.UpdateGameObjects(objsToMove, false);
        uvs2 = m.uv;
        for (int i = 0; i < uvs2.Length; i++)
        {
            uvs2[i] = Mathf.Sin(Time.time) * uvs[i];
        }
        m.uv = uvs2;
        multiMeshBaker.UpdateGameObjects(new GameObject[] { objWithChangingUVs }, true, true, true, true, true, false, false, false, false);
        multiMeshBaker.Apply(false, true, true, true, true, false, false, false, false, false);
    }
示例#2
0
 void LateUpdate()
 {
     //Apply changes after this and other scripts have made changes
     //Only to vertecies, tangents and normals
     //Only want to call this once per frame since it is slow
     meshbaker.UpdateGameObjects(objsToCombine);
     meshbaker.Apply(false, true, true, true, false, false, false, false, false);
 }
    public void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            // Cycle the material on targetRenderer to the next material in materials.

            Material mat = targetRenderer.sharedMaterial;
            //Find the index of the current material on the Renderer
            int materialIdx = -1;
            for (int i = 0; i < materials.Length; i++)
            {
                if (materials[i] == mat)
                {
                    materialIdx = i;
                }
            }

            // Get the next material in the cycle.
            materialIdx++;
            if (materialIdx >= materials.Length)
            {
                materialIdx = 0;
            }

            if (materialIdx != -1)
            {
                // Assign the material to the disabled renderer
                targetRenderer.sharedMaterial = materials[materialIdx];
                Debug.Log("Updating Material to: " + targetRenderer.sharedMaterial);

                // Update the Mesh Baker combined mesh
                GameObject[] gameObjects = new GameObject[] { targetRenderer.gameObject };
                meshBaker.UpdateGameObjects(gameObjects, false, false, false, false, true, false, false, false, false);

                // We could have used AddDelteGameObjects instead of UpdateGameObjects.
                // UpdateGameObjects is faster, but does not work if the material change causes
                // the object to switch submeshes in the combined mesh.
                // meshBaker.AddDeleteGameObjects(gameObjects, gameObjects,false);
                // Apply the changes.
                meshBaker.Apply();
            }
        }
    }