| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityStandardAssets.ImageEffects;
- /* 复制器-对相机上挂在的组件进行批量复制和粘贴 */
- public class CameraCopyer : MonoBehaviour
- {
- [SerializeField] GameObject src;
- [SerializeField] GameObject dest1;
- [SerializeField] GameObject dest2;
- void Awake() {
- Component[] components = {
- src.GetComponent<FlareLayer>(),
- src.GetComponent<VignetteAndChromaticAberration>(),
- src.GetComponent<Bloom>(),
- src.GetComponent<ScreenSpaceAmbientObscurance>(),
- src.GetComponent<GlobalFog>()
- };
- foreach (Component item in components)
- {
- // UnityEditorInternal.ComponentUtility.CopyComponent(item);
- // UnityEditorInternal.ComponentUtility.PasteComponentAsNew(dest1);
- // UnityEditorInternal.ComponentUtility.PasteComponentAsNew(dest2);
- CopyComponent(item, dest1);
- CopyComponent(item, dest2);
- }
- Color skyBoxBgColor = src.GetComponent<Camera>().backgroundColor;
- dest1.GetComponent<Camera>().backgroundColor = skyBoxBgColor;
- dest2.GetComponent<Camera>().backgroundColor = skyBoxBgColor;
- }
- void CopyComponent(Component comp, GameObject dest)
- {
- System.Type type = comp.GetType();
- Component copy = dest.AddComponent(type);
- System.Reflection.FieldInfo[] fields = type.GetFields();
- foreach (System.Reflection.FieldInfo field in fields)
- {
- field.SetValue(copy, field.GetValue(comp));
- }
- }
- }
|