public void OpenMetaDataFile()
    {
        Object currentObject     = Selection.activeObject;
        string currentObjectPath = AssetDatabase.GetAssetPath(currentObject);
        string guid;

#if UNITY_2018_2
        long localID;
#else
        int localID;
#endif
        if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(currentObject, out guid, out localID))
        {
            string metadataPath = AssetExplorerUtility.GetMetadataFilePathFromAssetGuid(guid);
            EditorUtility.RevealInFinder(metadataPath);
        }
    }
예제 #2
0
    private static string CreateStringFromTemplate(string template, Object currentObject, string currentObjectPath)
    {
        string result = template;

        string guid;

#if UNITY_2018_2
        long localID;
#else
        int localID;
#endif
        if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(currentObject, out guid, out localID))
        {
            result = result.Replace(kName, currentObject.name);
            result = result.Replace(kFullName, Path.GetFileName(currentObjectPath));
            result = result.Replace(kGUID, guid);
            result = result.Replace(kLocalID, localID.ToString());
            result = result.Replace(kAssetType, AssetDatabase.IsForeignAsset(currentObject) ? "Foreign" : "Native");
            result = result.Replace(kImporter, AssetImporter.GetAtPath(currentObjectPath).GetType().Name);
            result = result.Replace(kMetaFilePath, AssetDatabase.GetTextMetaFilePathFromAssetPath(currentObjectPath));
            result = result.Replace(kLibraryMetaFilePath, AssetExplorerUtility.GetShortMetadataFilePathFromAssetGuid(guid));

            if (result.Contains(kAssetObjects))
            {
                // LoadAllAssetsAtPath is not possible for scenes
                if (!currentObjectPath.EndsWith(".unity"))
                {
                    string objectListString = string.Empty;

                    var objects = AssetDatabase.LoadAllAssetsAtPath(currentObjectPath);
                    for (var i = 0; i < objects.Length; i++)
                    {
                        Object obj = objects[i];

                        if (i == kMaxObjects)
                        {
                            objectListString += "<color=yellow>...</color>";
                            break;
                        }

                        string objString =
                            CreateStringFromTemplate("Name: <color=yellow>{Name}</color> - Type: <color=yellow>{Type}</color>\n", obj, currentObjectPath);
                        if (!AssetDatabase.IsMainAsset(obj))
                        {
                            objString = objString.Insert(0, "    ");
                        }

                        objectListString += objString;
                    }

                    result = result.Replace(kAssetObjects, objectListString);
                }
                else
                {
                    result = result.Replace(kAssetObjects, "<color=red>Accessing Objects within Scene is not allowed</color>");
                }
            }

            if (result.Contains(kNumAssetObjects))
            {
                if (currentObjectPath.EndsWith(".unity"))
                {
                    result = result.Replace(kNumAssetObjects, "1");
                }
                else
                {
                    result = result.Replace(kNumAssetObjects, AssetDatabase.LoadAllAssetsAtPath(currentObjectPath).Length.ToString());
                }
            }

            var dependancies = AssetDatabase.GetDependencies(currentObjectPath, false);
            result = result.Replace(kNumAssetDependancies, dependancies.Length.ToString());

            if (result.Contains(kAssetDependancies))
            {
                string dependancyListString = string.Empty;

                for (int i = 0; i < dependancies.Length; ++i)
                {
                    var depPath = dependancies[i];

                    if (i == kMaxDependancies)
                    {
                        dependancyListString += "<color=yellow>...</color>";
                        break;
                    }

                    var depObj = AssetDatabase.LoadMainAssetAtPath(depPath);

                    dependancyListString +=
                        CreateStringFromTemplate("Name: <color=yellow>{Name}</color> - Type: <color=yellow>{Type}</color>\n", depObj, depPath);
                }

                result = result.Replace(kAssetDependancies, dependancyListString);
            }
        }

        // We can check these on scene objects
        result = result.Replace(kType, currentObject.GetType().Name);
        result = result.Replace(kInstanceID, currentObject.GetInstanceID().ToString());

        return(result);
    }