Unity 3D 自定义资源导入类型

Unity 3D 自定义资源导入类型_第1张图片

Unity 3D 自定义资源导入类型_第2张图片

using System.IO;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine;

//--监听后缀名是"anything"的自定义文件
[ScriptedImporter(1, "anything")]
public class AnyAssetImportMyTools : ScriptedImporter
{
    public override void OnImportAsset(AssetImportContext ctx)
    {
        var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

        var pos = JsonUtility.FromJson(File.ReadAllText(ctx.assetPath));

        cube.transform.position = pos;
        cube.transform.localPosition = Vector3.zero;

        ctx.AddObjectToAsset("obj", cube);
        ctx.SetMainObject(cube);

        var material = new Material(Shader.Find("Standard"));
        material.color = Color.red;
        ctx.AddObjectToAsset("material", material);

        var tempmesh = new Mesh();
        DestroyImmediate(tempmesh);
    }
}

 

你可能感兴趣的:(Unity,3D,游戏开发,第二版,学习笔记)