unity复制所有组件的值&&在hierarchy面板添加按钮
using UnityEngine;
using UnityEditor;
using System.Collections;
using System;
public class CopyAllComponent : EditorWindow
{
static Component[] copiedComponents;
[MenuItem("GameObject/复制所有组件", false, 0)]
[MenuItem("Component Editor/Copy Component")]
static void DoCopyComponent()
{
copiedComponents = Selection.activeGameObject.GetComponents<Component>();
}
[MenuItem("GameObject/粘贴所有组件Value", false, 0)]
[MenuItem("Component Editor/Paste Component")]
static void DoPasteComponent()
{
if (copiedComponents == null)
{
return;
}
GameObject targetObject = Selection.activeGameObject;
if (targetObject == null)
{
return;
}
for (int i = 0; i < copiedComponents.Length; i++)
{
Component newComponent = copiedComponents[i];

这个博客介绍了如何在Unity中创建一个编辑器扩展,该扩展允许用户复制选定游戏对象的所有组件及其值,并在Hierarchy面板中粘贴这些值到其他对象上。通过使用UnityEditorInternal.ComponentUtility类的方法,可以实现组件值的复制和粘贴功能,这对于快速复制对象属性非常有用。
最低0.47元/天 解锁文章
389

被折叠的 条评论
为什么被折叠?



