Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEditor.SceneManagement;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System;
  7. using System.Linq;
  8.  
  9. public class ModelProcessorExample : AssetPostprocessor
  10. {
  11. void OnPreprocessModel ()
  12. {
  13. var imp = assetImporter as ModelImporter;
  14. var asset = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath) as GameObject;
  15. }
  16.  
  17. void OnPostprocessModel (GameObject go)
  18. {
  19. Process(go.transform);
  20. }
  21.  
  22. void Process (Transform tran)
  23. {
  24. string name = tran.name.ToLower();
  25.  
  26. if (name.Contains("boxcollider"))
  27. {
  28. //TODO: don't create it as a child if it's not rotated at all
  29. //just add the boxCollider directly to the parent instead!
  30.  
  31. var mf = tran.GetComponent<MeshFilter>();
  32.  
  33. if(mf != null)
  34. {
  35. var mesh = mf.sharedMesh;
  36.  
  37. if(mesh != null)
  38. {
  39. var box = tran.gameObject.AddComponent<BoxCollider>();
  40. box.size = mesh.bounds.size;
  41. box.center = mesh.bounds.center;
  42.  
  43. GameObject.DestroyImmediate(tran.GetComponent<Renderer>());
  44. }
  45. }
  46. }
  47. else if (name.Contains("collider"))
  48. {
  49. tran.gameObject.AddComponent<MeshCollider>();
  50. }
  51.  
  52. // Recurse
  53. foreach (Transform child in tran)
  54. {
  55. Process(child);
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement