Unity开发中,你如果想要把某个对象的组件全部都拷贝到新的对象上,除了一个个复制粘贴组件,还要修改组件中的参数,也就是不断重复Copy Component 、Paste Component As New、Paste Component Values,实在是一件很麻烦的事,所以想办法将步骤合起来,直接复制物体上的所有组件、参数,一步搞定。
首先写一个脚本,将其放在Editor文件夹下面,代码如下:
CopyAllComponent.cs
using UnityEngine;
using UnityEditor;
using System.Collections;
public class CopyAllComponent : EditorWindow
{
static Component[] copiedComponents;
[MenuItem("GameObject/Copy Current Components #&C")]
static void Copy()
{
copiedComponents = Selection.activeGameObject.GetComponents<Component>();
}
[MenuItem("GameObject/Paste Current Components #&P")]
static void Paste()
{
foreach (var targetGameObject in Selection.gameObjects)
{
if (!targetGameObject || copiedComponents == null) continue;
foreach (va

在Unity开发中,复制对象的全部组件和参数通常繁琐。通过编写名为CopyAllComponent.cs的Editor脚本,可以实现一键复制并粘贴包括参数在内的所有组件。只需在菜单栏选择GameObject,使用Copy Current Components和Paste Current Components,即可便捷地完成整个对象的复制操作,极大地提高了工作效率。

1148

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



