/// Returns a serialized ToolkitBrushDescriptor suitable for inclusion in the Toolkit public static string CreateAndSerialize( BrushDescriptor desc, Guid materialGuid, string assetName, out string meta) { ToolkitBrushDescriptor tkdesc = CreateFrom(desc); string yaml = SerializeToUnityString(tkdesc, assetName, out meta); yaml = ChangeToToolkitScript(yaml); yaml = SetMaterialGuid(yaml, materialGuid); return(yaml); }
// Directly creates some assets in the target tree, and appends other assets // to collectedAssets for later copying. // // Assets which are directly created in the target: // --- asset --- --- .meta guid --- // <target>/Assets/Brushes/Basic/<name>/<name>.mat desc.m_Guid.ToString("N") // <target>/Assets/Brushes/Basic/<name>/<name>.asset Uuid5(desc.m_Guid, 'tbt-asset'), unity-style // // - .mat guids are serialized as .ToString("N") // - Pre-M14 .asset guids are random and generated by Unity (RFC 4122 type 4) // - M14+ .asset guids are generated deterministically (RFC 4122 type 5), and // we copy Unity's wacky serialization format so it's more-feasible to determine // which is which, should we ever need to. But maybe we should bite the bullet // and make them all type 5? (which may annoy a small number of people trying // to upgrade TBT in a pre-existing project because of the .meta change) static void ExportToToolkit_Brush( BrushDescriptor descriptor, string targetDirectory, HashSet <string> collectedAssets) { if (descriptor.name.StartsWith("Pbr")) { Debug.LogFormat("Skipping {0}: we don't know how to handle pbr in TBT yet", descriptor.name); return; } if (descriptor.name.StartsWith("EnvironmentDiffuse")) { Debug.LogFormat("Skipping {0}: we don't need these EnvironmentDiffuse things in TBT", descriptor.name); return; } string containerDirectory = Path.Combine(targetDirectory, GetSubdirForBrush(descriptor)); string assetName = GetCreatedAssetNameForBrush(descriptor); // Create material and store its dependencies string desiredFilename = assetName + ".mat"; string materialFinalPath = containerDirectory + "/" + desiredFilename; string materialAssetPath = AssetDatabase.GetAssetPath(descriptor.Material); collectedAssets.UnionWith(GetDependencies(materialAssetPath, includeRoot: false)); // Steal the brush's TB guid to use as a Unity guid. Guid materialGuid = descriptor.m_Guid; CopyAsset(materialAssetPath, materialFinalPath, adjustName: true); SetFileGuid_Incorrect(materialFinalPath, descriptor.m_Guid); // Create a brush descriptor string targetPath = Path.Combine(containerDirectory, assetName + ".asset"); string meta; string yaml = ToolkitBrushDescriptor.CreateAndSerialize( descriptor, materialGuid, assetName, out meta); File.WriteAllText(targetPath, yaml); string targetMetaPath = targetPath + ".meta"; if (!File.Exists(targetMetaPath)) { Warning("New brush {0}: Uncomment and run BrushManifest.MenuItem_UpdateManifest() in TBT", descriptor.m_DurableName); } else { // Revert spurious timestamp changes var match = Regex.Match(File.ReadAllText(targetMetaPath), @"timeCreated: \d+"); if (match.Success) { meta = Regex.Replace(meta, @"timeCreated: \d+", match.Groups[0].Value); } } File.WriteAllText(targetMetaPath, meta); if (kLegacyBrushGuidToTbtAssetGuidMapping.ContainsKey(descriptor.m_Guid)) { // Legacy: for pre-M14 brushes that were created with random .meta guids SetFileGuid_String(targetPath, kLegacyBrushGuidToTbtAssetGuidMapping[descriptor.m_Guid]); } else { Guid brushAssetGuid = GuidUtils.Uuid5(descriptor.m_Guid, "tbt-asset"); SetFileGuid_Correct(targetPath, brushAssetGuid); } }