当前位置: 首页 > news >正文

Unity 生成模版代码

1、创建模版代码文本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ClassNameScritpItem : MonoBehaviour
{public GameObject go;// Start is called before the first frame updatevoid Start(){go = new GameObject();}// Update is called once per framevoid Update(){}//测试public void Click(){ }//Testpublic void Test(){ }
}

2、创建代码脚本
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.ProjectWindowCallback;
using System.IO;
public class CreateSriptTool
{[MenuItem("Exaples/Create Sripts")]static void Init(){ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<CteateSriptItem>(),"ExampleComponet", null, null);}
}public class CteateSriptItem : EndNameEditAction
{public override void Action(int instanceId, string pathName, string resourceFile){DoCreate(instanceId, pathName, resourceFile);}public static string replaceTag = "ClassName";public static void DoCreate(int instanceId, string pathName, string resourceFile){EditorUtility.DisplayProgressBar("生成脚本", "生成中", 0.5f);string str = pathName.Split('/')[2];Debug.LogError("pathName:" + str);string CsText = File.ReadAllText(Application.dataPath + "/ComponentTemp/" + "ScritpItem.txt");CsText = CsText.Replace(replaceTag, str);File.WriteAllText(pathName + "ScritpItem.cs", CsText, System.Text.Encoding.UTF8);AssetDatabase.Refresh();EditorUtility.DisplayProgressBar("生成脚本", "完成", 1f);EditorUtility.ClearProgressBar();}
}

3、运行测试

http://www.lryc.cn/news/355500.html

相关文章:

  • 【ai】chatgpt的plugin已经废弃
  • 2024年03月 Python(四级)真题解析#中国电子学会#全国青少年软件编程等级考试
  • 多旋翼无人机机场考哪些内容?
  • 【前端每日基础】day23——箭头函数
  • 27.Java中单例模式的实现方式
  • C#面:当一个线程进入一个对象的方法后,其它线程是否可以进入该对象的方法?
  • express框架下后端获取req.body报错undefined
  • Element plus 低版本弹窗组件添加拖拽功能
  • 计算机组成原理易混淆知识点总结(持续更新)
  • 【STM32踩坑】HAL固件库版本过高导致烧录后无法运行问题
  • 芯片丝印反查
  • C语言之指针详解(5)(含有易错笔试题)
  • discuzX2.5的使用心得 札记一
  • 【Python】 探索Django框架的高并发处理能力
  • C-数据结构-平横二叉树
  • 算法训练营day41
  • cesium开发实例分享
  • 字符串和字符串函数(1)
  • 基于springboot+vue的班级综合测评管理系统
  • 蓝海项目揭秘:跨境选品师的崛起与挑战
  • 酷黑简洁大气体育直播自适应模板赛事直播门户网站源码
  • 2024年电工杯高校数学建模竞赛(B题) 建模解析| 大学生平衡膳食食谱的优化设计
  • 学习编程对英语要求高吗?
  • 使用 Django 和 RabbitMQ 构建高效的消息队列系统
  • Pycharm常见问题1
  • 开发一个comfyui的自定义节点
  • Prime算法构造最小生成树(加点法)
  • 【VTKExamples::Utilities】第五期 CommandSubclass
  • 重生之 SpringBoot3 入门保姆级学习(04、 包扫描)
  • VectorDBBench在windows的调试