public static AssetRef ExtractFromMatch(Match match)
        {
            var  fileIdString = match.Groups[2].Value;
            long fileId       = long.Parse(fileIdString);
            var  guid         = match.Groups[4].Value;

            return(AssetRef.New(fileId, guid));
        }
        public static void ReplaceDependency(string userPath, Object originalDependency, Object replacementDependency)
        {
            AssetDatabase.TryGetGUIDAndLocalFileIdentifier(originalDependency, out string originalGuid, out long originalLocalId);
            AssetDatabase.TryGetGUIDAndLocalFileIdentifier(replacementDependency, out string replacementGuid, out long replacementLocalId);
            Debug.Log($"DEPENDENCY: {originalGuid} - {originalLocalId} - {AssetDatabase.GUIDToAssetPath(originalGuid)}");
            Debug.Log($"REPLACEMENT: {replacementGuid} - {replacementLocalId} - {AssetDatabase.GUIDToAssetPath(replacementGuid)}");
            Debug.Log($"USAGE: {userPath}");

            var originalAssetRef    = AssetRef.New(originalLocalId, originalGuid);
            var replacementAssetRef = AssetRef.New(replacementLocalId, replacementGuid);

            var sourceFile = File.ReadAllText(userPath);
            var targetFile = ReplaceDependencyInPlace(sourceFile, originalAssetRef, replacementAssetRef);

            File.WriteAllText(userPath, targetFile);
        }
        public static string ReplaceDependencyInPlace(string fileContent, AssetRef original, AssetRef replacement)
        {
            var regexp = CreateRegexp();

            return(regexp.Replace(fileContent, match =>
            {
                var tuple = ExtractFromMatch(match);
                if (!original.Equals(tuple))
                {
                    return match.Value;
                }
                else
                {
                    return $"{match.Groups[1]}{replacement.fileId}{match.Groups[3]}{replacement.guid}{match.Groups[5]}";
                }
            }));
        }
 protected bool Equals(AssetRef other)
 {
     return(fileId == other.fileId && string.Equals(guid, other.guid, StringComparison.InvariantCulture));
 }