当前位置: 首页>>代码示例>>C#>>正文


C# UnityEngine.CombineInstance类代码示例

本文整理汇总了C#中UnityEngine.CombineInstance的典型用法代码示例。如果您正苦于以下问题:C# CombineInstance类的具体用法?C# CombineInstance怎么用?C# CombineInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CombineInstance类属于UnityEngine命名空间,在下文中一共展示了CombineInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CombineMeshes

        public static GameObject CombineMeshes(string name,
                                          string materialName,
                                          CombinablesCollection objects,
                                          GameObject parent = null)
        {
            var gameObject = new GameObject(name);
            gameObject.SetActive(false);
            if (parent != null)
              gameObject.transform.parent = parent.transform;
            var meshFilter = gameObject.AddComponent<MeshFilter>();
            var meshRenderer = gameObject.AddComponent<MeshRenderer>();
            meshRenderer.sharedMaterial = Resources.Load("Materials/" + materialName,
                                                 typeof(Material)) as Material;

            MeshFilter[] meshFilters = new MeshFilter[objects.Count];
            for (var i = 0; i < objects.Count; ++i)
            {
              meshFilters[i] = objects[i].meshFilter;
              GameObject.Destroy(objects[i].gameObject);
            }

            CombineInstance[] combine = new CombineInstance[meshFilters.Length];
            for (var i = 0; i < meshFilters.Length; ++i)
            {
              combine[i].mesh = meshFilters[i].sharedMesh;
              combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
            }

            meshFilter.mesh = new Mesh();
            meshFilter.mesh.CombineMeshes(combine);

            return gameObject;
        }
开发者ID:BrettGregson,项目名称:ProceduralBuildings,代码行数:33,代码来源:Util.cs

示例2: CombinedMeshes

    public Mesh[] CombinedMeshes(List<Mesh> meshObjectList)
    {
        List<Mesh> meshs = new List<Mesh>();

        // combine meshes
        List<CombineInstance> combine = new List<CombineInstance>();
        int i = 0;
        while (i < meshObjectList.Count)
        {
            CombineInstance instance = new CombineInstance();
            instance.mesh = meshObjectList[i];
            instance.transform = transform.localToWorldMatrix;

            combine.Add(instance);

            i++;
        }

        Mesh combinedMesh = new Mesh();
        combinedMesh.CombineMeshes(combine.ToArray());
        meshs.Add(combinedMesh);
        combine = new List<CombineInstance>();

        return meshs.ToArray();
    }
开发者ID:MusicalCreeper01,项目名称:BasicUnityVoxelTerrain,代码行数:25,代码来源:CubicTerrainGenerator.cs

示例3: Start

	// Use this for initialization
	void Start () {
		GameObject face = Instantiate(Face) as GameObject;
		face.transform.parent = transform;
		FaceRenderer = face.GetComponentInChildren<SkinnedMeshRenderer>();

		GameObject body = Instantiate(Body) as GameObject;
		body.transform.parent = transform;
		BodyRenderer = body.GetComponentInChildren<SkinnedMeshRenderer>();
		
		CombinedRenderer = gameObject.GetComponent<SkinnedMeshRenderer>();
		// 重组Mesh后删除原始GO
		Mesh faceMesh = FaceRenderer.sharedMesh;
		Mesh bodyMesh = BodyRenderer.sharedMesh;

		CombineInstance[] combineInstances = new CombineInstance[2];
		combineInstances[0].mesh = faceMesh;
		combineInstances[0].transform = FaceRenderer.transform.localToWorldMatrix;
		combineInstances[1].mesh = bodyMesh;
		combineInstances[1].transform = BodyRenderer.transform.localToWorldMatrix;

		CombinedRenderer.sharedMesh = new Mesh();
		CombinedRenderer.sharedMesh.CombineMeshes(combineInstances);
		
		// 组合材质球引用
		Material[] sharedMats = new Material[2];
		sharedMats[0] = FaceRenderer.sharedMaterial;
		sharedMats[1] = BodyRenderer.sharedMaterial;
		CombinedRenderer.sharedMaterials = sharedMats;

		// Mesh和材质的关联是按照材质在数组中的顺序的,重组Mesh势必会产生一个新的材质球次序
	}
开发者ID:Henry-T,项目名称:UnityPG,代码行数:32,代码来源:CombineMeshByCode.cs

示例4: CombineSelected

    static void CombineSelected()
    {
        if (EditorUtility.DisplayDialog("Do you want to combine these objects?", "This can't be undone! Make sure you have a backup if you don't know what you're doing.", "Heck Yeah!", "No, I'm scared"))
        {
            int amountSelected = Selection.gameObjects.Length;

            MeshFilter[] meshFilters = new MeshFilter[amountSelected];
            CombineInstance[] combineInstances = new CombineInstance[amountSelected];

            for (var i = 0; i < amountSelected; i++)
            {
                meshFilters[i] = Selection.gameObjects[i].GetComponent<MeshFilter>();

                combineInstances[i].mesh = meshFilters[i].sharedMesh;
                combineInstances[i].transform = meshFilters[i].transform.localToWorldMatrix;
            }

            GameObject obj = new GameObject("CombinededMeshes", typeof(MeshFilter), typeof(MeshRenderer), typeof(MeshCollider));
            obj.GetComponent<MeshFilter>().mesh = new Mesh();
            obj.GetComponent<MeshFilter>().sharedMesh.CombineMeshes(combineInstances);
            obj.GetComponent<MeshRenderer>().sharedMaterial = new Material(meshFilters[0].gameObject.GetComponent<MeshRenderer>().sharedMaterial);
            obj.GetComponent<MeshCollider>().sharedMesh = obj.GetComponent<MeshFilter>().sharedMesh;

            foreach (MeshFilter m in meshFilters)
            {
                DestroyImmediate(m.gameObject);
            }
        }
    }
开发者ID:JimmyJK96,项目名称:LD33_TeamOA,代码行数:29,代码来源:CombineMeshes.cs

示例5: Combine

    public void Combine()
    {
        List<MeshFilter> mfs = new List<MeshFilter>();
        FindMeshFilters(transform, mfs);

        MeshFilter[] meshFilters = mfs.ToArray();
        CombineInstance[] combine = new CombineInstance[meshFilters.Length];
        int i = 0;
        while (i < meshFilters.Length)
        {
            combine[i].mesh = meshFilters[i].sharedMesh;
            combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
            meshFilters[i].gameObject.SetActive(false);
            i++;
        }

        MeshFilter thisMf = this.GetComponent<MeshFilter>();
        if (thisMf == null)
        {
            thisMf = gameObject.AddComponent<MeshFilter>();
        }

        MeshRenderer thisMr = this.GetComponent<MeshRenderer>();
        if (thisMr == null)
        {
            thisMr = gameObject.AddComponent<MeshRenderer>();
        }

        thisMr.material = this.UseMaterial;

        thisMf.sharedMesh = new Mesh();
        thisMf.sharedMesh.CombineMeshes(combine);

        transform.gameObject.SetActive(true);
    }
开发者ID:mroslander,项目名称:BoomBalls,代码行数:35,代码来源:MbxCombineMesh.cs

示例6: BatchList

    /// <summary>
    /// Static method for batching a list of meshes. Note that the selector information goes to tangent vertex
    /// information, so any data in the mesh tangents will be lost.
    /// </summary>
    /// <param name="meshList">The list of meshes to batch</param>
    public static Mesh BatchList(List<Mesh> meshList)
    {
        // We will use this to combine the meshes
        CombineInstance[] combineInstances = new CombineInstance[meshList.Count];
        List<Vector4> tangentSelectors = new List<Vector4>();

        for (int i = 0; i < combineInstances.Length; i++)
        {
            Mesh mesh = meshList[i];

            for (int j = 0; j < mesh.vertexCount; j++)
            {
                tangentSelectors.Add(new Vector4(i, 0, 0, 0));
            }

            combineInstances[i].mesh = mesh;

            // We don't want to transform the meshes, it will be done in the shader.
            combineInstances[i].transform = Matrix4x4.identity;
        }

        // Make our new mesh out of the combined instance
        Mesh resultMesh = new Mesh();
        resultMesh.CombineMeshes(combineInstances);
        // And set the selectors of the meshes
        resultMesh.tangents = tangentSelectors.ToArray();

        return resultMesh;
    }
开发者ID:bennychen,项目名称:shader-playground,代码行数:34,代码来源:DynamicShaderBatcher.cs

示例7: EarClipping

    // Return a polygonized mesh from 2D outer/inner contours
    public static Mesh EarClipping( List<Contour> a_rDominantContoursList, float a_fExtrusionDepth, float a_fScale, Vector3 a_f3PivotPoint )
    {
        // The mesh to build
        Mesh oCombinedMesh = new Mesh( );

        int iContourCount = a_rDominantContoursList.Count; //a_rDominantContoursList.Count;

        // Step 2: Ear clip outer contour
        CombineInstance[ ] oCombineMeshInstance = new CombineInstance[ iContourCount ];
        for( int iContourIndex = 0; iContourIndex < iContourCount; ++iContourIndex )
        {
            Vector3[ ] oVerticesArray;
            List<int> oTrianglesList;

            EarClippingSubMesh( a_rDominantContoursList[ iContourIndex ], a_fScale, a_f3PivotPoint, out oVerticesArray, out oTrianglesList );

            oCombineMeshInstance[ iContourIndex ].mesh = BuildExtrudedMeshFromPolygonizedContours( oVerticesArray, oTrianglesList, a_fExtrusionDepth ); // EarClippingSubMesh( a_rDominantContoursList[ iContourIndex ] );
        }

        // Step 3: Combine every sub meshes (merge, no transform)
        oCombinedMesh.CombineMeshes( oCombineMeshInstance, true, false );

        // Return!
        return oCombinedMesh;
    }
开发者ID:NemOry,项目名称:EscapeTheNemories,代码行数:26,代码来源:Uni2DEditorUtilsPolygonTriangulation.cs

示例8: MergeBorder

    /*
     * The method that merges the meshes.
     * This code is based off of code from unity's script reference for
     * Mesh.CombineMeshes.
     */
    void MergeBorder()
    {
        //first, create an array of all meshes
        MeshFilter[] meshFilters = transform.GetComponentsInChildren<MeshFilter>();
        CombineInstance[] combine = new CombineInstance[meshFilters.Length];
        int i = 0;
        //use Unity's CombineInstance so Mesh.CombineMeshes may be called appropriately
        while (i < meshFilters.Length) {
            combine[i].mesh = meshFilters[i].sharedMesh;
            combine[i].transform = (meshFilters[i].transform.localToWorldMatrix);
            meshFilters[i].gameObject.SetActive(false); //turn off old meshes
            i++;
        }
        //create new, combined mesh and attach to a child since the parent is not a transform
        Transform mainWall = transform.GetChild (0);
        Mesh OneTrueMesh = new Mesh ();
        mainWall.GetComponent<MeshFilter>().mesh = OneTrueMesh;
        mainWall.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
        mainWall.gameObject.SetActive(true);

        //make sure the new mesh is the correct size and position
        mainWall.position = new Vector3 (0, 0, 0);
        mainWall.localScale = new Vector3 (1, 1, 1);
        mainWall.gameObject.AddComponent (typeof(MeshCollider));
        this.mainWall = mainWall; //store the child so VictoryScript may reference it
    }
开发者ID:GameDesignGroup6,项目名称:MazeFPS,代码行数:31,代码来源:BorderMerger.cs

示例9: MakeCubeFromQuads

    void MakeCubeFromQuads()
    {
        mesh.Clear();

        Vector3[] verts = new Vector3[8];
        verts[0] = new Vector3(-.5f, -.5f, -.5f);
        verts[1] = new Vector3(-.5f, .5f, -.5f);
        verts[2] = new Vector3(.5f, .5f, -.5f);
        verts[3] = new Vector3(.5f, -.5f, -.5f);
        verts[4] = new Vector3(-.5f, -.5f, .5f);
        verts[5] = new Vector3(-.5f, .5f, .5f);
        verts[6] = new Vector3(.5f, .5f, .5f);
        verts[7] = new Vector3(.5f, -.5f, .5f);

        CombineInstance[] combine = new CombineInstance[6];
        combine[0] = BuildAndReturnQuad(verts[0], verts[1], verts[2], verts[3]);
        combine[1] = BuildAndReturnQuad(verts[3], verts[2], verts[6], verts[7]);
        combine[2] = BuildAndReturnQuad(verts[7], verts[6], verts[5], verts[4]);
        combine[3] = BuildAndReturnQuad(verts[4], verts[5], verts[1], verts[0]);
        combine[4] = BuildAndReturnQuad(verts[1], verts[5], verts[6], verts[2]);
        combine[5] = BuildAndReturnQuad(verts[4], verts[0], verts[3], verts[7]);

        mesh.CombineMeshes(combine, true, false);
        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
    }
开发者ID:jhonj624,项目名称:Mesh-Workshop,代码行数:26,代码来源:MeshBuilder_Final.cs

示例10: Start

    void Start()
    {
        Quaternion startRotation=transform.localRotation;

        foreach(Transform child in transform)
            child.position += transform.position;
        transform.position = Vector3.zero;
        transform.rotation = Quaternion.identity;

        MeshFilter[] meshFilters = (MeshFilter[]) GetComponentsInChildren<MeshFilter>();
        CombineInstance[] combine = new CombineInstance[meshFilters.Length-1];
        int index = 0;
        for (int i = 0; i < meshFilters.Length; i++)
        {
            if (meshFilters[i].sharedMesh == null) continue;
            combine[index].mesh = meshFilters[i].sharedMesh;
            combine[index++].transform = meshFilters[i].transform.localToWorldMatrix;
            meshFilters[i].renderer.enabled = false;
        }
        GetComponent<MeshFilter>().mesh = new Mesh();
        GetComponent<MeshFilter>().mesh.CombineMeshes (combine);
        renderer.material = meshFilters[1].renderer.sharedMaterial;

        transform.localRotation=startRotation;
    }
开发者ID:mroslander,项目名称:BoomBalls,代码行数:25,代码来源:CombineMesh.cs

示例11: Start

    // Use this for initialization
    void Start()
    {
        // http://forum.unity3d.com/threads/combinemeshes-example-flawed.33209/
        foreach (Transform child in transform)
            child.position += transform.position;

        transform.position = Vector3.zero;
        transform.rotation = Quaternion.identity;

        // Find all children meshes
        MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
        CombineInstance[] combine = new CombineInstance[meshFilters.Length];

        int i = 0;
        while(i < meshFilters.Length)
        {
            combine[i].mesh = meshFilters[i].sharedMesh;
            combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
            meshFilters[i].gameObject.active = false;
            i++;
        }

        transform.GetComponent<MeshFilter>().mesh = new Mesh();
        transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine, commonMaterial);
        transform.gameObject.active = true;

        // Set bound of mesh collider attached to game object
        MeshCollider collider = GetComponent<MeshCollider>();
        if (collider)
        {
            // set mesh for collider
            collider.sharedMesh = transform.GetComponent<MeshFilter>().mesh;
        }
    }
开发者ID:gdsl,项目名称:SOFTENG-306-PROJECT-2,代码行数:35,代码来源:MeshCombine.cs

示例12: FuseToChunkMesh

        public Mesh FuseToChunkMesh(MeshFilter ChunkMesh, MeshFilter[] NewMeshes, Vector3 ChunkPos, bool Restart = true)
        {
            //store old positions
            foreach (MeshFilter filter in NewMeshes)
            {
                filter.transform.position -= ChunkPos;
            }
            ChunkMesh.transform.position = Vector3.zero;
            CombineInstance[] combine = new CombineInstance[NewMeshes.Length + 1];
            List<MeshFilter> MeshList = new List<MeshFilter>(NewMeshes);
            for (int i = 0; i < combine.Length - 1; i++)
            {
                combine[i].mesh = MeshList[i].sharedMesh;
                combine[i].transform = MeshList[i].transform.localToWorldMatrix;
                DestroyImmediate(MeshList[i].gameObject);
            }

            MeshList.Add(ChunkMesh);

            combine[NewMeshes.Length].mesh = MeshList[NewMeshes.Length].sharedMesh;
            combine[NewMeshes.Length].transform = MeshList[NewMeshes.Length].transform.localToWorldMatrix;

            Mesh m = new Mesh();
            m.CombineMeshes(combine, true, true);

            ChunkMesh.transform.position = ChunkPos;

            return m;
        }
开发者ID:Dytonis,项目名称:cube-war-game,代码行数:29,代码来源:ChunkFactory.cs

示例13: CreateMesh

        public Mesh CreateMesh()
        {
            Mesh m = new Mesh
            {
                vertices = Vertices.ToArray(),
                uv = UV1.ToArray(),
                uv2 = UV2.ToArray(),
                triangles = Triangles.ToArray(),
                colors = Colors.ToArray()
            };

            if(Submeshes.Count > 0)
            {
                CombineInstance[] instances = new CombineInstance[Submeshes.Count];
                for(int i = 0; i < Submeshes.Count; i++)
                {
                    CombineInstance ins = new CombineInstance
                    {
                        mesh = Submeshes[i].CreateMesh(),
                        transform = Matrix4x4.identity
                    };

                    instances[i] = ins;

                }
                m.CombineMeshes(instances, false);
            }

            m.RecalculateNormals();
            m.RecalculateBounds();
            m.Optimize();

            return m;
        }
开发者ID:Arcanum2010,项目名称:UnityVoxelTest,代码行数:34,代码来源:IMesher.cs

示例14: LateUpdate

        protected virtual void LateUpdate()
        {
            if(_hasRenderer)
                return;


            _hasRenderer = true;
            

            foreach (KeyValuePair<Material, List<PCTrail>> keyValuePair in _matToTrailList)
            {
                CombineInstance[] combineInstances = new CombineInstance[keyValuePair.Value.Count];

                for (int i = 0; i < keyValuePair.Value.Count; i++)
                {
                    combineInstances[i] = new CombineInstance
                    {
                        mesh = keyValuePair.Value[i].Mesh,
                        subMeshIndex = 0,
                        transform = Matrix4x4.identity
                    };
                }

                Mesh combinedMesh = new Mesh();
                combinedMesh.CombineMeshes(combineInstances, true, false);
                _toClean.Add(combinedMesh);

                DrawMesh(combinedMesh, keyValuePair.Key);

                keyValuePair.Value.Clear();
            }
        }
开发者ID:at-anhgh,项目名称:Game-RiotSamuraFight,代码行数:32,代码来源:TrailRenderer_Base.cs

示例15: Write

        public void Write(SceneWriter writer, object component)
        {
            Component script = component as Component;
            if (script == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            MeshFilter[] meshFilters = script.GetComponentsInChildren<MeshFilter>();
            CombineInstance[] combine = new CombineInstance[meshFilters.Length];
            for ( int i = 0; i < meshFilters.Length; i++) {
                combine[i].mesh = meshFilters[i].sharedMesh;
                combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
            }
            Mesh mesh = new Mesh();
            mesh.CombineMeshes(combine);
            MeshRenderer mr = script.GetComponentInChildren<MeshRenderer>();
            writer.WriteElement("sharedMaterials", mr.sharedMaterials);
            writer.WriteElement("triangles", mesh.triangles);
            writer.WriteElement("vertices", mesh.vertices);
            //writer.WriteElement("normals", mesh.normals);
            writer.WriteElement("uv", mesh.uv);
            Debug.Log(script.name + " batched " + combine.Length + " objects into a mesh of " + (mesh.triangles.Length / 3) + " triangles and " + mesh.vertices.Length + " vertices.");

            if (mesh.vertices.Length > short.MaxValue)
            {
                Debug.LogWarning("BATCHED TOO MANY TRIANGLES!!");
            }
        }
开发者ID:Joelone,项目名称:FFWD,代码行数:28,代码来源:StaticBatchExporter.cs


注:本文中的UnityEngine.CombineInstance类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。