protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint) { var hierarchy = asset.Hierarchy; var entities = (DynamicYamlArray)hierarchy.Parts; foreach (dynamic entityDesign in entities) { var entity = entityDesign.Entity; foreach (var component in entity.Components) { var componentTag = component.Node.Tag; if (componentTag == "!CharacterComponent") { var rads = component.MaxSlope; var angle = new DynamicYamlMapping(new YamlMappingNode()); angle.AddChild("Radians", rads); component.MaxSlope = angle; } } } }
protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint) { // Replace ComputeCurveSamplerVector4 with ComputeCurveSamplerColor4. // Replace ComputeAnimationCurveVector4 with ComputeAnimationCurveColor4. // Replace Vector4 with Color4. Action<dynamic> updateSampler = sampler => { if (sampler == null || sampler.Node.Tag != "!ComputeCurveSamplerVector4") return; sampler.Node.Tag = "!ComputeCurveSamplerColor4"; var curve = sampler.Curve; curve.Node.Tag = "!ComputeAnimationCurveColor4"; foreach (var kf in curve.KeyFrames) { var colorValue = new DynamicYamlMapping(new YamlMappingNode()); colorValue.AddChild("R", kf.Value.X); colorValue.AddChild("G", kf.Value.Y); colorValue.AddChild("B", kf.Value.Z); colorValue.AddChild("A", kf.Value.W); kf.Value = colorValue; } }; var hierarchy = asset.Hierarchy; var entities = hierarchy.Entities; foreach (var entityAndDesign in entities) { var entity = entityAndDesign.Entity; foreach (var component in entity.Components) { var componentTag = component.Node.Tag; if (componentTag != "!ParticleSystemComponent") continue; var particleSystem = component.ParticleSystem; if (particleSystem == null) continue; foreach (var emitter in particleSystem.Emitters) { // Updaters foreach (var updater in emitter.Updaters) { var updaterTag = updater.Node.Tag; if (updaterTag != "!UpdaterColorOverTime") continue; // Update the samplers updateSampler(updater.SamplerMain); updateSampler(updater.SamplerOptional); } } } } }
protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint) { var hierarchy = asset.Hierarchy; var entities = (DynamicYamlArray)hierarchy.Entities; foreach (dynamic entityAndDesign in entities) { var entity = entityAndDesign.Entity; foreach (var component in entity.Components) { var componentTag = component.Node.Tag; if (componentTag == "!ParticleSystemComponent") { dynamic particleSystem = component.ParticleSystem; if (particleSystem != null) { foreach (dynamic emitter in particleSystem.Emitters) { // Lifetime changed from: float (ParticleMinLifetime), float (ParticleMaxLifetime) -> Vector2 (ParticleLifetime) dynamic lifetime = new DynamicYamlMapping(new YamlMappingNode()); lifetime.AddChild("X", emitter.ParticleMinLifetime); lifetime.AddChild("Y", emitter.ParticleMaxLifetime); emitter.AddChild("ParticleLifetime", lifetime); emitter.RemoveChild("ParticleMinLifetime"); emitter.RemoveChild("ParticleMaxLifetime"); // Initializers foreach (dynamic initializer in emitter.Initializers) { var initializerTag = initializer.Node.Tag; if (initializerTag == "!InitialRotationSeed") { dynamic angle = new DynamicYamlMapping(new YamlMappingNode()); angle.AddChild("X", initializer.AngularRotationMin); angle.AddChild("Y", initializer.AngularRotationMax); initializer.AddChild("AngularRotation", angle); initializer.RemoveChild("AngularRotationMin"); initializer.RemoveChild("AngularRotationMax"); } } // Updaters foreach (dynamic updater in emitter.Updaters) { var updaterTag = updater.Node.Tag; if (updaterTag == "!UpdaterCollider") { var isSolid = (bool)updater.IsSolid; updater.AddChild("IsHollow", !isSolid); updater.RemoveChild("IsSolid"); } } } } } } } }
protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint) { dynamic newSource = new DynamicYamlMapping(new YamlMappingNode()); var assetName = (asset.FontName != null) ? (string)asset.FontName : null; var assetSource = (asset.Source != null) ? (string)asset.Source : null; // First check if the asset has a valid source if (assetSource != null && !assetSource.IsNullOrEmpty() && !assetSource.Equals("null")) { newSource.Node.Tag = "!FileFontProvider"; newSource.AddChild("Source", assetSource); } // Only if the asset doesn't have a valid source can it be a system font else if (assetName != null && !assetName.IsNullOrEmpty() && !assetName.Equals("null")) { newSource.Node.Tag = "!SystemFontProvider"; newSource.AddChild("FontName", assetName); if (asset.Style != null) { newSource.AddChild("Style", asset.Style); } } asset.RemoveChild("FontName"); asset.RemoveChild("Source"); asset.RemoveChild("Style"); asset.AddChild("FontSource", newSource); if (asset.FontType != null) { var fontType = (string)asset.FontType; asset.RemoveChild("FontType"); dynamic newType = new DynamicYamlMapping(new YamlMappingNode()); if (fontType.Equals("Dynamic")) { newType.Node.Tag = "!RuntimeRasterizedSpriteFontType"; if (asset.Size != null) newType.AddChild("Size", asset.Size); if (asset.AntiAlias != null) newType.AddChild("AntiAlias", asset.AntiAlias); } else if (fontType.Equals("SDF")) { newType.Node.Tag = "!SignedDistanceFieldSpriteFontType"; if (asset.Size != null) newType.AddChild("Size", asset.Size); if (asset.CharacterSet != null) newType.AddChild("CharacterSet", asset.CharacterSet); if (asset.CharacterRegions != null) newType.AddChild("CharacterRegions", asset.CharacterRegions); } else { newType.Node.Tag = "!OfflineRasterizedSpriteFontType"; if (asset.Size != null) newType.AddChild("Size", asset.Size); if (asset.CharacterSet != null) newType.AddChild("CharacterSet", asset.CharacterSet); if (asset.CharacterRegions != null) newType.AddChild("CharacterRegions", asset.CharacterRegions); if (asset.AntiAlias != null) newType.AddChild("AntiAlias", asset.AntiAlias); if (asset.IsPremultiplied != null) newType.AddChild("IsPremultiplied", asset.IsPremultiplied); } asset.AddChild("FontType", newType); } asset.RemoveChild("IsPremultiplied"); asset.RemoveChild("AntiAlias"); asset.RemoveChild("UseKerning"); asset.RemoveChild("Size"); asset.RemoveChild("CharacterSet"); asset.RemoveChild("CharacterRegions"); }
protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint) { // SerializedVersion format changed during renaming upgrade. However, before this was merged back in master, some asset upgrader still with older version numbers were developed. var proceduralType = asset.Type; if (proceduralType.Node.Tag == "!ConeProceduralModel" && currentVersion != PackageVersion.Parse("0.0.6")) { if (proceduralType.LocalOffset == null) { dynamic offset = new DynamicYamlMapping(new YamlMappingNode()); offset.AddChild("X", 0.0f); offset.AddChild("Y", 0.5f); offset.AddChild("Z", 0.0f); proceduralType.AddChild("LocalOffset", offset); } } }