Unity技术分享之编辑器中识别Unity不支持的文件格式并修改Icon

在日常工作中可能会有这样的需求 : 公司有内部数据格式文件或者lua语言编写的应用 , 但是Unity编辑器中Lua文件是不识别的并且图标显示的是白块 ; 还有的公司可能会使用内部的格式文件 , 图标也是白块 , 这样下来感觉苦恼 , 那么有没有什么办法解决这些问题呢 ? 答案是有的 !! (关子卖完了 , 废话完毕 .)

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

[ScriptedImporter(1, "lua")]
public class LuaImporter : ScriptedImporter
{
    public override void OnImportAsset(AssetImportContext ctx)
    {
        var text = File.ReadAllText(ctx.assetPath);
        var asset = new TextAsset(text);
        ctx.AddObjectToAsset("main obj", asset);
        ctx.SetMainObject(asset);
    }
}
[CustomEditor(typeof(LuaImporter))]
public class LuaImporterEditor : ScriptedImporterEditor
{
    public override void OnInspectorGUI()
    {
    }
}

参考文章:
https://docs.unity3d.com/Manual/ScriptedImporters.html
https://docs.unity3d.com/ScriptReference/Experimental.AssetImporters.ScriptedImporter.html
https://docs.unity3d.com/ScriptReference/Experimental.AssetImporters.ScriptedImporterEditor.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值