Unity Editor 深拷贝 组件
2017-07-27 15:24
876 查看
Unity Editor 深拷贝 组件
GameObject Inspector 面板上 Copy Component 功能 的实现
![](https://oscdn.geek-share.com/Uploads/Images/Content/202012/18/961a37ecbc8ddb8a3123176a494e90bb)
GameObject Inspector 面板上 Copy Component 功能 的实现
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using System; public class Copy : EditorWindow { static Component[] componentArr; [MenuItem("GameObject/Copy Component %#C")] static void CopyComponent() { componentArr = Selection.activeGameObject.GetComponents<Component>(); } [MenuItem("GameObject/Paste Component %#V")] static void PasteComponent() { if (componentArr == null) { return; } GameObject targetGameObject = Selection.activeGameObject; if (!targetGameObject) { return; } for (int i = 0; i < componentArr.Length; ++i) { Component component = componentArr[i]; if (!component) { continue; } UnityEditorInternal.ComponentUtility.CopyComponent(component); Type type = component.GetType(); Component componentOld = targetGameObject.GetComponent(type); if (!componentOld) { UnityEditorInternal.ComponentUtility.PasteComponentAsNew(targetGameObject); } else { UnityEditorInternal.ComponentUtility.PasteComponentValues(component); } } } }
相关文章推荐
- Unity对象的所有组件深拷贝与粘贴
- UnityEditor 如何将一个资源文件夹下的对象拖曳赋值到文件夹外的某个对象组件属性中
- Unity对象的所有组件深拷贝与粘贴
- Unity对象的所有组件深拷贝与粘贴
- Unity界面插件NGUI核心组件介绍
- [Unity]代码组件动态改变天空盒
- unity——使用角色控制器组件+射线移动
- 在Unity中使用C#的深度拷贝
- 【Unity】4.1 创建组件
- 王者荣耀是怎样炼成的(三)unity组件与脚本
- Unity Editor Extensions – Menu Items私人定制
- 【转载】Unity3d UnityEditor编辑器定制和开发插件
- Unity不同路径下的文件拷贝
- Unity UGUI——Rect Transform组件(Anchor Presets)
- Unity Editor Toolbar 编辑器扩展
- unity_NGUI系统学习(三)_Button组件
- unity_Editor自定义窗口顶部添加小图标
- EditorGridPanel组件取消某一行的编辑状态
- 【Unity】Unity移除组件(获取物体身上所有组件)
- Unity界面插件NGUI核心组件说明