ランダムに整列
This commit is contained in:
parent
a55f46e7c3
commit
ff6b37420a
@ -1,13 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace AsmdefHelper.DependencyGraph.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,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: de8afe620d6667940a15a8871781c62d
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -13,16 +13,8 @@ namespace AsmdefHelper.DependencyGraph.Editor {
|
|||||||
void OnEnable() {
|
void OnEnable() {
|
||||||
// .asmdefをすべて取得
|
// .asmdefをすべて取得
|
||||||
var asmdefs = CompilationPipeline.GetAssemblies();
|
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の作成
|
// viewの作成
|
||||||
var graphView = new AsmdefGraphView(allDependencies) {
|
var graphView = new AsmdefGraphView(asmdefs) {
|
||||||
style = { flexGrow = 1 }
|
style = { flexGrow = 1 }
|
||||||
};
|
};
|
||||||
rootVisualElement.Add(graphView);
|
rootVisualElement.Add(graphView);
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using AsmdefHelper.DependencyGraph.Editor.DependencyNode;
|
||||||
|
using AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort;
|
||||||
|
using AsmdefHelper.DependencyGraph.Editor.NodeView;
|
||||||
|
using UnityEditor.Compilation;
|
||||||
using UnityEditor.Experimental.GraphView;
|
using UnityEditor.Experimental.GraphView;
|
||||||
|
using UnityEngine;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
namespace AsmdefHelper.DependencyGraph.Editor {
|
namespace AsmdefHelper.DependencyGraph.Editor {
|
||||||
public class AsmdefGraphView : GraphView {
|
public sealed class AsmdefGraphView : GraphView {
|
||||||
public AsmdefGraphView(IEnumerable<AsmdefDependency> asmdefs) : base() {
|
public AsmdefGraphView(IEnumerable<Assembly> assemblies) {
|
||||||
|
var assemblyArr = assemblies.ToArray();
|
||||||
// zoom可能に
|
// zoom可能に
|
||||||
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
|
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
|
||||||
// 背景を黒に
|
// 背景を黒に
|
||||||
@ -12,24 +19,50 @@ namespace AsmdefHelper.DependencyGraph.Editor {
|
|||||||
// ドラッグによる移動可能に
|
// ドラッグによる移動可能に
|
||||||
this.AddManipulator(new SelectionDragger());
|
this.AddManipulator(new SelectionDragger());
|
||||||
// ノードの追加
|
// ノードの追加
|
||||||
var asmdefNodeDict = new Dictionary<string, AsmdefNode>();
|
var asmdefNodeDict = new Dictionary<string, IAsmdefNodeView>();
|
||||||
foreach (var asmdef in asmdefs) {
|
foreach (var asm in assemblyArr) {
|
||||||
var node = new AsmdefNode(asmdef.DependsFrom);
|
var node = new AsmdefNode(asm.name, contentContainer);
|
||||||
AddElement(node);
|
AddElement(node);
|
||||||
asmdefNodeDict.Add(node.title, node);
|
asmdefNodeDict.Add(node.title, node);
|
||||||
}
|
}
|
||||||
// 依存先にラインを追加
|
// 依存の整理
|
||||||
var nodeApapter = new NodeAdapter();
|
var nodeProfiles = assemblyArr
|
||||||
foreach (var asmdef in asmdefs) {
|
.Select((x, i) => new NodeProfile(new NodeId(i), x.name))
|
||||||
if (!asmdefNodeDict.TryGetValue(asmdef.DependsFrom, out var fromNode)) {
|
.ToDictionary(x => x.Name);
|
||||||
|
var dependencies = new List<IDependencyNode>(nodeProfiles.Count);
|
||||||
|
// 依存先の設定
|
||||||
|
foreach (var asm in assemblyArr) {
|
||||||
|
if (nodeProfiles.TryGetValue(asm.name, out var profile)) {
|
||||||
|
var requireProfiles = asm.assemblyReferences
|
||||||
|
.Where(x => nodeProfiles.ContainsKey(x.name))
|
||||||
|
.Select(x => nodeProfiles[x.name]);
|
||||||
|
var dep = new HashSetDependencyNode(profile);
|
||||||
|
dep.SetRequireNodes(requireProfiles);
|
||||||
|
dependencies.Add(dep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 依存元の設定
|
||||||
|
NodeProcessor.SetBeRequiredNodes(dependencies);
|
||||||
|
|
||||||
|
// 依存先にのみラインを追加
|
||||||
|
foreach (var dep in dependencies) {
|
||||||
|
if (!asmdefNodeDict.TryGetValue(dep.Profile.Name, out var fromNode)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach (var dependents in asmdef.DependsTo) {
|
foreach (var dest in dep.Destinations) {
|
||||||
if (!asmdefNodeDict.TryGetValue(dependents, out var toNode)) {
|
if (!asmdefNodeDict.TryGetValue(dest.Name, out var toNode)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var edge = fromNode.RightPort.ConnectTo(toNode.LeftPort);
|
fromNode.RightPort.Connect(toNode.LeftPort);
|
||||||
contentContainer.Add(edge);// これが無いと線が表示されない
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ノードの場所を整列
|
||||||
|
var sortStrategy = new RandomSortStrategy(Vector2.zero, 100, 600, 100);
|
||||||
|
var sortedNode = sortStrategy.Sort(dependencies);
|
||||||
|
foreach (var node in sortedNode) {
|
||||||
|
if (asmdefNodeDict.TryGetValue(node.Profile.Name, out var nodeView)) {
|
||||||
|
nodeView.SetPositionXY(node.Position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
using UnityEditor.Experimental.GraphView;
|
using AsmdefHelper.DependencyGraph.Editor.NodeView;
|
||||||
|
using UnityEditor.Experimental.GraphView;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
namespace AsmdefHelper.DependencyGraph.Editor {
|
namespace AsmdefHelper.DependencyGraph.Editor {
|
||||||
public class AsmdefNode : Node {
|
public class AsmdefNode : UiElementsNodeView, IAsmdefNodeView {
|
||||||
public readonly Port LeftPort;
|
public IPort LeftPort { get; }
|
||||||
public readonly Port RightPort;
|
public IPort RightPort { get; }
|
||||||
|
|
||||||
public AsmdefNode(string nodeName) {
|
public AsmdefNode(string nodeName, VisualElement parentContentContainer) {
|
||||||
title = nodeName;
|
Label = nodeName;
|
||||||
|
|
||||||
LeftPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(Port));
|
LeftPort = new GraphViewPort(parentContentContainer, Direction.Input) { Label = "Ref By" };
|
||||||
LeftPort.portName = "Ref By";
|
inputContainer.Add(LeftPort as Port); // as right side
|
||||||
outputContainer.Add(LeftPort); // as right side
|
|
||||||
|
|
||||||
RightPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Multi, typeof(Port));
|
RightPort = new GraphViewPort(parentContentContainer, Direction.Output) { Label = "Ref To" };
|
||||||
RightPort.portName = "Ref To";
|
outputContainer.Add(RightPort as Port); // as left side
|
||||||
inputContainer.Add(RightPort); // as left side
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,16 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort {
|
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort {
|
||||||
public class NodeGrid {
|
public class NodeGrid {
|
||||||
public readonly float GridSize;
|
public readonly float GridWidth;
|
||||||
|
public readonly float GridHeight;
|
||||||
|
public readonly float Distance;
|
||||||
readonly int gridSideCount;
|
readonly int gridSideCount;
|
||||||
public readonly int GridCount;
|
public readonly int GridCount;
|
||||||
|
|
||||||
public NodeGrid(float nodeWidth, float nodeDistance, int nodeCount) {
|
public NodeGrid(float nodeWidth, float nodeHeight, float nodeDistance, int nodeCount) {
|
||||||
GridSize = nodeDistance + nodeWidth / 2.0F;
|
GridWidth = nodeWidth;
|
||||||
|
GridHeight = nodeHeight;
|
||||||
|
Distance = nodeDistance;
|
||||||
gridSideCount = SquareValueProvider.ProvideNearestSquareValue(nodeCount);
|
gridSideCount = SquareValueProvider.ProvideNearestSquareValue(nodeCount);
|
||||||
GridCount = gridSideCount * gridSideCount;
|
GridCount = gridSideCount * gridSideCount;
|
||||||
}
|
}
|
||||||
@ -21,10 +25,10 @@ namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort {
|
|||||||
var x = 0.0F;
|
var x = 0.0F;
|
||||||
for (var j = 0; j < gridSideCount; j++) {
|
for (var j = 0; j < gridSideCount; j++) {
|
||||||
grids[index] = new Vector2(x, y);
|
grids[index] = new Vector2(x, y);
|
||||||
x += GridSize;
|
x += (GridWidth/2.0F) + Distance;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
y += GridSize;
|
y += (GridHeight/2.0F) + Distance;;
|
||||||
}
|
}
|
||||||
return grids;
|
return grids;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort {
|
|||||||
var nodeArr = nodes
|
var nodeArr = nodes
|
||||||
.Select(x => new SortedNode { Profile = x.Profile, Position = originPosition })
|
.Select(x => new SortedNode { Profile = x.Profile, Position = originPosition })
|
||||||
.ToArray();
|
.ToArray();
|
||||||
var nodeGrid = new NodeGrid(nodeWidth, basicDistance, nodeArr.Length);
|
var nodeGrid = new NodeGrid(nodeWidth, nodeHeight, basicDistance, nodeArr.Length);
|
||||||
var positions = nodeGrid.GridCenterPositions();
|
var positions = nodeGrid.GridCenterPositions();
|
||||||
var indexes = Enumerable.Range(0, positions.Count).ToList();
|
var indexes = Enumerable.Range(0, positions.Count).ToList();
|
||||||
|
|
||||||
|
@ -10,9 +10,8 @@ namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode.Tests {
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestNodeGrid() {
|
public void TestNodeGrid() {
|
||||||
const float e = 0.000001F;
|
const float e = 0.000001F;
|
||||||
var nodeGrid = new NodeGrid(10.0F, 10.0F, 4);
|
var nodeGrid = new NodeGrid(10.0F, 10.0F, 10.0F, 4);
|
||||||
Assert.That(nodeGrid.GridCount, Is.EqualTo(4));
|
Assert.That(nodeGrid.GridCount, Is.EqualTo(4));
|
||||||
Assert.That(nodeGrid.GridSize, Is.EqualTo(15.0F).Within(e));
|
|
||||||
var grids = nodeGrid.GridCenterPositions();
|
var grids = nodeGrid.GridCenterPositions();
|
||||||
Assert.That(grids[0].x, Is.EqualTo(0.0F).Within(e));
|
Assert.That(grids[0].x, Is.EqualTo(0.0F).Within(e));
|
||||||
Assert.That(grids[0].y, Is.EqualTo(0.0F).Within(e));
|
Assert.That(grids[0].y, Is.EqualTo(0.0F).Within(e));
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
using AsmdefHelper.DependencyGraph.Editor.NodeView;
|
||||||
|
|
||||||
|
namespace AsmdefHelper.DependencyGraph.Editor {
|
||||||
|
public interface IAsmdefNodeView : INodeView {
|
||||||
|
IPort LeftPort { get; }
|
||||||
|
IPort RightPort { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b6072eb937a646a4b9cd860534bd9d43
|
||||||
|
timeCreated: 1605710938
|
@ -0,0 +1,24 @@
|
|||||||
|
using UnityEditor.Experimental.GraphView;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
|
namespace AsmdefHelper.DependencyGraph.Editor.NodeView {
|
||||||
|
public class GraphViewPort : Port, IPort {
|
||||||
|
|
||||||
|
readonly VisualElement parentContentContainer;
|
||||||
|
|
||||||
|
public GraphViewPort(VisualElement contentContainer, Direction directionType) : base(Orientation.Horizontal,
|
||||||
|
directionType, Capacity.Multi, typeof(Port)) {
|
||||||
|
parentContentContainer = contentContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Label { set => portName = value; get => portName; }
|
||||||
|
public Vector2 Position => new Vector2(GetPosition().x, GetPosition().y);
|
||||||
|
|
||||||
|
public void Connect(IPort port) {
|
||||||
|
if (port is Port graphViewPort) {
|
||||||
|
parentContentContainer.Add(ConnectTo(graphViewPort));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 44bf77af3f4d4781a1f63e6227256bec
|
||||||
|
timeCreated: 1605711889
|
10
Assets/AsmdefHelper/DependencyGraph/Editor/NodeView/IPort.cs
Normal file
10
Assets/AsmdefHelper/DependencyGraph/Editor/NodeView/IPort.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using UnityEditor.Experimental.GraphView;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace AsmdefHelper.DependencyGraph.Editor.NodeView {
|
||||||
|
public interface IPort {
|
||||||
|
string Label { set; get; }
|
||||||
|
Vector2 Position { get; }
|
||||||
|
void Connect(IPort port);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 21b3446cef7248c8b533162402f8429f
|
||||||
|
timeCreated: 1605711702
|
@ -1,25 +1,26 @@
|
|||||||
using UnityEditor.Graphs;
|
using UnityEditor.Experimental.GraphView;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AsmdefHelper.DependencyGraph.Editor.NodeView {
|
namespace AsmdefHelper.DependencyGraph.Editor.NodeView {
|
||||||
public class UiElementsNodeView : Node, INodeView {
|
public class UiElementsNodeView : Node, INodeView {
|
||||||
|
|
||||||
string INodeView.Label {
|
public string Label {
|
||||||
get => title;
|
get => title;
|
||||||
set => title = value;
|
set => title = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
float IRect.PositionX {
|
public float PositionX {
|
||||||
get => position.x;
|
get => transform.position.x;
|
||||||
set => position.x = value;
|
set => transform.position = new Vector3(value, PositionY, transform.position.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
float IRect.PositionY {
|
public float PositionY {
|
||||||
get => position.y;
|
get => transform.position.y;
|
||||||
set => position.y = value;
|
set => transform.position = new Vector3(PositionX, value, transform.position.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
float IRect.Height => position.height;
|
public float Height => contentRect.height;
|
||||||
|
|
||||||
float IRect.Width => position.width;
|
public float Width => contentRect.width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user