Is it possible to create a model importer so that

2019-09-14 17:42发布

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条回答
够拽才男人
2楼-- · 2019-09-14 18:40

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.

查看更多
登录 后发表回答