Created
January 4, 2017 12:21
-
-
Save DmitriyYukhanov/e3fe8fb9ee3675eaa227c8f43fcedac1 to your computer and use it in GitHub Desktop.
How to select asset in Project Browser without loading Asset.
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
// use to select asset at the Project Browser when you know path and asset | |
// has no objects inside, e.g. AssetDatabase.LoadMainAssetAtPath() returns null | |
// path - relative to Project folder, e.g. Assets/StrangeFile.asset | |
public static void SelectNonObjectFile(string path) | |
{ | |
string guid = AssetDatabase.AssetPathToGUID(path); | |
// in perfect world, all reflection should be cached (including method delegate) | |
Type assetDatabaseType = typeof(AssetDatabase); | |
MethodInfo mi = assetDatabaseType.GetMethod("GetInstanceIDFromGUID", BindingFlags.NonPublic | BindingFlags.Static); | |
if (mi == null) | |
{ | |
Debug.LogError("AssetDatabase.GetInstanceIDFromGUID() not found via reflection!"); | |
return; | |
} | |
int instanceId = (int)mi.Invoke(null, new object[]{ guid }); | |
Selection.activeInstanceID = instanceId; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometime we will cache averything... sometime...
Nice solution! =)