Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEditor;
- using UnityEditor.SceneManagement;
- using System.Collections;
- using System.Collections.Generic;
- using System;
- using System.Linq;
- public class ModelProcessorExample : AssetPostprocessor
- {
- void OnPreprocessModel ()
- {
- var imp = assetImporter as ModelImporter;
- var asset = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath) as GameObject;
- }
- void OnPostprocessModel (GameObject go)
- {
- Process(go.transform);
- }
- void Process (Transform tran)
- {
- string name = tran.name.ToLower();
- if (name.Contains("boxcollider"))
- {
- //TODO: don't create it as a child if it's not rotated at all
- //just add the boxCollider directly to the parent instead!
- var mf = tran.GetComponent<MeshFilter>();
- if(mf != null)
- {
- var mesh = mf.sharedMesh;
- if(mesh != null)
- {
- var box = tran.gameObject.AddComponent<BoxCollider>();
- box.size = mesh.bounds.size;
- box.center = mesh.bounds.center;
- GameObject.DestroyImmediate(tran.GetComponent<Renderer>());
- }
- }
- }
- else if (name.Contains("collider"))
- {
- tran.gameObject.AddComponent<MeshCollider>();
- }
- // Recurse
- foreach (Transform child in tran)
- {
- Process(child);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement