DependencyBuilderData.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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(ScriptableObjectMetadata)
  22. };
  23. public static int GetIndexFromType(Type type) => Types.IndexOf(type);
  24. public static Type GetTypeFromIndex(int index) => (index >= 0 && index < Types.Count) ? Types[index] : null;
  25. }
  26. public class RoslynSetupData
  27. {
  28. public string[] SourceFiles { get; set; }
  29. public string[] References { get; set; }
  30. public string[] PreprocessorSymbols { get; set; }
  31. public Dictionary<string, string> TypeToGuidMap { get; set; }
  32. public List<string> SystemTypePrefixes { get; set; }
  33. }
  34. /// <summary>
  35. /// A serializable wrapper to store the concrete type and JSON data of our
  36. /// abstract AssetMetadata objects. This allows for correct deserialization.
  37. /// </summary>
  38. [Serializable]
  39. public class MetadataWrapper
  40. {
  41. public int AssetTypeIndex { get; set; }
  42. public string JsonData { get; set; }
  43. }
  44. /// <summary>
  45. /// The base class for all asset metadata. It is now the primary serializable object
  46. /// and contains the list of direct dependencies for the asset.
  47. /// </summary>
  48. [Serializable]
  49. public abstract class AssetMetadata
  50. {
  51. public string Guid { get; set; }
  52. public List<string> DependencyGuids { get; set; } = new();
  53. }
  54. /// <summary>
  55. /// Metadata for a C# script. Its DependencyGuids will be populated by Roslyn analysis.
  56. /// </summary>
  57. [Serializable]
  58. public class ScriptMetadata : AssetMetadata
  59. {
  60. [JsonIgnore]
  61. public string FullPath { get; set; }
  62. }
  63. /// <summary>
  64. /// Metadata for a Prefab. Its DependencyGuids will contain the GUIDs of all scripts attached as components.
  65. /// </summary>
  66. [Serializable]
  67. public class PrefabMetadata : AssetMetadata { }
  68. /// <summary>
  69. /// Metadata for a ScriptableObject. Its DependencyGuids will contain the GUID of its backing script.
  70. /// </summary>
  71. [Serializable]
  72. public class ScriptableObjectMetadata : AssetMetadata { }
  73. }
  74. }