Skip to content

Instantly share code, notes, and snippets.

@AndreySkyFoxSidorov
Created November 8, 2016 19:43
Show Gist options
  • Select an option

  • Save AndreySkyFoxSidorov/7eb9f8f37a3236e29af8752b8f774539 to your computer and use it in GitHub Desktop.

Select an option

Save AndreySkyFoxSidorov/7eb9f8f37a3236e29af8752b8f774539 to your computer and use it in GitHub Desktop.
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 + "");
List<UnityEngine.Object> gos = new List<UnityEngine.Object>();
foreach (string patchlist in findObj(guids, "t: Material"))
{
gos.Add(AssetDatabase.LoadAssetAtPath(patchlist, typeof(UnityEngine.Object)));
}
foreach (string patchlist in findObj(guids, "t: Prefab"))
{
gos.Add(AssetDatabase.LoadAssetAtPath(patchlist, typeof(UnityEngine.Object)));
}
foreach (string patchlist in findObj(guids, "t: Scene"))
{
gos.Add(AssetDatabase.LoadAssetAtPath(patchlist, typeof(UnityEngine.Object)));
}
if (gos.Count > 0)
{
Selection.objects = gos.ToArray();
}
}
[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 + "");
List<UnityEngine.Object> gos = new List<UnityEngine.Object>();
foreach (string patchlist in findObj(guids, "t: Prefab"))
{
gos.Add(AssetDatabase.LoadAssetAtPath(patchlist, typeof(UnityEngine.Object)));
}
if (gos.Count > 0)
{
Selection.objects = gos.ToArray();
}
}
[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 + "");
List<UnityEngine.Object> gos = new List<UnityEngine.Object>();
foreach (string patchlist in findObj(guids, "t: Material"))
{
gos.Add(AssetDatabase.LoadAssetAtPath(patchlist, typeof(UnityEngine.Object)));
}
if (gos.Count > 0)
{
Selection.objects = gos.ToArray();
}
}
[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>");
List<UnityEngine.Object> gos = new List<UnityEngine.Object>();
foreach (string patchlist in findObj(guids, "t: Scene"))
{
gos.Add(AssetDatabase.LoadAssetAtPath(patchlist, typeof(UnityEngine.Object)));
}
if (gos.Count > 0)
{
Selection.objects = gos.ToArray();
}
}
[MenuItem("Assets/Find all Texture in folder")]
private static void FindTexture()
{
var selected = Selection.activeObject;
List<string> patch = new List<string>();
patch.Add(AssetDatabase.GetAssetPath(selected));
string[] guids2 = AssetDatabase.FindAssets(" t:Texture", patch.ToArray());
List<UnityEngine.Object> gos = new List<UnityEngine.Object>();
foreach (string guid in guids2)
{
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
Debug.Log(assetPath);
gos.Add(AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object)));
}
if (gos.Count > 0)
{
Selection.objects = gos.ToArray();
}
}
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