Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- public class ModelProcessor : AssetPostprocessor {
- void OnPostprocessGameObjectWithUserProperties (GameObject go, string[] propNames, System.Object[] values) {
- for (int i = 0; i < propNames.Length; i++) {
- string propName = propNames[i];
- System.Object v = values[i];
- if (propName == "UDP3DSMAX")
- {
- // max exports all props as single string. we must split by return char
- string[] lines = ((string)v).Split('\n');
- foreach (string line in lines)
- {
- string prop = line.Trim();
- Debug.Log (prop);
- if (prop == "splitfbx")
- {
- string path = System.IO.Path.GetDirectoryName(assetPath);
- string assetFileName = System.IO.Path.GetFileNameWithoutExtension(assetPath);
- System.IO.Directory.CreateDirectory(path+"/"+assetFileName);
- string prefabPath = path+"/"+assetFileName+"/"+go.name+".prefab";
- Object targetPrefab = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(Object));
- if (targetPrefab != null) {
- PrefabUtility.ReplacePrefab(go, targetPrefab, ReplacePrefabOptions.ReplaceNameBased);
- } else {
- PrefabUtility.CreatePrefab( prefabPath, go );
- }
- }
- if (prop == "boxcollider")
- {
- go.AddComponent<BoxCollider>();
- }
- if (prop == "spherecollider")
- {
- go.AddComponent<SphereCollider>();
- }
- if (prop == "meshcollider")
- {
- go.AddComponent<MeshCollider>();
- }
- if (prop == "proxy")
- {
- go.renderer.enabled = false;
- if (go.GetComponent<Collider>() == null)
- {
- go.AddComponent<MeshCollider>();
- }
- }
- if (prop == "movable")
- {
- go.AddComponent<Rigidbody>();
- MeshCollider mc = go.GetComponent<MeshCollider>();
- if (mc != null)
- {
- mc.convex = true;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement