Unity 编辑器下对Prefab预设的一些操作

	
	//给预设增加AssetBundle名称
	[MenuItem("ILFrameWork/Prefab rename", false, 10)]

    static void reboot_rename()
    {
        setPrefabname("xxx");
    }

	//给一个对象命名预设名称,可以选择多个,并单独命名
    static void setPrefabname(string xxx)
    {
        foreach (var obj in Selection.GetFiltered<UnityEngine.Object>(SelectionMode.Assets))
        {
            var path = AssetDatabase.GetAssetPath(obj);
            if (string.IsNullOrEmpty(path))
                continue;

            if (System.IO.File.Exists(path))
            {
                int idx = path.LastIndexOf(".");
                if (idx != -1)
                {
                    int len = path.Length - idx;
                    string rename = path.Substring(0, path.Length - len);
                    
                    rename = xxx + rename;
                    AssetImporter assetImporter = AssetImporter.GetAtPath(path);  //得到Asset
                    assetImporter.assetBundleName = rename;
                    Debug.Log(rename);
                }
            }
        }
    }

对于设置预设名,还可以设置预设的扩展名(点后面的)

                    AssetImporter assetImporter = AssetImporter.GetAtPath(path);  //得到Asset
                    string extname = Path.GetExtension(prefabname);
                    assetImporter.assetBundleName = cfg.prefabname.Replace(extname,"");
                    assetImporter.assetBundleVariant = extname.Replace(".","");
	//选择一个预设,并复制他的名字到粘贴板
	[MenuItem("ILFrameWork/Prefab name copy", false, 10)]
    static void namecopy()
    {
        foreach (var obj in Selection.GetFiltered<UnityEngine.Object>(SelectionMode.Assets))
        {
            var path = AssetDatabase.GetAssetPath(obj);
            if (string.IsNullOrEmpty(path))
                continue;
            AssetImporter assetImporter = AssetImporter.GetAtPath(path);

            string fullname = assetImporter.assetBundleName + "." + assetImporter.assetBundleVariant;
            TextEditor t = new TextEditor();
            t.text = fullname;
            t.OnFocus();
            t.Copy();
            Debug.Log("名称已经复制到粘贴板 : "+ fullname);
        }
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值