當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。