Version: 2021.2

AssetPostprocessor.OnPreprocessMaterialDescription(MaterialDescription,Material, AnimationClip[])

切换到手册

参数

description A MaterialDescription that describes the imported camera properties and animations.
material Model Importer 生成的材质。
animations Model Importer 生成的动画剪辑。

描述

将此函数添加到一个子类中,以在材质从 Model Importer 导入时接收通知。

Unity only calls this function if you set ModelImporter.materialImportMode to ModelImporterMaterialImportMode.ImportViaMaterialDescription. This function gives you control over material properties and animations during the model import process. The MaterialDescription structure contains all the material data from the imported file. You can use it to populate the material and animation clips.

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.AssetImporters;

public class CreateMaterialFromMaterialDescription : AssetPostprocessor { public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] materialAnimation) { var shader = Shader.Find("Standard"); if (shader == null) return; material.shader = shader;

List<string> props = new List<string>(); // list the properties of type Vector4 : description.GetVector4PropertyNames(props); Debug.Log(props);

// Read a texture property from the material description. TexturePropertyDescription textureProperty; if (description.TryGetProperty("DiffuseColor", out textureProperty)) { // Assign the texture to the material. material.SetTexture("_MainTex", textureProperty.texture); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961