Пример #1
0
            public static AssetMetadata Add(string path, AssetMetadata metadata)
            {
                path = path.Replace('\\', '/');

                if (metadata.AssetType == null)
                {
                    path = GuessType(path, out metadata.AssetType, out metadata.AssetFormat);
                }

                metadata.PathRelative = path;

                // We want our new mapping to replace the previous one, but need to replace the previous one in the shadow structure.
                AssetMetadata metadataPrev;

                if (!Map.TryGetValue(path, out metadataPrev))
                {
                    metadataPrev = null;
                }

                // Hardcoded case: Handle dialog .txts separately.
                if (metadata.AssetType == typeof(AssetTypeDialog))
                {
                    // Store multiple AssetMetadatas in a list per path.
                    List <AssetMetadata> dialogs;
                    if (!MapDialogs.TryGetValue(path, out dialogs))
                    {
                        dialogs          = new List <AssetMetadata>();
                        MapDialogs[path] = dialogs;
                    }
                    dialogs.Add(metadata);
                }
                // Hardcoded case: Handle maps separately.
                else if (metadata.AssetType == typeof(AssetTypeMap))
                {
                    // Store all maps in a single shared list.
                    // Note that we only store the last added item.
                    int index = ListMaps.FindIndex(other => other.PathRelative == metadata.PathRelative);
                    if (index == -1)
                    {
                        index = ListMaps.Count;
                    }
                    ListMaps.Insert(index, metadata);
                    // We also store the metadata as usual.
                    Map[path] = metadata;
                }
                // Hardcoded case: Handle directories separately.
                else if (metadata.AssetType == typeof(AssetTypeDirectory))
                {
                    MapDirs[path] = metadata;
                }
                else
                {
                    Map[path] = metadata;
                }

                // If we're not already the highest level shadow "node"...
                if (path != "")
                {
                    // Add directories automatically.
                    string        pathDir = Path.GetDirectoryName(path).Replace('\\', '/');
                    AssetMetadata metadataDir;
                    if (!MapDirs.TryGetValue(pathDir, out metadataDir))
                    {
                        metadataDir = new AssetMetadata(pathDir)
                        {
                            Source    = AssetMetadata.SourceType.Meta,
                            AssetType = typeof(AssetTypeDirectory)
                        };
                        Add(pathDir, metadataDir);
                    }
                    // If a previous mapping exists, replace it in the shadow structure.
                    int metadataPrevIndex = metadataDir.Children.IndexOf(metadataPrev);
                    if (metadataPrevIndex != -1)
                    {
                        metadataDir.Children[metadataPrevIndex] = metadata;
                    }
                    else
                    {
                        metadataDir.Children.Add(metadata);
                    }
                }

                return(metadata);
            }