コード例 #1
0
ファイル: AssetUpgraderBase.cs プロジェクト: cg123/xenko
        public void Upgrade(AssetMigrationContext context, string dependencyName, PackageVersion currentVersion, PackageVersion targetVersion, YamlMappingNode yamlAssetNode, PackageLoadingAssetFile assetFile)
        {
            dynamic asset = new DynamicYamlMapping(yamlAssetNode);

            // upgrade the asset
            var baseBranch = asset[Asset.BaseProperty];
            var basePartsBranch = asset[Asset.BasePartsProperty] as DynamicYamlArray;

            // Detect in what kind of override context we are
            var overrideHint = (baseBranch != null || (basePartsBranch != null && basePartsBranch.Node.Children.Count > 0))
                ? OverrideUpgraderHint.Derived
                : OverrideUpgraderHint.Unknown;

            // Upgrade the asset
            UpgradeAsset(context, currentVersion, targetVersion, asset, assetFile, overrideHint);
            SetSerializableVersion(asset, dependencyName, targetVersion);

            // Upgrade its base
            if (baseBranch != null)
            {
                UpgradeBase(context, dependencyName, currentVersion, targetVersion, baseBranch, assetFile);
            }

            // Upgrade base parts
            if (basePartsBranch != null)
            {
                foreach (dynamic assetBase in basePartsBranch)
                {
                    UpgradeBase(context, dependencyName, currentVersion, targetVersion, assetBase, assetFile);
                }
            }
        }
コード例 #2
0
ファイル: AssetUpgraderBase.cs プロジェクト: psowinski/xenko
        public void Upgrade(AssetMigrationContext context, string dependencyName, PackageVersion currentVersion, PackageVersion targetVersion, YamlMappingNode yamlAssetNode, PackageLoadingAssetFile assetFile)
        {
            dynamic asset = new DynamicYamlMapping(yamlAssetNode);

            // upgrade the asset
            UpgradeAsset(context, currentVersion, targetVersion, asset, assetFile);
            SetSerializableVersion(asset, dependencyName, targetVersion);

            // upgrade its base
            var baseBranch = asset[Asset.BaseProperty];
            if (baseBranch != null)
            {
                UpgradeBase(context, dependencyName, currentVersion, targetVersion, baseBranch, assetFile);
            }

            // upgrade base parts
            var basePartsBranch = asset[Asset.BasePartsProperty] as DynamicYamlArray;
            if (basePartsBranch != null)
            {
                foreach (dynamic assetBase in basePartsBranch)
                {
                    UpgradeBase(context, dependencyName, currentVersion, targetVersion, assetBase, assetFile);
                }
            }
        }
コード例 #3
0
ファイル: SceneAsset.cs プロジェクト: Windaloo/paradox
            public void Upgrade(int currentVersion, int targetVersion, ILogger log, YamlMappingNode yamlAssetNode)
            {
                dynamic asset = new DynamicYamlMapping(yamlAssetNode);
                var baseBranch = asset["~Base"];
                if (baseBranch != null)
                    asset["~Base"] = DynamicYamlEmpty.Default;

                SetSerializableVersion(asset, targetVersion);
            }
コード例 #4
0
        public static Version GetPackageVersion(string fullPath)
        {
            try
            {
                foreach (var packageFullPath in EnumeratePackageFullPaths(fullPath))
                {
                    // Load the package as a Yaml dynamic node, so that we can check Xenko version from dependencies
                    var input = new StringReader(File.ReadAllText(packageFullPath));
                    var yamlStream = new YamlStream();
                    yamlStream.Load(input);
                    dynamic yamlRootNode = new DynamicYamlMapping((YamlMappingNode)yamlStream.Documents[0].RootNode);

                    SemanticVersion dependencyVersion = null;

                    foreach (var dependency in yamlRootNode.Meta.Dependencies)
                    {
                        // Support paradox legacy projects
                        if ((string)dependency.Name == "Xenko" || (string)dependency.Name == "Paradox")
                        {
                            dependencyVersion = new SemanticVersion((string)dependency.Version);

                            // Paradox 1.1 was having incorrect version set (1.0), read it from .props file
                            if (dependencyVersion.Version.Major == 1 && dependencyVersion.Version.Minor == 0)
                            {
                                var propsFilePath = Path.Combine(Path.GetDirectoryName(packageFullPath) ?? "", Path.GetFileNameWithoutExtension(packageFullPath) + ".props");
                                if (File.Exists(propsFilePath))
                                {
                                    using (XmlReader propsReader = XmlReader.Create(propsFilePath))
                                    {
                                        propsReader.MoveToContent();
                                        if (propsReader.ReadToDescendant("SiliconStudioPackageParadoxVersion"))
                                        {
                                            if (propsReader.Read())
                                            {
                                                dependencyVersion = new SemanticVersion(propsReader.Value);
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }

                    // Stop after first version
                    if (dependencyVersion != null)
                    {
                        return new Version(dependencyVersion.Version.Major, dependencyVersion.Version.Minor);
                    }
                }
            }
            catch (Exception)
            {
            }

            return null;
        }
コード例 #5
0
            public void Upgrade(AssetMigrationContext context, string dependencyName, PackageVersion currentVersion, PackageVersion targetVersion, YamlMappingNode yamlAssetNode, PackageLoadingAssetFile assetFile)
            {
                dynamic asset = new DynamicYamlMapping(yamlAssetNode);
                var baseBranch = asset[Asset.BaseProperty];
                if (baseBranch != null)
                    asset[BaseProperty] = DynamicYamlEmpty.Default;

                AssetUpgraderBase.SetSerializableVersion(asset, dependencyName, targetVersion);
            }
コード例 #6
0
ファイル: SceneAsset.cs プロジェクト: releed/paradox
            public void Upgrade(AssetMigrationContext context, int currentVersion, int targetVersion, YamlMappingNode yamlAssetNode, PackageLoadingAssetFile assetFile)
            {
                dynamic asset = new DynamicYamlMapping(yamlAssetNode);
                var baseBranch = asset["~Base"];
                if (baseBranch != null)
                    asset["~Base"] = DynamicYamlEmpty.Default;

                SetSerializableVersion(asset, targetVersion);
            }
コード例 #7
0
                public void Upgrade(int currentVersion, int targetVersion, ILogger log, YamlMappingNode yamlAssetNode)
                {
                    dynamic asset = new DynamicYamlMapping(yamlAssetNode);

                    asset.SerializedVersion = targetVersion;

                    // Move Test4 to Test5
                    asset.Test5 = asset.Test4;
                    asset.Test4 = DynamicYamlEmpty.Default;
                }
コード例 #8
0
                public void Upgrade(int currentVersion, int targetVersion, ILogger log, YamlMappingNode yamlAssetNode)
                {
                    dynamic asset = new DynamicYamlMapping(yamlAssetNode);

                    asset.SerializedVersion = AssetRegistry.GetCurrentFormatVersion(typeof(MyUpgradedAsset));

                    // Move Test1 to Test2
                    asset.Test2 = asset.Test1;
                    asset.Test1 = DynamicYamlEmpty.Default;
                }
コード例 #9
0
ファイル: TestAssetUpgrade.cs プロジェクト: cg123/xenko
                public void Upgrade(AssetMigrationContext context, string dependencyName, PackageVersion currentVersion, PackageVersion targetVersion, YamlMappingNode yamlAssetNode, PackageLoadingAssetFile assetFile)
                {
                    dynamic asset = new DynamicYamlMapping(yamlAssetNode);

                    // Note: seems little bit strange, but original test was not using targetVersion...
                    var serializedVersion = AssetRegistry.GetCurrentFormatVersions(typeof(MyUpgradedAsset))[dependencyName];
                    AssetUpgraderBase.SetSerializableVersion(asset, dependencyName, serializedVersion);

                    // Move Test1 to Test2
                    asset.Test2 = asset.Test1;
                    asset.Test1 = DynamicYamlEmpty.Default;
                }
コード例 #10
0
        public void Upgrade(int currentVersion, int targetVersion, ILogger log, YamlMappingNode yamlAssetNode)
        {
            dynamic asset = new DynamicYamlMapping(yamlAssetNode);

            // upgrade the asset
            UpgradeAsset(currentVersion, targetVersion, log, asset);
            SetSerializableVersion(asset, targetVersion);
            // upgrade its base
            var baseBranch = asset["~Base"];
            if (baseBranch != null)
            {
                var baseAsset = baseBranch["Asset"];
                if (baseAsset != null)
                    UpgradeAsset(currentVersion, targetVersion, log, baseAsset);
                SetSerializableVersion(baseAsset, targetVersion);
            }
        }
コード例 #11
0
ファイル: AssetUpgraderBase.cs プロジェクト: releed/paradox
        public void Upgrade(AssetMigrationContext context, int currentVersion, int targetVersion, YamlMappingNode yamlAssetNode, PackageLoadingAssetFile assetFile)
        {
            dynamic asset = new DynamicYamlMapping(yamlAssetNode);

            // upgrade the asset
            UpgradeAsset(context, currentVersion, targetVersion, asset, assetFile);
            SetSerializableVersion(asset, targetVersion);
            // upgrade its base
            var baseBranch = asset["~Base"];
            if (baseBranch != null)
            {
                var baseAsset = baseBranch["Asset"];
                if (baseAsset != null)
                    UpgradeAsset(context, currentVersion, targetVersion, baseAsset, assetFile);
                SetSerializableVersion(baseAsset, targetVersion);
            }
        }
コード例 #12
0
ファイル: TestAssetUpgrade.cs プロジェクト: cg123/xenko
                public void Upgrade(AssetMigrationContext context, string dependencyName, PackageVersion currentVersion, PackageVersion targetVersion, YamlMappingNode yamlAssetNode, PackageLoadingAssetFile assetFile)
                {
                    dynamic asset = new DynamicYamlMapping(yamlAssetNode);

                    AssetUpgraderBase.SetSerializableVersion(asset, dependencyName, targetVersion);

                    // Move Test2 to Test4
                    if (currentVersion == PackageVersion.Parse("0.0.2"))
                    {
                        asset.Test4 = asset.Test2;
                        asset.Test2 = DynamicYamlEmpty.Default;
                    }
                    // Move Test3 to Test4
                    else if (currentVersion == PackageVersion.Parse("0.0.3"))
                    {
                        asset.Test4 = asset.Test3;
                        asset.Test3 = DynamicYamlEmpty.Default;
                    }
                }
コード例 #13
0
                public void Upgrade(int currentVersion, int targetVersion, ILogger log, YamlMappingNode yamlAssetNode)
                {
                    dynamic asset = new DynamicYamlMapping(yamlAssetNode);

                    asset.SerializedVersion = targetVersion;

                    // Move Test2 to Test4
                    if (currentVersion == 2)
                    {
                        asset.Test4 = asset.Test2;
                        asset.Test2 = DynamicYamlEmpty.Default;
                    }
                    // Move Test3 to Test4
                    else if (currentVersion == 3)
                    {
                        asset.Test4 = asset.Test3;
                        asset.Test3 = DynamicYamlEmpty.Default;
                    }
                }
コード例 #14
0
        public static T ConvertTo <T>(DynamicYamlMapping yamObject)
        {
            using (var memoryStream = new MemoryStream())
            {
                // convert Yaml nodes to string
                using (var streamWriter = new StreamWriter(memoryStream))
                {
                    var yamlStream = new YamlStream {
                        new YamlDocument(yamObject.Node)
                    };
                    yamlStream.Save(streamWriter, true, YamlSerializer.GetSerializerSettings().PreferredIndent);

                    streamWriter.Flush();
                    memoryStream.Position = 0;

                    // convert string to object
                    return((T)YamlSerializer.Deserialize(memoryStream, typeof(T), null));
                }
            }
        }
コード例 #15
0
 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);
         }
     }
 }
コード例 #16
0
ファイル: SceneAsset.cs プロジェクト: releed/paradox
            protected override void UpgradeAsset(AssetMigrationContext context, int currentVersion, int targetVersion, dynamic asset, PackageLoadingAssetFile assetFile)
            {
                var entities = asset.Hierarchy.Entities;
                var designEntities = new YamlSequenceNode();
                asset.Hierarchy.Entities = designEntities;

                foreach (var entity in entities)
                {
                    var designEntity = new YamlMappingNode();
                    dynamic dynamicDesignEntity = new DynamicYamlMapping(designEntity);
                    dynamicDesignEntity.Entity = entity;
                    designEntities.Add(designEntity);
                }
            }
コード例 #17
0
            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)
                    {
                        try
                        {
                            var componentTag = component.Value.Node.Tag;
                            if (componentTag == "!ModelComponent")
                            {
                                var materials = component.Value.Materials;
                                var node = ((DynamicYamlMapping)materials).Node;
                                var i = -1;
                                foreach (var material in node.Children.ToList())
                                {
                                    ++i;
                                    node.Children.Remove(material.Key);
                                    if (((YamlScalarNode)material.Value).Value == "null")
                                        continue;

                                    node.Children.Add(new YamlScalarNode(((YamlScalarNode)material.Key).Value + '~' + i), material.Value);
                                }
                            }
                        }
                        catch (Exception)
                        {
                            try
                            {
                                // Component list serialized with the old version (as a sequence with ~Id in each item)
                                var componentTag = component.Node.Tag;
                                if (componentTag == "!ModelComponent")
                                {
                                    var materials = component.Materials;
                                    var node = ((DynamicYamlArray)materials).Node;
                                    var i = -1;
                                    dynamic newMaterial = new DynamicYamlMapping(new YamlMappingNode());
                                    foreach (var material in node.Children.ToList())
                                    {
                                        ++i;
                                        var reference = (YamlScalarNode)material;
                                        if (reference.Value == "null") // Skip null
                                            continue;

                                        UFile location;
                                        Guid referenceId;
                                        AssetId assetReference;
                                        if (AssetReference.TryParse(reference.Value, out assetReference, out location, out referenceId) && referenceId != Guid.Empty)
                                        {
                                            var itemId = new ItemId(referenceId.ToByteArray());
                                            newMaterial[itemId + "~" + i] = new AssetReference(assetReference, location);
                                        }
                                    }
                                    component["Materials"] = newMaterial;
                                }
                            }
                            catch (Exception e)
                            {
                                e.Ignore();
                            }
                        }
                    }
                }

            }
コード例 #18
0
 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;
             }
         }
     }
 }
コード例 #19
0
            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);
                            }
                        }
                    }
                }
            }
コード例 #20
0
            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");
            }
コード例 #21
0
ファイル: EntityAsset.cs プロジェクト: robterrell/paradox
            public void Upgrade(int currentVersion, int targetVersion, ILogger log, YamlMappingNode yamlAssetNode)
            {
                dynamic asset = new DynamicYamlMapping(yamlAssetNode);

                // Get the EntityData, and generate an Id
                var oldEntityData = asset.Data;
                oldEntityData.Id = Guid.NewGuid().ToString().ToLowerInvariant();

                // Create a new EntityDataHierarchy object
                asset.Hierarchy = new YamlMappingNode();
                asset.Hierarchy.Entities = new YamlSequenceNode();
                asset.Hierarchy.Entities.Add(oldEntityData);

                asset["~Base"] = DynamicYamlEmpty.Default;

                // Bump asset version -- make sure it is stored right after Id
                asset.SerializedVersion = AssetFormatVersion;
                asset.MoveChild("SerializedVersion", asset.IndexOf("Id") + 1);

                // Currently not final, so enable at your own risk
                throw new NotImplementedException();
            }
コード例 #22
0
ファイル: TestAssetUpgrade.cs プロジェクト: cg123/xenko
                public void Upgrade(AssetMigrationContext context, string dependencyName, PackageVersion currentVersion, PackageVersion targetVersion, YamlMappingNode yamlAssetNode, PackageLoadingAssetFile assetFile)
                {
                    dynamic asset = new DynamicYamlMapping(yamlAssetNode);

                    AssetUpgraderBase.SetSerializableVersion(asset, dependencyName, targetVersion);

                    // Move Test4 to Test5
                    asset.Test5 = asset.Test4;
                    asset.Test4 = DynamicYamlEmpty.Default;
                }
コード例 #23
0
ファイル: SceneAsset.cs プロジェクト: RxGamesLtd/paradox
            protected override void UpgradeAsset(int currentVersion, int targetVersion, ILogger log, dynamic asset)
            {
                var entities = asset.Hierarchy.Entities;
                var designEntities = new YamlSequenceNode();
                asset.Hierarchy.Entities = designEntities;

                foreach (var entity in entities)
                {
                    var designEntity = new YamlMappingNode();
                    dynamic dynamicDesignEntity = new DynamicYamlMapping(designEntity);
                    dynamicDesignEntity.Entity = entity;
                    designEntities.Add(designEntity);
                }
            }
コード例 #24
0
            private DynamicYamlMapping FixEntityComponentReferences(dynamic item, Dictionary<string, Dictionary<string, Tuple<string, dynamic>>> maps)
            {
                // Go recursively into an object to fix anykind of EntityComponent references

                var mapping = item as DynamicYamlMapping;
                var array = item as DynamicYamlArray;

                // We have an EntityComponentLink, transform it to the new format
                // Entity: {Id: guid}             =>    Entity: {Id: guid}
                // Component: Component.Key       =>    Id: guid
                if (mapping != null && item.Entity is DynamicYamlMapping && item.Component != null && item.Entity.Id != null && mapping.Node.Children.Count == 2)
                {
                    var entity = item.Entity;
                    var entityId = (string)entity.Id;
                    var componentKey = (string)item.Component;
                    var newComponentReference = new DynamicYamlMapping(new YamlMappingNode());
                    var newComponentDynamic = (dynamic)newComponentReference;

                    newComponentDynamic.Entity = entity;

                    string componentId = Guid.Empty.ToString();

                    Dictionary<string, Tuple<string, dynamic>> componentInfo;
                    if (maps.TryGetValue(entityId, out componentInfo))
                    {
                        var componentTypeName = GetComponentNameFromKey(componentKey);

                        Tuple<string, dynamic> newIdAndComponent;
                        if (componentInfo.TryGetValue(componentTypeName, out newIdAndComponent))
                        {
                            componentId = newIdAndComponent.Item1;
                        }

                        newComponentReference.Node.Tag = "!" + componentTypeName;
                        newComponentDynamic.Id = componentId;

                        return newComponentReference;
                    }
                    return null;
                }
                else if (mapping != null)
                {
                    foreach (var subKeyValue in mapping.Cast<KeyValuePair<dynamic, dynamic>>())
                    {
                        var newRef = FixEntityComponentReferences(subKeyValue.Value, maps);
                        if (newRef != null)
                        {
                            item[subKeyValue.Key] = newRef;
                        }
                    }
                }
                else if (array != null)
                {
                    var elements = array.Cast<dynamic>().ToList();
                    for (int i = 0; i < elements.Count; i++)
                    {
                        var arrayItem = elements[i];
                        var newRef = FixEntityComponentReferences(arrayItem, maps);
                        if (newRef != null)
                        {
                            item[i] = newRef;
                        }
                    }
                }

                // Otherwise we are not modifying anything
                return null;
            }
コード例 #25
0
            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");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }