Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- public class ModelImportProcessor : AssetPostprocessor
- {
- // requires a CustomEditor of OffmeshLinkInspector!
- void OnPostprocessModel (GameObject g)
- {
- Apply (g.transform);
- }
- void Apply (Transform t)
- {
- if (t.name.ToLower ().Contains ("ladder")) {
- var link = t.gameObject.AddComponent<OffMeshLink> ();
- // find top & bottom of ladder
- SerializedObject linkObj = new SerializedObject (link);
- var start = linkObj.FindProperty ("m_Start");
- var end = linkObj.FindProperty ("m_End");
- var layer = linkObj.FindProperty ("m_NavMeshLayer");
- Debug.Log ("ladder found");
- foreach (Transform child in t) {
- Debug.Log ("child: " + child.name);
- if (child.name.ToLower ().StartsWith ("top")) {
- start.objectReferenceValue = child;
- Debug.Log ("set start");
- }
- if (child.name.ToLower ().StartsWith ("bottom")) {
- end.objectReferenceValue = child;
- Debug.Log ("set end");
- }
- }
- layer.intValue = NavMesh.GetNavMeshLayerFromName ("Ladder");
- linkObj.ApplyModifiedProperties ();
- }
- // Recurse
- foreach (Transform child in t) {
- Apply (child);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment