From 61df3a4bb2dca3c462ba4f716ab575089549420a Mon Sep 17 00:00:00 2001 From: nakano yosuke Date: Mon, 9 Dec 2019 02:13:50 +0900 Subject: [PATCH] parse asmdef --- Assets/AsmdefGraph/AsmdefGraph.asmdef | 3 -- Assets/AsmdefGraph/AsmdefGraph.asmdef.meta | 7 ----- Assets/AsmdefGraph/Editor/Scripts/Asmdef.cs | 8 +++-- .../AsmdefGraph/Editor/Scripts/AsmdefFile.cs | 30 +++++++++++++++++++ .../Editor/Scripts/AsmdefFile.cs.meta | 11 +++++++ .../Editor/Scripts/AsmdefGraphEditorWindow.cs | 23 ++++++++------ .../Editor/Scripts/AsmdefGraphView.cs | 4 +-- .../Example/AsmdefGraph.Example.asmdef | 18 +++++++++-- .../Fuga/AsmdefGraph.Example.Fuga.asmdef | 19 ++++++++++-- .../Hoge/AsmdefGraph.Example.Hoge.asmdef | 18 +++++++++-- .../Piyo/AsmdefGraph.Example.Piyo.asmdef | 6 +++- 11 files changed, 114 insertions(+), 33 deletions(-) delete mode 100644 Assets/AsmdefGraph/AsmdefGraph.asmdef delete mode 100644 Assets/AsmdefGraph/AsmdefGraph.asmdef.meta create mode 100644 Assets/AsmdefGraph/Editor/Scripts/AsmdefFile.cs create mode 100644 Assets/AsmdefGraph/Editor/Scripts/AsmdefFile.cs.meta diff --git a/Assets/AsmdefGraph/AsmdefGraph.asmdef b/Assets/AsmdefGraph/AsmdefGraph.asmdef deleted file mode 100644 index d70696e..0000000 --- a/Assets/AsmdefGraph/AsmdefGraph.asmdef +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "AsmdefGraph" -} diff --git a/Assets/AsmdefGraph/AsmdefGraph.asmdef.meta b/Assets/AsmdefGraph/AsmdefGraph.asmdef.meta deleted file mode 100644 index 5bbf53c..0000000 --- a/Assets/AsmdefGraph/AsmdefGraph.asmdef.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 6f2ba0cedcb8c3b47a21d0d0a4e78efe -AssemblyDefinitionImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/AsmdefGraph/Editor/Scripts/Asmdef.cs b/Assets/AsmdefGraph/Editor/Scripts/Asmdef.cs index 6c6671f..0aed0b3 100644 --- a/Assets/AsmdefGraph/Editor/Scripts/Asmdef.cs +++ b/Assets/AsmdefGraph/Editor/Scripts/Asmdef.cs @@ -1,6 +1,10 @@ namespace AsmdefGraph.Editor { public class Asmdef { - public string Name; - public string[] Asmdefs; + public string name; + public string[] references; + public Asmdef() { + name = ""; + references = new string[0]; + } } } diff --git a/Assets/AsmdefGraph/Editor/Scripts/AsmdefFile.cs b/Assets/AsmdefGraph/Editor/Scripts/AsmdefFile.cs new file mode 100644 index 0000000..d497206 --- /dev/null +++ b/Assets/AsmdefGraph/Editor/Scripts/AsmdefFile.cs @@ -0,0 +1,30 @@ +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 new file mode 100644 index 0000000..d8f236a --- /dev/null +++ b/Assets/AsmdefGraph/Editor/Scripts/AsmdefFile.cs.meta @@ -0,0 +1,11 @@ +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 7a9221b..2408db4 100644 --- a/Assets/AsmdefGraph/Editor/Scripts/AsmdefGraphEditorWindow.cs +++ b/Assets/AsmdefGraph/Editor/Scripts/AsmdefGraphEditorWindow.cs @@ -1,5 +1,5 @@ -using System.IO; -using System.Linq; +using System.Collections.Generic; +using System.IO; using UnityEditor; namespace AsmdefGraph.Editor { @@ -10,14 +10,19 @@ namespace AsmdefGraph.Editor { } void OnEnable() { + var asmdefs = new List(); + var projectPath = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar; // プロジェクトのasmdefを全検索 - var asmdefs = Directory.EnumerateFiles( - Directory.GetCurrentDirectory(), "*.asmdef", SearchOption.AllDirectories); - var asmdefNames = asmdefs - .Select(x => x.Split('\\').LastOrDefault()) - .Select(x => x.Replace(".asmdef", "")) - .Where(x => !string.IsNullOrEmpty(x)); - var graphView = new AsmdefGraphView(asmdefNames) { + 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); + } + // viewの作成 + var graphView = new AsmdefGraphView(asmdefs) { style = { flexGrow = 1 } }; rootVisualElement.Add(graphView); diff --git a/Assets/AsmdefGraph/Editor/Scripts/AsmdefGraphView.cs b/Assets/AsmdefGraph/Editor/Scripts/AsmdefGraphView.cs index fc4604f..94b7901 100644 --- a/Assets/AsmdefGraph/Editor/Scripts/AsmdefGraphView.cs +++ b/Assets/AsmdefGraph/Editor/Scripts/AsmdefGraphView.cs @@ -4,7 +4,7 @@ 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); // 背景を黒に @@ -12,7 +12,7 @@ namespace AsmdefGraph.Editor { // ドラッグによる移動可能に this.AddManipulator(new SelectionDragger()); foreach (var asmdef in asmdefs) { - AddElement(new AsmdefNode(asmdef)); + AddElement(new AsmdefNode(asmdef.Content.name)); } } diff --git a/Assets/AsmdefGraph/Example/AsmdefGraph.Example.asmdef b/Assets/AsmdefGraph/Example/AsmdefGraph.Example.asmdef index 0ce7a6c..36d25ec 100644 --- a/Assets/AsmdefGraph/Example/AsmdefGraph.Example.asmdef +++ b/Assets/AsmdefGraph/Example/AsmdefGraph.Example.asmdef @@ -1,3 +1,15 @@ -{ - "name": "AsmdefGraph.Example" -} +{ + "name": "AsmdefGraph.Example", + "references": [ + "GUID:2bafac87e7f4b9b418d9448d219b01ab" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/AsmdefGraph/Example/Fuga/AsmdefGraph.Example.Fuga.asmdef b/Assets/AsmdefGraph/Example/Fuga/AsmdefGraph.Example.Fuga.asmdef index 1cc94dd..218e791 100644 --- a/Assets/AsmdefGraph/Example/Fuga/AsmdefGraph.Example.Fuga.asmdef +++ b/Assets/AsmdefGraph/Example/Fuga/AsmdefGraph.Example.Fuga.asmdef @@ -1,3 +1,16 @@ -{ - "name": "AsmdefGraph.Example.Fuga" -} +{ + "name": "AsmdefGraph.Example.Fuga", + "references": [ + "GUID:4326ab8b7972b7c4abe4e28df1a1c005", + "GUID:119b4cf3f63d4c84d920ceae3917f02c" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/AsmdefGraph/Example/Hoge/AsmdefGraph.Example.Hoge.asmdef b/Assets/AsmdefGraph/Example/Hoge/AsmdefGraph.Example.Hoge.asmdef index c60ac19..8192d19 100644 --- a/Assets/AsmdefGraph/Example/Hoge/AsmdefGraph.Example.Hoge.asmdef +++ b/Assets/AsmdefGraph/Example/Hoge/AsmdefGraph.Example.Hoge.asmdef @@ -1,3 +1,15 @@ -{ - "name": "AsmdefGraph.Example.Hoge" -} +{ + "name": "AsmdefGraph.Example.Hoge", + "references": [ + "GUID:4326ab8b7972b7c4abe4e28df1a1c005" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/AsmdefGraph/Example/Piyo/AsmdefGraph.Example.Piyo.asmdef b/Assets/AsmdefGraph/Example/Piyo/AsmdefGraph.Example.Piyo.asmdef index 81190e1..7b9f81f 100644 --- a/Assets/AsmdefGraph/Example/Piyo/AsmdefGraph.Example.Piyo.asmdef +++ b/Assets/AsmdefGraph/Example/Piyo/AsmdefGraph.Example.Piyo.asmdef @@ -1,6 +1,10 @@ { "name": "AsmdefGraph.Example.Piyo", - "references": [], + "references": [ + "GUID:4326ab8b7972b7c4abe4e28df1a1c005", + "GUID:119b4cf3f63d4c84d920ceae3917f02c", + "GUID:56e14997241bc0d4796fc4e693fcc806" + ], "includePlatforms": [], "excludePlatforms": [], "allowUnsafeCode": false,