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
|
||||
guid: f30f8c38436702248a368db79323d7e8
|
||||
guid: de8afe620d6667940a15a8871781c62d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
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.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<AsmdefFile>();
|
||||
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<AsmdefDependency>();
|
||||
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);
|
||||
|
@ -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<AsmdefFile> asmdefs) : base() {
|
||||
public AsmdefGraphView(IEnumerable<AsmdefDependency> asmdefs) : base() {
|
||||
// zoom可能に
|
||||
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
|
||||
// 背景を黒に
|
||||
Insert(0, new GridBackground());
|
||||
// ドラッグによる移動可能に
|
||||
this.AddManipulator(new SelectionDragger());
|
||||
// ノードの追加
|
||||
var asmdefNodeDict = new Dictionary<string, AsmdefNode>();
|
||||
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 {
|
||||
public class AsmdefNode : Node {
|
||||
public readonly Port InPort;
|
||||
public readonly Port OutPort;
|
||||
|
||||
public AsmdefNode(string nodeName) {
|
||||
title = nodeName;
|
||||
|
||||
var inputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Multi, typeof(Port));
|
||||
inputPort.portName = "In";
|
||||
inputContainer.Add(inputPort);
|
||||
InPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Multi, typeof(Port));
|
||||
InPort.portName = "In";
|
||||
inputContainer.Add(InPort);
|
||||
|
||||
var outputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(Port));
|
||||
outputPort.portName = "Out";
|
||||
outputContainer.Add(outputPort);
|
||||
OutPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(Port));
|
||||
OutPort.portName = "Out";
|
||||
outputContainer.Add(OutPort);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user