zoukankan      html  css  js  c++  java
  • 复制、粘贴一个物体的所有组件

     1 using UnityEngine;
     2 using UnityEditor;
     3 using System.Collections.Generic;
     4 
     5 public class CopyAllComponent : EditorWindow
     6 {
     7     static Component[] copiedComponents;
     8     [MenuItem("GameObject/Copy Current Components",false,10)]
     9     static void Copy()
    10     {
    11         copiedComponents = Selection.activeGameObject.GetComponents<Component>();
    12     }
    13 
    14     [MenuItem("GameObject/Paste Current Components",false,10)]
    15     static void Paste()
    16     {
    17         foreach (var targetGameObject in Selection.gameObjects)
    18         {
    19             if (!targetGameObject || copiedComponents == null) continue;
    20 
    21             var targetComponents = new List<Component>(targetGameObject.GetComponents<Component>());
    22 
    23             foreach (var copiedComponent in copiedComponents)
    24             {
    25                 if (!copiedComponent) continue;
    26 
    27                 var targetComponent = targetComponents.Find((item) => item.GetType() == copiedComponent.GetType());
    28 
    29                 UnityEditorInternal.ComponentUtility.CopyComponent(copiedComponent);
    30 
    31                 if (targetComponent != null)
    32                 {
    33                     UnityEditorInternal.ComponentUtility.PasteComponentValues(targetComponent);
    34                 }
    35                 else
    36                 {
    37                     UnityEditorInternal.ComponentUtility.PasteComponentAsNew(targetGameObject);
    38                 }
    39             }
    40         }
    41     }
    42 
    43 }
  • 相关阅读:
    Integer的疑惑
    简单选择排序算法
    冒泡排序
    插入排序算法java
    BinaryOperator<T>接口的用法示例+BiFunction
    装箱和拆箱、类型比较
    java的Junit的用法(转发)
    htmlnav
    好用的壁纸网站大全
    c# 财务数据编号的生辰
  • 原文地址:https://www.cnblogs.com/bzyzhang/p/5517862.html
Copyright © 2011-2022 走看看