connect node
This commit is contained in:
parent
61df3a4bb2
commit
ca86eb7e05
@ -1,10 +0,0 @@
|
|||||||
namespace AsmdefGraph.Editor {
|
|
||||||
public class Asmdef {
|
|
||||||
public string name;
|
|
||||||
public string[] references;
|
|
||||||
public Asmdef() {
|
|
||||||
name = "";
|
|
||||||
references = new string[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
13
Assets/AsmdefGraph/Editor/Scripts/AsmdefDependency.cs
Normal file
13
Assets/AsmdefGraph/Editor/Scripts/AsmdefDependency.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AsmdefGraph.Editor {
|
||||||
|
public class AsmdefDependency {
|
||||||
|
public string DependsFrom { get; }
|
||||||
|
public IEnumerable<string> DependsTo { get; }
|
||||||
|
|
||||||
|
public AsmdefDependency(string key, IEnumerable<string> value) {
|
||||||
|
DependsFrom = key;
|
||||||
|
DependsTo = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: f30f8c38436702248a368db79323d7e8
|
guid: de8afe620d6667940a15a8871781c62d
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@ -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<Asmdef>(json);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public IEnumerable<string> Guids =>
|
|
||||||
Content.references.Where(x => !string.IsNullOrEmpty(x)).Select(x => x.Replace("GUID:", ""));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: ad4bbaa3b7aa9cd439fe68c352f6868c
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -1,6 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
using UnityEditor.Compilation;
|
||||||
|
|
||||||
namespace AsmdefGraph.Editor {
|
namespace AsmdefGraph.Editor {
|
||||||
public class AsmdefGraphEditorWindow : EditorWindow {
|
public class AsmdefGraphEditorWindow : EditorWindow {
|
||||||
@ -10,19 +12,18 @@ namespace AsmdefGraph.Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnEnable() {
|
void OnEnable() {
|
||||||
var asmdefs = new List<AsmdefFile>();
|
// .asmdefをすべて取得
|
||||||
var projectPath = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar;
|
var asmdefs = CompilationPipeline.GetAssemblies();
|
||||||
// プロジェクトのasmdefを全検索
|
var allDependencies = new List<AsmdefDependency>();
|
||||||
var fullPathes = Directory.EnumerateFiles(projectPath, "*.asmdef", SearchOption.AllDirectories);
|
foreach (var asmdef in asmdefs) {
|
||||||
// asmdefの内容取得
|
allDependencies.Add(
|
||||||
foreach (var fullPath in fullPathes) {
|
new AsmdefDependency(
|
||||||
var assetPath = fullPath.Replace(projectPath, "");
|
asmdef.name,
|
||||||
var asmdef = new AsmdefFile();
|
asmdef.assemblyReferences?.Select(x => x.name) ?? new string[0])
|
||||||
asmdef.LoadFromPath(fullPath, assetPath);
|
);
|
||||||
asmdefs.Add(asmdef);
|
|
||||||
}
|
}
|
||||||
// viewの作成
|
// viewの作成
|
||||||
var graphView = new AsmdefGraphView(asmdefs) {
|
var graphView = new AsmdefGraphView(allDependencies) {
|
||||||
style = { flexGrow = 1 }
|
style = { flexGrow = 1 }
|
||||||
};
|
};
|
||||||
rootVisualElement.Add(graphView);
|
rootVisualElement.Add(graphView);
|
||||||
|
@ -1,18 +1,37 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UnityEditor.Experimental.GraphView;
|
using UnityEditor.Experimental.GraphView;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
namespace AsmdefGraph.Editor {
|
namespace AsmdefGraph.Editor {
|
||||||
public class AsmdefGraphView : GraphView {
|
public class AsmdefGraphView : GraphView {
|
||||||
public AsmdefGraphView(IEnumerable<AsmdefFile> asmdefs) : base() {
|
public AsmdefGraphView(IEnumerable<AsmdefDependency> asmdefs) : base() {
|
||||||
// zoom可能に
|
// zoom可能に
|
||||||
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
|
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
|
||||||
// 背景を黒に
|
// 背景を黒に
|
||||||
Insert(0, new GridBackground());
|
Insert(0, new GridBackground());
|
||||||
// ドラッグによる移動可能に
|
// ドラッグによる移動可能に
|
||||||
this.AddManipulator(new SelectionDragger());
|
this.AddManipulator(new SelectionDragger());
|
||||||
|
// ノードの追加
|
||||||
|
var asmdefNodeDict = new Dictionary<string, AsmdefNode>();
|
||||||
foreach (var asmdef in asmdefs) {
|
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);// これが無いと線が表示されない
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,16 +2,19 @@
|
|||||||
|
|
||||||
namespace AsmdefGraph.Editor {
|
namespace AsmdefGraph.Editor {
|
||||||
public class AsmdefNode : Node {
|
public class AsmdefNode : Node {
|
||||||
|
public readonly Port InPort;
|
||||||
|
public readonly Port OutPort;
|
||||||
|
|
||||||
public AsmdefNode(string nodeName) {
|
public AsmdefNode(string nodeName) {
|
||||||
title = nodeName;
|
title = nodeName;
|
||||||
|
|
||||||
var inputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Multi, typeof(Port));
|
InPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Multi, typeof(Port));
|
||||||
inputPort.portName = "In";
|
InPort.portName = "In";
|
||||||
inputContainer.Add(inputPort);
|
inputContainer.Add(InPort);
|
||||||
|
|
||||||
var outputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(Port));
|
OutPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(Port));
|
||||||
outputPort.portName = "Out";
|
OutPort.portName = "Out";
|
||||||
outputContainer.Add(outputPort);
|
outputContainer.Add(OutPort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user