您当前的位置: 首页 >  unity
  • 4浏览

    0关注

    193博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity在编辑器中删除本地资源文件和移除组件

我寄人间雪满头丶 发布时间:2020-05-09 14:08:04 ,浏览量:4

复制组件
	//编辑器模式下
    UnityEditorInternal.ComponentUtility.CopyComponent(component);
    UnityEditorInternal.ComponentUtility.PasteComponentAsNew(component);
    //运行模式下,利用反射
    System.Type type = component.GetType();   
    Component copy = objEnd.AddComponent(type);
    System.Reflection.FieldInfo[] fields = type.GetFields();
    foreach (System.Reflection.FieldInfo field in fields)
    {
        field.SetValue(copy, field.GetValue(anim));
    }
移除组件

Unity中只有AddComponent,没有RemoveComponent。 移除组件如果是运行中用Destroy,如果是编辑器脚本用DestroyImmediateDestroyImmediate(component, true); //第一个参数是组件类型,后面的bool参数是是否允许销毁资源文件。

删除

删除项目中的资源:File.Delete(path); //注意Path是相对路径,Assets/xxx

关注
打赏
1648518768
查看更多评论
立即登录/注册

微信扫码登录

0.1294s