DependencyBuilderData.cs 3.4 KB

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