Ok I have a small problem with the assetPostprocessor. I want to automatically add colliders and triggers on import using this script. I got this script from the wiki and it is really great ... but I am trying to add some extra functionality (The second Part of the script)and I have a problem.
everything is imported as a trigger ... I think that I have somehow to differentiate the array in but I am not sure how. Any help or suggestion will be appreciated. I am importing one model that has one trigger, one collision mesh, and the visible model.
public class BoundingBoxAdder : AssetPostprocessor {
void OnPostprocessModel(GameObject g)
{
// filter out only animations.
string lowerCaseAssetPath = assetPath.ToLower();
if (lowerCaseAssetPath.IndexOf("/environment/") == -1) //do this ONLY if we are in the ENVIRONMENT FOLDER, assets/environment/...
return;
Apply(g.transform);
}
// Add a mesh collider to each game object that contains collider in its name
void Apply (Transform transform){
if (transform.name.ToLower().Contains("collider")){
transform.gameObject.AddComponent(typeof(MeshCollider));
Object[] smr = transform.gameObject.GetComponentsInChildren(typeof(MeshRenderer), false);
Object[] mfs = transform.gameObject.GetComponentsInChildren(typeof(MeshFilter), false);
foreach (MeshRenderer o in smr){
Object.DestroyImmediate(o, true);
}
foreach (MeshFilter mf in mfs){
Object.DestroyImmediate(mf, true);
}
}
if (transform.name.ToLower().Contains("trigger")){
transform.gameObject.AddComponent(typeof(MeshCollider));
transform.gameObject.collider.isTrigger = true;
Object[] amr= transform.gameObject.GetComponentsInChildren(typeof(MeshRenderer), false);
Object[] afs = transform.gameObject.GetComponentsInChildren(typeof(MeshFilter), false);
foreach (MeshRenderer a in amr){
Object.DestroyImmediate(a, true);
}
foreach (MeshFilter af in afs){
Object.DestroyImmediate(af, true);
}
}
// Recurse
foreach(Transform child in transform)
Apply(child);
}
}