DependencyBuilderData.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using Newtonsoft.Json;
  3. using System.Collections.Generic;
  4. namespace IntelligentProjectAnalyzer.Editor
  5. {
  6. /// <summary>
  7. /// Contains all the data structures and models used throughout the dependency build process.
  8. /// </summary>
  9. public static class DependencyBuilderData
  10. {
  11. /// <summary>
  12. /// A helper class to map concrete AssetMetadata types to a stable integer index.
  13. /// </summary>
  14. public static class MetadataTypeHelper
  15. {
  16. // This list defines the stable mapping. Order is important.
  17. private static readonly List<Type> Types = new()
  18. {
  19. typeof(ScriptMetadata),
  20. typeof(PrefabMetadata),
  21. typeof(SceneMetadata),
  22. typeof(ScriptableObjectMetadata),
  23. };
  24. public static int GetIndexFromType(Type type) => Types.IndexOf(type);
  25. public static Type GetTypeFromIndex(int index) => (index >= 0 && index < Types.Count) ? Types[index] : null;
  26. }
  27. public class RoslynSetupData
  28. {
  29. public string[] SourceFiles { get; set; }
  30. public string[] References { get; set; }
  31. public string[] PreprocessorSymbols { get; set; }
  32. public Dictionary<string, string> TypeToGuidMap { get; set; }
  33. public List<string> SystemTypePrefixes { get; set; }
  34. }
  35. /// <summary>
  36. /// A serializable wrapper to store the concrete type and JSON data of our
  37. /// abstract AssetMetadata objects. This allows for correct deserialization.
  38. /// </summary>
  39. [Serializable]
  40. public class MetadataWrapper
  41. {
  42. public int AssetTypeIndex { get; set; }
  43. public string JsonData { get; set; }
  44. }
  45. /// <summary>
  46. /// The base class for all asset metadata. It is now the primary serializable object
  47. /// and contains the list of direct dependencies for the asset.
  48. /// </summary>
  49. [Serializable]
  50. public abstract class AssetMetadata
  51. {
  52. public string Guid { get; set; }
  53. public List<string> DependencyGuids { get; set; } = new();
  54. }
  55. /// <summary>
  56. /// Metadata for a C# script. Its DependencyGuids will be populated by Roslyn analysis.
  57. /// </summary>
  58. [Serializable]
  59. public class ScriptMetadata : AssetMetadata
  60. {
  61. [JsonIgnore]
  62. public string FullPath { get; set; }
  63. }
  64. /// <summary>
  65. /// Metadata for a Prefab. Its DependencyGuids will contain the GUIDs of all scripts attached as components.
  66. /// </summary>
  67. [Serializable]
  68. public class PrefabMetadata : AssetMetadata { }
  69. /// <summary>
  70. /// Metadata for a ScriptableObject. Its DependencyGuids will contain the GUID of its backing script.
  71. /// </summary>
  72. [Serializable]
  73. public class ScriptableObjectMetadata : AssetMetadata { }
  74. /// <summary>
  75. /// Metadata for scene.Its DependencyGuids will contain the GUIDs of all scripts attached as components.
  76. /// </summary>
  77. [Serializable]
  78. public class SceneMetadata : AssetMetadata { }
  79. }
  80. }