출처 : http://answers.unity3d.com/questions/458207/copy-a-component-at-runtime.html
1 2 3 4 5 6 7 8 9 10 11 12 | T CopyComponent<T>(T original, GameObject destination) where T : Component { System.Type type = original.GetType(); Component copy = destination.AddComponent(type); System.Reflection.FieldInfo[] fields = type.GetFields(); foreach (System.Reflection.FieldInfo field in fields) { field.SetValue(copy, field.GetValue(original)); } return copy as T; } | cs |
Type.GetFiels
(https://msdn.microsoft.com/ko-kr/library/ch9714z3(v=vs.110).aspx)
- 현재 타입에서 public 필드를 가져오는 함수입니다. [SerializeField]는 가져오지 않습니다.
'Game Programming > Unity3D' 카테고리의 다른 글
| Unity에서 스크린샷 (0) | 2016.06.15 |
|---|---|
| 렌더텍스쳐 좌표계(Render Texture coordinates) (0) | 2016.06.15 |
| C++에서 C#함수 호출(곁다리로 C#에서 C++함수 호출) (0) | 2015.06.03 |
| Unity 빌드할 때 유의사항 (0) | 2015.06.03 |