Version: 2020.2
言語: 日本語
public Mesh mesh ;

説明

メッシュフィルターに割り当てられた Mesh を返します

メッシュがメッシュフィルターに割り当てられていない場合、新しいメッシュが作成され割り当てられます。

If a mesh is assigned to the mesh filter already, then first query of mesh property will create a duplicate of it, and this copy will be returned. Further queries of mesh property will return this duplicated mesh instance. Once mesh property is queried, link to the original shared mesh is lost and MeshFilter.sharedMesh property becomes an alias to mesh. If you want to avoid this automatic mesh duplication, use MeshFilter.sharedMesh instead.

By using mesh property you can modify the mesh for a single object only. The other objects that used the same mesh will not be modified.

It is your responsibility to destroy the automatically instantiated mesh when the game object is being destroyed. Resources.UnloadUnusedAssets also destroys the mesh but it is usually only called when loading a new level.

以下のコードのショートカットとして mesh プロパティーを考慮してください。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Start() { Mesh mesh = GetComponent<MeshFilter>().sharedMesh; Mesh mesh2 = Instantiate(mesh); GetComponent<MeshFilter>().sharedMesh = mesh2; } }

mesh プロパティーの最初の問い合わせ(query)で呼び出されます。

Note:
If MeshFilter is a part of an asset object, quering mesh property is not allowed and only asset mesh can be assigned.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { // Distorts the mesh vertically. void Update() { // Get instantiated mesh Mesh mesh = GetComponent<MeshFilter>().mesh; // Randomly change vertices Vector3[] vertices = mesh.vertices; int p = 0; while (p < vertices.Length) { vertices[p] += new Vector3(0, Random.Range(-0.3F, 0.3F), 0); p++; } mesh.vertices = vertices; mesh.RecalculateNormals(); } }

関連項目: Mesh クラス

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961