Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- public class AutoSplitFBX : 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 );
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment