英語で読む 編集

次の方法で共有


MaterialInstance Class

Definition

The MaterialInstance behavior aides in tracking instance material lifetime and automatically destroys instanced materials for the user. This utility component can be used as a replacement to Renderer.material or Renderer.materials. When invoking Unity's Renderer.material(s), Unity automatically instantiates new materials. It is the caller's responsibility to destroy the materials when a material is no longer needed or the game object is destroyed. The MaterialInstance behavior helps avoid material leaks and keeps material allocation paths consistent during edit and run time.

C++
public ref class MaterialInstance : UnityEngine::MonoBehaviour
Inheritance
UnityEngine.MonoBehaviour
MaterialInstance
Attributes
UnityEngine.AddComponentMenuAttribute UnityEngine.ExecuteAlwaysAttribute UnityEngine.HelpURLAttribute UnityEngine.RequireComponentAttribute

Constructors

Properties

CacheSharedMaterialsFromRenderer

Whether to use a cached copy of cachedRenderer.sharedMaterials or call sharedMaterials on the Renderer directly. Enabling the option will lead to better performance but you must turn it off before modifying sharedMaterials of the Renderer.

Material

Returns the first instantiated Material assigned to the renderer, similar to Renderer.material.

Materials

Returns all the instantiated materials of this object, similar to Renderer.materials.

Methods

AcquireMaterial(Object, Boolean)

Returns the first instantiated Material assigned to the renderer, similar to Renderer.material. If any owner is specified the instanced material(s) will not be released until all owners are released. When a material is no longer needed ReleaseMaterial should be called with the matching owner.

AcquireMaterials(Object, Boolean)

Returns all the instantiated materials of this object, similar to Renderer.materials. If any owner is specified the instanced material(s) will not be released until all owners are released. When a material is no longer needed ReleaseMaterial should be called with the matching owner.

ReleaseMaterial(Object, Boolean)

Relinquishes ownership of a material instance. This should be called when a material is no longer needed after acquire ownership with AcquireMaterial(s).

Applies to

製品 バージョン
MRTK2 Unity 2018 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.6.0, 2.7.0
MRTK2 Unity 2019 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.6.0, 2.7.0, 2.8.0
MRTK2 Unity 2020 2.5.2, 2.5.3, 2.5.4, 2.6.0, 2.7.0, 2.8.0