Created
June 17, 2015 12:32
-
-
Save samjessup/8f71ccab276896f02ad1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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