Guest User

RigidBody interpolation changer

a guest
May 27th, 2017
419
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Assets/Editor/ModifyRigidBodyEditor.cs
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6.  
  7. class ModifyRigidBodyEditor {
  8.     [MenuItem("Tools/Change all RigidBody Interpolations in assets to None... :(")]
  9.     static void ModifyRigidBodyMenu() {
  10.  
  11.         if (EditorUtility.DisplayDialog("Rigid Body changer","Are you sure you want to change all of your assets RigidBody interpolations to None? There's no undo for this", "Do it...", "Don't do it, I'll wait for unity to fix this...")){
  12.             string[] allPrefabs = GetAllPrefabs();
  13.             foreach (string prefab in allPrefabs) {
  14.  
  15.  
  16.                 UnityEngine.Object o = AssetDatabase.LoadMainAssetAtPath(prefab);
  17.                 GameObject go;
  18.                 try {
  19.                     go = (GameObject)o;
  20.                     foreach (Rigidbody c in go.GetComponentsInChildren<Rigidbody>(true)) {
  21.                         c.interpolation = RigidbodyInterpolation.None;
  22.                         Debug.Log("Prefab's " + prefab + " RigidBody interpolation set to None");
  23.                     }
  24.                 } catch {
  25.                     Debug.Log("Warning: Prefab " + prefab + " won't cast to GameObject");
  26.  
  27.                 }
  28.             }
  29.         }
  30.     }
  31.  
  32.     public static string[] GetAllPrefabs() {
  33.         string[] temp = AssetDatabase.GetAllAssetPaths();
  34.         List<string> result = new List<string>();
  35.         foreach (string s in temp) {
  36.             if (s.Contains(".prefab")) result.Add(s);
  37.         }
  38.         return result.ToArray();
  39.     }
  40. }
RAW Paste Data