MegaDeepCopy.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 
  2. #if !UNITY_WP8 && !UNITY_METRO
  3. using UnityEditor;
  4. using UnityEngine;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. public class MegaDeepCopy : MonoBehaviour
  8. {
  9. #if false
  10. [MenuItem("GameObject/Mega Copy Mesh")]
  11. static void DeepCopy()
  12. {
  13. GameObject subject = Selection.activeGameObject;
  14. GameObject clone = (GameObject)GameObject.Instantiate(subject);
  15. MeshFilter[] mfs = subject.GetComponentsInChildren<MeshFilter>();
  16. MeshFilter[] clonemfs = clone.GetComponentsInChildren<MeshFilter>();
  17. MeshCollider[] mcs = clone.GetComponentsInChildren<MeshCollider>();
  18. MeshCollider[] clonemcs = clone.GetComponentsInChildren<MeshCollider>();
  19. int l = mfs.Length;
  20. for ( int i = 0; i < l; i++ )
  21. {
  22. MeshFilter mf = mfs[i];
  23. MeshFilter clonemf = clonemfs[i];
  24. Mesh mesh = mf.sharedMesh;
  25. Mesh clonemesh = new Mesh();
  26. clonemesh.vertices = mesh.vertices;
  27. clonemesh.uv1 = mesh.uv1;
  28. clonemesh.uv2 = mesh.uv2;
  29. clonemesh.uv = mesh.uv;
  30. clonemesh.normals = mesh.normals;
  31. clonemesh.tangents = mesh.tangents;
  32. clonemesh.colors = mesh.colors;
  33. clonemesh.subMeshCount = mesh.subMeshCount;
  34. for ( int s = 0; s < mesh.subMeshCount; s++ )
  35. {
  36. clonemesh.SetTriangles(mesh.GetTriangles(s), s);
  37. }
  38. //clonemesh.triangles = mesh.triangles;
  39. clonemesh.boneWeights = mesh.boneWeights;
  40. clonemesh.bindposes = mesh.bindposes;
  41. clonemesh.name = mesh.name + "_copy";
  42. clonemesh.RecalculateBounds();
  43. clonemf.sharedMesh = clonemesh;
  44. for ( int j = 0; j < mcs.Length; j++ )
  45. {
  46. MeshCollider mc = mcs[j];
  47. if ( mc.sharedMesh = mesh )
  48. clonemcs[j].sharedMesh = clonemesh;
  49. }
  50. }
  51. }
  52. #endif
  53. [MenuItem("GameObject/Mega Deep Copy")]
  54. static void DeepCopyNew()
  55. {
  56. MegaCopyObject.DeepCopy(Selection.activeGameObject);
  57. }
  58. }
  59. #endif