Unity3D --游戏体上所有Component组件复制
来源:互联网 发布:数组和指针作为形参 编辑:程序博客网 时间:2024/05/18 07:53
该篇文章只是实现以下功能
1、实现复制功能 Copy Component
2、实现粘贴功能 Paste Component As New和Paste Component Values
直接上可运行代码:
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEditor;using System;public class CopyComponent : Editor { static Component[] compoentArr; [MenuItem("Component Editor/Copy Component")] static void DoCopyComponent() { compoentArr = Selection.activeGameObject.GetComponents<Component> (); } [MenuItem("Component Editor/Paste Component")] static void DoPasteComponent() { if (compoentArr == null) { return; } GameObject targetObject = Selection.activeGameObject; if (targetObject == null) { return; } for (int i = 0; i < compoentArr.Length; i++) { Component newComponent = compoentArr [i]; if (newComponent == null) { continue; } UnityEditorInternal.ComponentUtility.CopyComponent (newComponent); Component oldComponent = targetObject.GetComponent (newComponent.GetType ()); if (oldComponent != null) { if (UnityEditorInternal.ComponentUtility.PasteComponentValues (oldComponent)) { Debug.Log ("Paste Values " + newComponent.GetType ().ToString () + " Success"); } else { Debug.Log ("Paste Values " + newComponent.GetType ().ToString () + " Failed"); } } else { if (UnityEditorInternal.ComponentUtility.PasteComponentAsNew (targetObject)) { Debug.Log ("Paste New Values " + newComponent.GetType ().ToString () + " Success"); } else { Debug.Log ("Paste New Values " + newComponent.GetType ().ToString () + " Failed"); } } } }}
最后效果:
被我们复制相机的组件信息
粘贴到新创建的游戏体中
阅读全文
0 0
- Unity3D --游戏体上所有Component组件复制
- unity3d教程游戏目标 (GameObject) 和组件 (Component) 的联系
- Unity3d之组件Component
- Unity3d之组件Component
- Unity3D入门基础之游戏对象 (GameObject) 和组件 (Component) 的关系
- unity3D -- 给游戏体添加组件
- Unity3D对Component组件的管理机制
- Unity3D如何获取GameObject上的Component
- Unity3d基础之组件 (Component) 和脚本 (Script) 的关系
- 组件 - Component
- Unity3D-各个组件/游戏对象作用
- Android核心技术之(3)上---系统组件component
- Unity3D 改变对象下所有子对象的组件属性
- 取到对象上所有组件
- 遍历Panel组件上的所有控件:
- Unity3D游戏开发之Lua与游戏的不解之缘(上)
- 游戏动作师使用Unity3D遇到过的所有问题
- 游戏动作师使用Unity3D遇到过的所有问题
- 第十五周项目一(6)——堆排序
- 微信摇一摇(模拟)
- CtrlP命令
- linux查找文件命令find
- Move Zeroes(leetcode)
- Unity3D --游戏体上所有Component组件复制
- Error:Please select Android SDK
- 态度支付,如何用聚合支付帮助商家赚钱
- Masonry学习之UILabel
- 算符优先系列之(一)Firstvt和Lastvt集 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Descri
- 字符解码时加号解码为空格问题探究
- 文章标题
- Linux 多线程编程
- Java调用Python测试成功的记录