public FileMetadata(string filename) {
this.filename = filename;
filenameCanonical = filename;
var filenameComponents = new FilenameComponents(filename);
// Parse metadata from the filename.
string[] tokens =
filenameComponents.basenameNoExtension.Split(
FILENAME_TOKEN_SEPARATOR);
if (tokens.Length > 1) {
filenameComponents.basenameNoExtension = tokens[0];
for (int i = 1; i < tokens.Length; ++i) {
string token = tokens[i];
if (token == FILENAME_TOKEN_MANIFEST) {
isManifest = true;
} else if (token.StartsWith(TOKEN_TARGETS)) {
targets = ParseTargets(token);
} else if (token.StartsWith(TOKEN_VERSION)) {
versionString = ParseVersion(token);
}
}
}
// Parse metadata from asset labels if it hasn't been specified in
// the filename.
AssetImporter importer = GetAssetImporter();
if (importer != null) {
foreach (string label in AssetDatabase.GetLabels(importer)) {
// Labels are converted to title case in the asset database
// so convert to lower case before parsing.
string lowerLabel = label.ToLower();
if (lowerLabel.StartsWith(LABEL_PREFIX)) {
string token =
lowerLabel.Substring(LABEL_PREFIX.Length);
if (token.StartsWith(TOKEN_TARGETS)) {
if (targets == null) {
targets = ParseTargets(token);
}
} else if (token.StartsWith(TOKEN_VERSION)) {
if (String.IsNullOrEmpty(versionString)) {
versionString = ParseVersion(token);
}
} else if (token.Equals(FILENAME_TOKEN_MANIFEST)) {
isManifest = true;
}
}
}
}
// On Windows the AssetDatabase converts native path separators
// used by the .NET framework '\' to *nix style '/' such that
// System.IO.Path generated paths will not match those looked up
// in the asset database. So we convert the output of Path.Combine
// here to use *nix style paths so that it's possible to perform
// simple string comparisons to check for path equality.
filenameCanonical = Path.Combine(
filenameComponents.directory,
filenameComponents.basenameNoExtension +
filenameComponents.extension).Replace('\\', '/');
UpdateAssetLabels();
}