diff --git a/Assets/AsmdefGraph/Editor/Scripts/Asmdef.cs b/Assets/AsmdefGraph/Editor/Scripts/Asmdef.cs deleted file mode 100644 index 0aed0b3..0000000 --- a/Assets/AsmdefGraph/Editor/Scripts/Asmdef.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AsmdefGraph.Editor { - public class Asmdef { - public string name; - public string[] references; - public Asmdef() { - name = ""; - references = new string[0]; - } - } -} diff --git a/Assets/AsmdefGraph/Editor/Scripts/AsmdefDependency.cs b/Assets/AsmdefGraph/Editor/Scripts/AsmdefDependency.cs new file mode 100644 index 0000000..d2eec00 --- /dev/null +++ b/Assets/AsmdefGraph/Editor/Scripts/AsmdefDependency.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace AsmdefGraph.Editor { + public class AsmdefDependency { + public string DependsFrom { get; } + public IEnumerable DependsTo { get; } + + public AsmdefDependency(string key, IEnumerable value) { + DependsFrom = key; + DependsTo = value; + } + } +} diff --git a/Assets/AsmdefGraph/Editor/Scripts/Asmdef.cs.meta b/Assets/AsmdefGraph/Editor/Scripts/AsmdefDependency.cs.meta similarity index 83% rename from Assets/AsmdefGraph/Editor/Scripts/Asmdef.cs.meta rename to Assets/AsmdefGraph/Editor/Scripts/AsmdefDependency.cs.meta index 432da14..4e823b1 100644 --- a/Assets/AsmdefGraph/Editor/Scripts/Asmdef.cs.meta +++ b/Assets/AsmdefGraph/Editor/Scripts/AsmdefDependency.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f30f8c38436702248a368db79323d7e8 +guid: de8afe620d6667940a15a8871781c62d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/AsmdefGraph/Editor/Scripts/AsmdefFile.cs b/Assets/AsmdefGraph/Editor/Scripts/AsmdefFile.cs deleted file mode 100644 index d497206..0000000 --- a/Assets/AsmdefGraph/Editor/Scripts/AsmdefFile.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using UnityEditor; -using UnityEngine; - -namespace AsmdefGraph.Editor { - public class AsmdefFile { - public string FilePath { set; get; } - public string Guid { set; get; } - public Asmdef Content { set; get; } - public AsmdefFile() { - FilePath = ""; - Guid = ""; - Content = new Asmdef(); - } - public bool LoadFromPath(string fullPath, string assetPath) { - FilePath = fullPath; - Guid = AssetDatabase.AssetPathToGUID(assetPath); - var json = File.ReadAllText(fullPath); - if (string.IsNullOrEmpty(json)) { - return false; - } - Content = JsonUtility.FromJson(json); - return true; - } - public IEnumerable Guids => - Content.references.Where(x => !string.IsNullOrEmpty(x)).Select(x => x.Replace("GUID:", "")); - } -} diff --git a/Assets/AsmdefGraph/Editor/Scripts/AsmdefFile.cs.meta b/Assets/AsmdefGraph/Editor/Scripts/AsmdefFile.cs.meta deleted file mode 100644 index d8f236a..0000000 --- a/Assets/AsmdefGraph/Editor/Scripts/AsmdefFile.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ad4bbaa3b7aa9cd439fe68c352f6868c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/AsmdefGraph/Editor/Scripts/AsmdefGraphEditorWindow.cs b/Assets/AsmdefGraph/Editor/Scripts/AsmdefGraphEditorWindow.cs index 2408db4..3e0673e 100644 --- a/Assets/AsmdefGraph/Editor/Scripts/AsmdefGraphEditorWindow.cs +++ b/Assets/AsmdefGraph/Editor/Scripts/AsmdefGraphEditorWindow.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.IO; +using System.Linq; using UnityEditor; +using UnityEditor.Compilation; namespace AsmdefGraph.Editor { public class AsmdefGraphEditorWindow : EditorWindow { @@ -10,19 +12,18 @@ namespace AsmdefGraph.Editor { } void OnEnable() { - var asmdefs = new List(); - var projectPath = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar; - // プロジェクトのasmdefを全検索 - var fullPathes = Directory.EnumerateFiles(projectPath, "*.asmdef", SearchOption.AllDirectories); - // asmdefの内容取得 - foreach (var fullPath in fullPathes) { - var assetPath = fullPath.Replace(projectPath, ""); - var asmdef = new AsmdefFile(); - asmdef.LoadFromPath(fullPath, assetPath); - asmdefs.Add(asmdef); + // .asmdefをすべて取得 + var asmdefs = CompilationPipeline.GetAssemblies(); + var allDependencies = new List(); + foreach (var asmdef in asmdefs) { + allDependencies.Add( + new AsmdefDependency( + asmdef.name, + asmdef.assemblyReferences?.Select(x => x.name) ?? new string[0]) + ); } // viewの作成 - var graphView = new AsmdefGraphView(asmdefs) { + var graphView = new AsmdefGraphView(allDependencies) { style = { flexGrow = 1 } }; rootVisualElement.Add(graphView); diff --git a/Assets/AsmdefGraph/Editor/Scripts/AsmdefGraphView.cs b/Assets/AsmdefGraph/Editor/Scripts/AsmdefGraphView.cs index 94b7901..d878bf5 100644 --- a/Assets/AsmdefGraph/Editor/Scripts/AsmdefGraphView.cs +++ b/Assets/AsmdefGraph/Editor/Scripts/AsmdefGraphView.cs @@ -1,18 +1,37 @@ using System.Collections.Generic; +using System.Linq; using UnityEditor.Experimental.GraphView; using UnityEngine.UIElements; namespace AsmdefGraph.Editor { public class AsmdefGraphView : GraphView { - public AsmdefGraphView(IEnumerable asmdefs) : base() { + public AsmdefGraphView(IEnumerable asmdefs) : base() { // zoom可能に SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); // 背景を黒に Insert(0, new GridBackground()); // ドラッグによる移動可能に this.AddManipulator(new SelectionDragger()); + // ノードの追加 + var asmdefNodeDict = new Dictionary(); foreach (var asmdef in asmdefs) { - AddElement(new AsmdefNode(asmdef.Content.name)); + var node = new AsmdefNode(asmdef.DependsFrom); + AddElement(node); + asmdefNodeDict.Add(node.title, node); + } + // 依存先にラインを追加 + var nodeApapter = new NodeAdapter(); + foreach (var asmdef in asmdefs) { + if (!asmdefNodeDict.TryGetValue(asmdef.DependsFrom, out var fromNode)) { + continue; + } + foreach (var dependents in asmdef.DependsTo) { + if (!asmdefNodeDict.TryGetValue(dependents, out var toNode)) { + continue; + } + var edge = fromNode.OutPort.ConnectTo(toNode.InPort); + contentContainer.Add(edge);// これが無いと線が表示されない + } } } diff --git a/Assets/AsmdefGraph/Editor/Scripts/AsmdefNode.cs b/Assets/AsmdefGraph/Editor/Scripts/AsmdefNode.cs index 720ba3c..dabe3e8 100644 --- a/Assets/AsmdefGraph/Editor/Scripts/AsmdefNode.cs +++ b/Assets/AsmdefGraph/Editor/Scripts/AsmdefNode.cs @@ -2,16 +2,19 @@ namespace AsmdefGraph.Editor { public class AsmdefNode : Node { + public readonly Port InPort; + public readonly Port OutPort; + public AsmdefNode(string nodeName) { title = nodeName; - var inputPort = Port.Create(Orientation.Horizontal, Direction.Input, Port.Capacity.Multi, typeof(Port)); - inputPort.portName = "In"; - inputContainer.Add(inputPort); - - var outputPort = Port.Create(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(Port)); - outputPort.portName = "Out"; - outputContainer.Add(outputPort); + InPort = Port.Create(Orientation.Horizontal, Direction.Input, Port.Capacity.Multi, typeof(Port)); + InPort.portName = "In"; + inputContainer.Add(InPort); + + OutPort = Port.Create(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(Port)); + OutPort.portName = "Out"; + outputContainer.Add(OutPort); } } }