CameraCopyer.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityStandardAssets.ImageEffects;
  5. public class CameraCopyer : MonoBehaviour
  6. {
  7. [SerializeField] GameObject src;
  8. [SerializeField] GameObject dest1;
  9. [SerializeField] GameObject dest2;
  10. void Awake() {
  11. Component[] components = {
  12. src.GetComponent<FlareLayer>(),
  13. src.GetComponent<VignetteAndChromaticAberration>(),
  14. src.GetComponent<Bloom>(),
  15. src.GetComponent<ScreenSpaceAmbientObscurance>(),
  16. src.GetComponent<GlobalFog>()
  17. };
  18. foreach (Component item in components)
  19. {
  20. // UnityEditorInternal.ComponentUtility.CopyComponent(item);
  21. // UnityEditorInternal.ComponentUtility.PasteComponentAsNew(dest1);
  22. // UnityEditorInternal.ComponentUtility.PasteComponentAsNew(dest2);
  23. CopyComponent(item, dest1);
  24. CopyComponent(item, dest2);
  25. }
  26. Color skyBoxBgColor = src.GetComponent<Camera>().backgroundColor;
  27. dest1.GetComponent<Camera>().backgroundColor = skyBoxBgColor;
  28. dest2.GetComponent<Camera>().backgroundColor = skyBoxBgColor;
  29. }
  30. void CopyComponent(Component comp, GameObject dest)
  31. {
  32. System.Type type = comp.GetType();
  33. Component copy = dest.AddComponent(type);
  34. System.Reflection.FieldInfo[] fields = type.GetFields();
  35. foreach (System.Reflection.FieldInfo field in fields)
  36. {
  37. field.SetValue(copy, field.GetValue(comp));
  38. }
  39. }
  40. }