Skip to content

Instantly share code, notes, and snippets.

@AndreySkyFoxSidorov
Created November 2, 2016 10:56
Show Gist options
  • Save AndreySkyFoxSidorov/977e5b0a91b3bc3e2acf53917e32f410 to your computer and use it in GitHub Desktop.
Save AndreySkyFoxSidorov/977e5b0a91b3bc3e2acf53917e32f410 to your computer and use it in GitHub Desktop.
Search object in Prefabs, Material, Scene, by GUID
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using System;
using System.IO;
public class findGuid : MonoBehaviour {
[MenuItem("Assets/Find GUID in Prefabs Material Scene")]
private static void FindGUIDinPrefabs1()
{
var selected = Selection.activeObject;
string patch = AssetDatabase.GetAssetPath(selected);
string guids = AssetDatabase.AssetPathToGUID(patch);
Debug.Log("" + patch + " guid: " + guids + "");
findObj(guids, "t: Material");
findObj(guids, "t: Prefab");
findObj(guids, "t: Scene");
}
[MenuItem("Assets/Find GUID in Prefabs")]
private static void FindGUIDinPrefabs2()
{
var selected = Selection.activeObject;
string patch = AssetDatabase.GetAssetPath(selected);
string guids = AssetDatabase.AssetPathToGUID(patch);
Debug.Log("" + patch + " guid: " + guids + "");
findObj(guids, "t: Prefab");
}
[MenuItem("Assets/Find GUID in Material")]
private static void FindGUIDinPrefabs3()
{
var selected = Selection.activeObject;
string patch = AssetDatabase.GetAssetPath(selected);
string guids = AssetDatabase.AssetPathToGUID(patch);
Debug.Log("" + patch + " guid: " + guids + "");
findObj(guids, "t: Material");
}
[MenuItem("Assets/Find GUID in Scene")]
private static void FindGUIDinPrefabs4()
{
var selected = Selection.activeObject;
string patch = AssetDatabase.GetAssetPath(selected);
string guids = AssetDatabase.AssetPathToGUID(patch);
Debug.Log("<size=12><color=#0000ffff>" + patch + " guid: " + guids + "</color></size>");
findObj(guids, "t: Scene");
}
static List<string> ret = new List<string>();
public static List<string> findObj(string guids, string findAssetsText)
{
ret = new List<string>();
string[] guids2 = AssetDatabase.FindAssets(findAssetsText);
foreach (string guid in guids2)
{
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
try
{
using (StreamReader sr = new StreamReader(Application.dataPath + "/../" + assetPath))
{
string line = sr.ReadToEnd();
if (line.Contains(guids))
{
Debug.Log("<size=14><color=#0000ffff> Found file::" + assetPath + "</color></size>");
ret.Add(assetPath);
}
}
}
catch (Exception e)
{
Debug.Log(e.Message);
}
}
if (ret.Count < 1)
{
Debug.Log("<size=14><color=#ff0f0fff> NOT Found files</color></size>");
}
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment