Skip to content

Instantly share code, notes, and snippets.

@samjessup
Created June 17, 2015 12:32
Show Gist options
  • Save samjessup/8f71ccab276896f02ad1 to your computer and use it in GitHub Desktop.
Save samjessup/8f71ccab276896f02ad1 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
using System.IO;
public class FixPrefabThing
{
// Add menu item named "My Window" to the Window menu
[MenuItem("Sam/FixPrefabThing")]
public static void DoSomething()
{
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
if (path == "")
{
path = "Assets";
}
else if (Path.GetExtension(path) != "")
{
path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
}
if (path[path.Length - 1] == '/')
path = path.Substring(0, path.Length - 1);
if (!EditorUtility.DisplayDialog("Confirm folder", "Do you want to instantiate, update and delete all prefabs in folder: " + path, "OK", "Cancel"))
return;
DirectoryInfo dir = new DirectoryInfo(path);
FileInfo[] info = dir.GetFiles("*.prefab");
foreach (FileInfo f in info)
{
string s = path + "/" + f.Name; //.Replace(".prefab","");
GameObject pgo = AssetDatabase.LoadAssetAtPath(s, typeof(GameObject)) as GameObject;//AssetDatabase.LoadAssetAtPath(s, typeof(GameObject)) as GameObject;
GameObject go = PrefabUtility.InstantiatePrefab((Object)pgo) as GameObject;
PrefabUtility.ReplacePrefab(go, pgo, ReplacePrefabOptions.ConnectToPrefab);
GameObject.DestroyImmediate(go);
}
}
[MenuItem("Sam/FixEditorTimescale")]
public static void DoSomething2()
{
Time.timeScale = 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment