Advertisement
duck

Unity 3D Post process game object with user properties

Nov 13th, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4.  
  5. public class ModelPropertyProcessor : 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);
  15.  
  16.             if (propName == "UDP3DSMAX")
  17.             {
  18.                 // max exports all props as single string. we must split by return char
  19.                 string[] lines = ((string)v).Split('\n');
  20.                
  21.                 foreach (string line in lines)
  22.                 {
  23.                     string prop = line.Trim();
  24.                     Debug.Log (prop);
  25.                     if (prop == "boxcollider")
  26.                     {
  27.                         go.AddComponent<BoxCollider>();
  28.                     }
  29.            
  30.                     if (prop == "spherecollider")
  31.                     {
  32.                         go.AddComponent<SphereCollider>();
  33.                     }
  34.            
  35.                     if (prop == "meshcollider")
  36.                     {
  37.                         go.AddComponent<MeshCollider>();
  38.                     }
  39.                        
  40.                     if (prop == "proxy")
  41.                     {
  42.                         go.renderer.enabled = false;
  43.                     }
  44.                        
  45.                     if (prop == "movable")
  46.                     {
  47.                         go.AddComponent<Rigidbody>();
  48.                     }
  49.                    
  50.         }
  51.                    
  52.             }
  53.                
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement