SHOW:
|
|
- or go back to the newest paste.
| 1 | using UnityEngine; | |
| 2 | using UnityEditor; | |
| 3 | using System.Collections; | |
| 4 | ||
| 5 | - | public class ModelPropertyProcessor : AssetPostprocessor {
|
| 5 | + | public class ModelProcessor : AssetPostprocessor {
|
| 6 | ||
| 7 | void OnPostprocessGameObjectWithUserProperties (GameObject go, string[] propNames, System.Object[] values) {
| |
| 8 | ||
| 9 | for (int i = 0; i < propNames.Length; i++) {
| |
| 10 | ||
| 11 | string propName = propNames[i]; | |
| 12 | System.Object v = values[i]; | |
| 13 | ||
| 14 | - | Debug.Log("Model "+go.name+" has Property: " + propName + " with value: " +v);
|
| 14 | + | |
| 15 | {
| |
| 16 | // max exports all props as single string. we must split by return char | |
| 17 | string[] lines = ((string)v).Split('\n');
| |
| 18 | ||
| 19 | foreach (string line in lines) | |
| 20 | {
| |
| 21 | string prop = line.Trim(); | |
| 22 | Debug.Log (prop); | |
| 23 | ||
| 24 | if (prop == "splitfbx") | |
| 25 | {
| |
| 26 | ||
| 27 | string path = System.IO.Path.GetDirectoryName(assetPath); | |
| 28 | string assetFileName = System.IO.Path.GetFileNameWithoutExtension(assetPath); | |
| 29 | System.IO.Directory.CreateDirectory(path+"/"+assetFileName); | |
| 30 | string prefabPath = path+"/"+assetFileName+"/"+go.name+".prefab"; | |
| 31 | Object targetPrefab = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(Object)); | |
| 32 | ||
| 33 | if (targetPrefab != null) {
| |
| 34 | PrefabUtility.ReplacePrefab(go, targetPrefab, ReplacePrefabOptions.ReplaceNameBased); | |
| 35 | } else {
| |
| 36 | PrefabUtility.CreatePrefab( prefabPath, go ); | |
| 37 | } | |
| 38 | } | |
| 39 | ||
| 40 | ||
| 41 | if (prop == "boxcollider") | |
| 42 | {
| |
| 43 | go.AddComponent<BoxCollider>(); | |
| 44 | } | |
| 45 | ||
| 46 | if (prop == "spherecollider") | |
| 47 | {
| |
| 48 | go.AddComponent<SphereCollider>(); | |
| 49 | } | |
| 50 | - | } |
| 50 | + | |
| 51 | if (prop == "meshcollider") | |
| 52 | {
| |
| 53 | - | |
| 53 | + | |
| 54 | } | |
| 55 | ||
| 56 | if (prop == "proxy") | |
| 57 | {
| |
| 58 | go.renderer.enabled = false; | |
| 59 | if (go.GetComponent<Collider>() == null) | |
| 60 | {
| |
| 61 | go.AddComponent<MeshCollider>(); | |
| 62 | } | |
| 63 | } | |
| 64 | ||
| 65 | if (prop == "movable") | |
| 66 | {
| |
| 67 | go.AddComponent<Rigidbody>(); | |
| 68 | MeshCollider mc = go.GetComponent<MeshCollider>(); | |
| 69 | ||
| 70 | if (mc != null) | |
| 71 | {
| |
| 72 | mc.convex = true; | |
| 73 | } | |
| 74 | } | |
| 75 | ||
| 76 | } | |
| 77 | ||
| 78 | } | |
| 79 | ||
| 80 | ||
| 81 | } | |
| 82 | } | |
| 83 | } |