Is it possible to create a model importer so that properties on the MeshRenderer of the model prefab can be tweaked?

不问归期 提交于 2019-12-12 02:08:24

问题


I want to create some default import settings for my models so that when a model is imported into the editor, I can modify the values of Receive Shadows, Motion Vectors, Reflection Probes, and other fields of the MeshRenderer children of that model on a prefab level.

Is this possible?

I prefer a solution so that the default import settings of the model file are modified, and that it won't be necessary for me to create a duplicate prefab of the model asset file.

EDIT:

Going with the accepted answer's direction, here's the code I came up with to achieve my desired results.

using UnityEngine;

public class DefaultImportSettings : AssetPostprocessor
{
    void OnPostprocessModel(GameObject go) //Is called when we import a fbx or when we press apply on its settings
    {
        Renderer[] renderers = go.GetComponentsInChildren<Renderer>();
        for (int i = 0, iMax = renderers.Length; i < iMax; i++)
        {
            Renderer renderer = renderers[i];

            renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            renderer.receiveShadows = false;
            renderer.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
            renderer.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
            renderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;

            // Other renderer modifications
        }
    }
}

回答1:


I think it possible but it hard to modifier for each model you need import. I found some document : https://docs.unity3d.com/ScriptReference/PrefabUtility.InstantiatePrefab.html

https://docs.unity3d.com/ScriptReference/AssetPostprocessor.OnPreprocessModel.html

The AssetPostprocessor.OnPreprocessModel() method to get model setting and you use PrefabUtility.InstantiatePrefab() create prefab with own setting.



来源:https://stackoverflow.com/questions/42497386/is-it-possible-to-create-a-model-importer-so-that-properties-on-the-meshrenderer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!