Compare commits
58 Commits
Author | SHA1 | Date | |
---|---|---|---|
63e57636c0 | |||
![]() |
d0a17c5bbd | ||
![]() |
553b327d4d | ||
![]() |
c8f308c41a | ||
![]() |
29e21dbbe2 | ||
![]() |
4cfe8c73a0 | ||
![]() |
fb2b3228c0 | ||
![]() |
2246d8f136 | ||
![]() |
1dafd474c2 | ||
![]() |
62598385de | ||
![]() |
a414349cda | ||
![]() |
ab03e64ec3 | ||
![]() |
b4824a5490 | ||
![]() |
ccf420747b | ||
![]() |
7f311b9000 | ||
![]() |
7669aa0212 | ||
![]() |
1bfa4d5b41 | ||
![]() |
6e87411074 | ||
![]() |
c9a893fdde | ||
![]() |
db82661e78 | ||
![]() |
40b208a7c5 | ||
![]() |
2d46806ca2 | ||
![]() |
e2ea2241e5 | ||
![]() |
455f64f72c | ||
![]() |
95fa00c675 | ||
![]() |
d470c63fee | ||
![]() |
a2b3bc90a7 | ||
![]() |
89d8712bb5 | ||
![]() |
0bb5c8d293 | ||
![]() |
42fbb35553 | ||
![]() |
45af1a7d81 | ||
![]() |
6a2cbd6dd3 | ||
![]() |
9a8772967a | ||
![]() |
35961651b3 | ||
![]() |
2d13dc20ce | ||
![]() |
363ed7914f | ||
![]() |
5e63d32268 | ||
![]() |
ad5ad99975 | ||
![]() |
52f2856307 | ||
![]() |
6e5241ed2e | ||
![]() |
c6aafef7ae | ||
![]() |
9c0e3deac3 | ||
![]() |
569f645220 | ||
![]() |
b798d5a3ca | ||
![]() |
cb49abe84c | ||
![]() |
bedce68a44 | ||
![]() |
d5a67a4571 | ||
![]() |
ff6b37420a | ||
![]() |
a55f46e7c3 | ||
![]() |
2cba3e7e95 | ||
![]() |
5ec5d749c3 | ||
![]() |
029ee6515d | ||
![]() |
beebf3e7c8 | ||
![]() |
004348f024 | ||
![]() |
5e3c9dc760 | ||
![]() |
cd8514c114 | ||
![]() |
fd0399c364 | ||
![]() |
203892791e |
@ -1,20 +1,18 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using AsmdefHelper.CustomCreate.Editor;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEditor.UIElements;
|
||||
|
||||
|
||||
// original: https://github.com/baba-s/UniAssemblyDefinitionCreator
|
||||
public class AsmdefCustomCreateView : EditorWindow {
|
||||
namespace AsmdefHelper.CustomCreate.Editor {
|
||||
// original: https://github.com/baba-s/UniAssemblyDefinitionCreator
|
||||
public class AsmdefCustomCreateView : EditorWindow {
|
||||
[MenuItem("Assets/AsmdefHelper/Create custom asmdef")]
|
||||
public static void ShowWindow() {
|
||||
var window = GetWindow<AsmdefCustomCreateView>();
|
||||
window.titleContent = new GUIContent("AsmdefCustomCreateView");
|
||||
window.minSize = new Vector2(200,180);
|
||||
window.maxSize = new Vector2(2000,180);
|
||||
window.minSize = new Vector2(200, 200);
|
||||
window.maxSize = new Vector2(2000, 2000);
|
||||
}
|
||||
|
||||
public void OnEnable() {
|
||||
@ -30,36 +28,52 @@ public class AsmdefCustomCreateView : EditorWindow {
|
||||
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
|
||||
"Packages/dev.n5y.asmdefhelper/AsmdefHelper/CustomCreate/Editor/AsmdefCustomCreateView.uxml");
|
||||
}
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
VisualElement labelFromUXML = visualTree.Instantiate();
|
||||
#else
|
||||
VisualElement labelFromUXML = visualTree.CloneTree();
|
||||
#endif
|
||||
root.Add(labelFromUXML);
|
||||
|
||||
// UI取得
|
||||
var PathTextField = root.Q<TextField>(className: "PathTextField");
|
||||
var NameTextField = root.Q<TextField>(className: "NameTextField");
|
||||
var AllowUnsafeToggle = root.Q<Toggle>(className: "AllowUnsafeToggle");
|
||||
var AutoReferencedToggle = root.Q<Toggle>(className: "AutoReferencedToggle");
|
||||
var OverrideReferencesToggle = root.Q<Toggle>(className: "OverrideReferencesToggle");
|
||||
var NoEngineReferencesToggle = root.Q<Toggle>(className: "NoEngineReferencesToggle");
|
||||
var IsEditorToggle = root.Q<Toggle>(className: "IsEditorToggle");
|
||||
var CreateButton = root.Q<Button>(className: "CreateButton");
|
||||
var pathTextField = root.Q<TextField>(className: "PathTextField");
|
||||
var nameTextField = root.Q<TextField>(className: "NameTextField");
|
||||
var allowUnsafeToggle = root.Q<Toggle>(className: "AllowUnsafeToggle");
|
||||
var autoReferencedToggle = root.Q<Toggle>(className: "AutoReferencedToggle");
|
||||
var noEngineReferencesToggle = root.Q<Toggle>(className: "NoEngineReferencesToggle");
|
||||
var overrideReferencesToggle = root.Q<Toggle>(className: "OverrideReferencesToggle");
|
||||
var rootNamespaceTextField = root.Q<TextField>(className: "RootNamespaceTextField");
|
||||
var isEditorToggle = root.Q<Toggle>(className: "IsEditorToggle");
|
||||
var createButton = root.Q<Button>(className: "CreateButton");
|
||||
|
||||
// PathとNameの初期値
|
||||
var asset = Selection.activeObject;
|
||||
var assetPath = AssetDatabase.GetAssetPath(asset);
|
||||
var directory = string.IsNullOrWhiteSpace(assetPath) ? "Assets/" : assetPath;
|
||||
PathTextField.value = directory;
|
||||
NameTextField.value = directory.Replace("Assets/", "").Replace('/', '.');
|
||||
pathTextField.value = directory;
|
||||
var defaultName = directory.Replace("Assets/", "").Replace('/', '.');
|
||||
nameTextField.value = defaultName;
|
||||
|
||||
// RootNamespace が設定できるのは2020.2以降
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
rootNamespaceTextField.value = defaultName;
|
||||
#else
|
||||
root.Q<Box>(className: "Box").Remove(rootNamespaceTextField);
|
||||
#endif
|
||||
// .asmdefを作成して閉じる
|
||||
CreateButton.clickable.clicked += () => {
|
||||
var asmdefName = NameTextField.value;
|
||||
createButton.clickable.clicked += () => {
|
||||
var asmdefName = nameTextField.value;
|
||||
var asmdef = new AssemblyDefinitionJson {
|
||||
name = asmdefName,
|
||||
allowUnsafeCode = AllowUnsafeToggle.value,
|
||||
autoReferenced = AutoReferencedToggle.value,
|
||||
overrideReferences = OverrideReferencesToggle.value,
|
||||
noEngineReferences = NoEngineReferencesToggle.value,
|
||||
includePlatforms = IsEditorToggle.value ? new[] { "Editor" } : new string[0]
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
rootNamespace = rootNamespaceTextField.value,
|
||||
#endif
|
||||
allowUnsafeCode = allowUnsafeToggle.value,
|
||||
autoReferenced = autoReferencedToggle.value,
|
||||
overrideReferences = overrideReferencesToggle.value,
|
||||
noEngineReferences = noEngineReferencesToggle.value,
|
||||
includePlatforms = isEditorToggle.value ? new[] { "Editor" } : new string[0]
|
||||
};
|
||||
var asmdefJson = JsonUtility.ToJson(asmdef, true);
|
||||
var asmdefPath = $"{directory}/{asmdefName}.asmdef";
|
||||
@ -68,4 +82,5 @@ public class AsmdefCustomCreateView : EditorWindow {
|
||||
Close();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,14 @@
|
||||
xsi:noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd"
|
||||
>
|
||||
<engine:Label class="AsmdefInfo" text="Input your asmdef info"/>
|
||||
<engine:Box>
|
||||
<engine:Box class="Box">
|
||||
<engine:TextField class="PathTextField" label="Path" text="ASMDEF_PATH_HERE" readonly="true"/>
|
||||
<engine:TextField class="NameTextField" label="Name" text="ASMDEF_NAME_HERE"/>
|
||||
<engine:Toggle class="AllowUnsafeToggle" label="Allow 'unsafe' Code" value="false"/>
|
||||
<engine:Toggle class="AutoReferencedToggle" label="Auto Referenced" value="true"/>
|
||||
<engine:Toggle class="OverrideReferencesToggle" label="Override Referenced" value="false"/>
|
||||
<engine:Toggle class="NoEngineReferencesToggle" label="No Engine References" value="false"/>
|
||||
<engine:Toggle class="OverrideReferencesToggle" label="Override Referenced" value="false"/>
|
||||
<engine:TextField class="RootNamespaceTextField" label="Root Namespace" text="ROOT_NAMESPACE_HERE"/>
|
||||
<engine:Toggle class="IsEditorToggle" label="Is Editor" value="false"/>
|
||||
<engine:Button class="CreateButton" text="Create" />
|
||||
</engine:Box>
|
||||
|
92
Assets/AsmdefHelper/CustomCreate/Editor/AsmdefRenameView.cs
Normal file
92
Assets/AsmdefHelper/CustomCreate/Editor/AsmdefRenameView.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace AsmdefHelper.CustomCreate.Editor {
|
||||
public class AsmdefRenameView : EditorWindow {
|
||||
static string renameAsmdefPath = "";
|
||||
static string asmdefDirectory = "";
|
||||
|
||||
[MenuItem("Assets/AsmdefHelper/Rename asmdef")]
|
||||
public static void ShowWindow() {
|
||||
// PathとNameの初期値
|
||||
var asset = Selection.activeObject;
|
||||
renameAsmdefPath = AssetDatabase.GetAssetPath(asset);
|
||||
asmdefDirectory = Path.GetDirectoryName(renameAsmdefPath);
|
||||
// asmdefが選択されている時のみ開く
|
||||
var extension = renameAsmdefPath.Split('.').LastOrDefault();
|
||||
if (extension == "asmdef") {
|
||||
var window = GetWindow<AsmdefRenameView>();
|
||||
window.titleContent = new GUIContent("AsmdefRenameView");
|
||||
window.minSize = new Vector2(200, 100);
|
||||
window.maxSize = new Vector2(2000, 100);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnEnable() {
|
||||
// Each editor window contains a root VisualElement object
|
||||
VisualElement root = rootVisualElement;
|
||||
|
||||
// Import UXML
|
||||
var visualTree =
|
||||
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
|
||||
"Assets/AsmdefHelper/CustomCreate/Editor/AsmdefRenameView.uxml");
|
||||
if (visualTree == null) {
|
||||
visualTree =
|
||||
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
|
||||
"Packages/dev.n5y.asmdefhelper/AsmdefHelper/CustomCreate/Editor/AsmdefRenameView.uxml");
|
||||
}
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
VisualElement labelFromUXML = visualTree.Instantiate();
|
||||
#else
|
||||
VisualElement labelFromUXML = visualTree.CloneTree();
|
||||
#endif
|
||||
root.Add(labelFromUXML);
|
||||
|
||||
// UI取得
|
||||
var pathTextField = root.Q<TextField>(className: "PathTextField");
|
||||
var nameTextField = root.Q<TextField>(className: "NameTextField");
|
||||
var rootNamespaceTextField = root.Q<TextField>(className: "RootNamespaceTextField");
|
||||
var createButton = root.Q<Button>(className: "RenameButton");
|
||||
|
||||
// 既存のasmdef読み込み
|
||||
var orgText = File.ReadAllText(renameAsmdefPath);
|
||||
var asmdef = JsonUtility.FromJson<AssemblyDefinitionJson>(orgText);
|
||||
|
||||
// 既存パラメータの反映
|
||||
pathTextField.value = asmdefDirectory;
|
||||
nameTextField.value = asmdef.name;
|
||||
var asmdefNameOrg = asmdef.name;
|
||||
|
||||
// RootNamespace が設定できるのは2020.2以降
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
rootNamespaceTextField.value = asmdef.rootNamespace;
|
||||
#else
|
||||
root.Q<Box>(className: "Box").Remove(rootNamespaceTextField);
|
||||
#endif
|
||||
|
||||
// .asmdefのnameとファイル名を更新して閉じる
|
||||
createButton.clickable.clicked += () => {
|
||||
var asmdefName = nameTextField.value;
|
||||
asmdef.name = asmdefName;
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
asmdef.rootNamespace = rootNamespaceTextField.value;
|
||||
#endif
|
||||
var asmdefJson = JsonUtility.ToJson(asmdef, true);
|
||||
var newAsmdefPath = $"{asmdefDirectory}/{asmdefName}.asmdef";
|
||||
// 新asmdef作成
|
||||
File.WriteAllText(newAsmdefPath, asmdefJson, Encoding.UTF8);
|
||||
// ファイル名が変わった場合は旧asmdef削除
|
||||
if (asmdefNameOrg != asmdefName) {
|
||||
FileUtil.DeleteFileOrDirectory(renameAsmdefPath);
|
||||
}
|
||||
AssetDatabase.Refresh();
|
||||
Close();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cc99bb7ae3447c29afa7daef6d72347
|
||||
timeCreated: 1603812149
|
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<engine:UXML
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:engine="UnityEngine.UIElements"
|
||||
xmlns:editor="UnityEditor.UIElements"
|
||||
xsi:noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd"
|
||||
>
|
||||
<engine:Label class="AsmdefInfo" text="Input your asmdef info"/>
|
||||
<engine:Box>
|
||||
<engine:TextField class="PathTextField" label="Path" text="ASMDEF_PATH_HERE" readonly="true"/>
|
||||
<engine:TextField class="NameTextField" label="Name" text="ASMDEF_NAME_HERE"/>
|
||||
<engine:TextField label="Root Namespace" text="ROOT_NAMESPACE_HERE" class="RootNamespaceTextField" />
|
||||
<engine:Button class="RenameButton" text="Rename" />
|
||||
</engine:Box>
|
||||
</engine:UXML>
|
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72a349d5d05ba6c4db6d137a4bc54b01
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
@ -1,6 +1,9 @@
|
||||
namespace AsmdefHelper.CustomCreate.Editor {
|
||||
public class AssemblyDefinitionJson {
|
||||
public string name = string.Empty;
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
public string rootNamespace = string.Empty;
|
||||
#endif
|
||||
public string[] references = new string[0];
|
||||
public string[] includePlatforms = new string[0];
|
||||
public string[] excludePlatforms = new string[0];
|
||||
|
@ -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,10 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Compilation;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor {
|
||||
public class AsmdefGraphEditorWindow : EditorWindow {
|
||||
public class AsmdefGraphEditorWindow : EditorWindow, IToggleCheckDelegate {
|
||||
static AsmdefSelectionView selectionWindow;
|
||||
AsmdefGraphView graphView;
|
||||
|
||||
[MenuItem("AsmdefHelper/Open DependencyGraph", priority = 2000)]
|
||||
public static void Open() {
|
||||
GetWindow<AsmdefGraphEditorWindow>("Asmdef Dependency");
|
||||
@ -13,19 +14,27 @@ namespace AsmdefHelper.DependencyGraph.Editor {
|
||||
void OnEnable() {
|
||||
// .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(allDependencies) {
|
||||
graphView = new AsmdefGraphView(asmdefs) {
|
||||
style = { flexGrow = 1 }
|
||||
};
|
||||
rootVisualElement.Add(graphView);
|
||||
|
||||
// 選択ウィンドウも作成
|
||||
selectionWindow = GetWindow<AsmdefSelectionView>("Asmdef Selection");
|
||||
selectionWindow.SetAsmdef(asmdefs, this);
|
||||
}
|
||||
|
||||
// 片方を閉じる
|
||||
void OnDestroy() {
|
||||
if (selectionWindow != null) {
|
||||
selectionWindow.Close();
|
||||
}
|
||||
selectionWindow = null;
|
||||
}
|
||||
|
||||
void IToggleCheckDelegate.OnSelectionChanged(string label, bool isChecked) {
|
||||
graphView.SetNodeVisibility(label, isChecked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +1,87 @@
|
||||
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 UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor {
|
||||
public class AsmdefGraphView : GraphView {
|
||||
public AsmdefGraphView(IEnumerable<AsmdefDependency> asmdefs) : base() {
|
||||
public sealed class AsmdefGraphView : GraphView {
|
||||
readonly Dictionary<string, IAsmdefNodeView> asmdefNodeDict;
|
||||
public AsmdefGraphView(IEnumerable<Assembly> assemblies) {
|
||||
var assemblyArr = assemblies.ToArray();
|
||||
// zoom可能に
|
||||
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
|
||||
// 背景を黒に
|
||||
Insert(0, new GridBackground());
|
||||
// ドラッグによる移動可能に
|
||||
this.AddManipulator(new SelectionDragger());
|
||||
// ドラッグで描画範囲を動かせるように
|
||||
this.AddManipulator(new ContentDragger());
|
||||
// ノードの追加
|
||||
var asmdefNodeDict = new Dictionary<string, AsmdefNode>();
|
||||
foreach (var asmdef in asmdefs) {
|
||||
var node = new AsmdefNode(asmdef.DependsFrom);
|
||||
asmdefNodeDict = new Dictionary<string, IAsmdefNodeView>();
|
||||
foreach (var asm in assemblyArr) {
|
||||
var node = new AsmdefNode(asm.name, contentContainer);
|
||||
AddElement(node);
|
||||
asmdefNodeDict.Add(node.title, node);
|
||||
}
|
||||
// 依存先にラインを追加
|
||||
var nodeApapter = new NodeAdapter();
|
||||
foreach (var asmdef in asmdefs) {
|
||||
if (!asmdefNodeDict.TryGetValue(asmdef.DependsFrom, out var fromNode)) {
|
||||
// 依存の整理
|
||||
var nodeProfiles = assemblyArr
|
||||
.Select((x, i) => new NodeProfile(new NodeId(i), x.name))
|
||||
.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;
|
||||
}
|
||||
foreach (var dependents in asmdef.DependsTo) {
|
||||
if (!asmdefNodeDict.TryGetValue(dependents, out var toNode)) {
|
||||
foreach (var dest in dep.Destinations) {
|
||||
if (!asmdefNodeDict.TryGetValue(dest.Name, out var toNode)) {
|
||||
continue;
|
||||
}
|
||||
var edge = fromNode.RightPort.ConnectTo(toNode.LeftPort);
|
||||
contentContainer.Add(edge);// これが無いと線が表示されない
|
||||
fromNode.RightPort.Connect(toNode.LeftPort);
|
||||
}
|
||||
}
|
||||
|
||||
// Portに接続数を追記
|
||||
foreach (var dep in dependencies) {
|
||||
if (asmdefNodeDict.TryGetValue(dep.Profile.Name, out var node)) {
|
||||
node.LeftPort.Label = $"RefBy({dep.Sources.Count})";
|
||||
node.RightPort.Label = $"RefTo({dep.Destinations.Count})";
|
||||
}
|
||||
}
|
||||
|
||||
// ノードの場所を整列
|
||||
var sortStrategy = new AlignSortStrategy(AlignParam.Default(), Vector2.zero);
|
||||
var sortedNode = sortStrategy.Sort(dependencies);
|
||||
foreach (var node in sortedNode) {
|
||||
if (asmdefNodeDict.TryGetValue(node.Profile.Name, out var nodeView)) {
|
||||
nodeView.SetPositionXY(node.Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetNodeVisibility(string nodeName, bool visible_) {
|
||||
if (asmdefNodeDict.TryGetValue(nodeName, out var node)) {
|
||||
node.Visibility = visible_;
|
||||
}
|
||||
}
|
||||
|
||||
public override List<Port> GetCompatiblePorts(Port startAnchor, NodeAdapter nodeAdapter) {
|
||||
|
@ -1,20 +1,37 @@
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using AsmdefHelper.DependencyGraph.Editor.NodeView;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor {
|
||||
public class AsmdefNode : Node {
|
||||
public readonly Port LeftPort;
|
||||
public readonly Port RightPort;
|
||||
public class AsmdefNode : UiElementsNodeView, IAsmdefNodeView {
|
||||
readonly GraphViewPort leftPort;
|
||||
readonly GraphViewPort rightPort;
|
||||
public IPort LeftPort => leftPort;
|
||||
public IPort RightPort => rightPort;
|
||||
|
||||
public AsmdefNode(string nodeName) {
|
||||
title = nodeName;
|
||||
public AsmdefNode(string nodeName, VisualElement parentContentContainer) {
|
||||
Label = nodeName;
|
||||
|
||||
LeftPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(Port));
|
||||
LeftPort.portName = "Ref By";
|
||||
outputContainer.Add(LeftPort); // as right side
|
||||
leftPort = new GraphViewPort(parentContentContainer, Direction.Input) { Label = "Ref By" };
|
||||
inputContainer.Add(LeftPort as Port); // as right side
|
||||
|
||||
RightPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Multi, typeof(Port));
|
||||
RightPort.portName = "Ref To";
|
||||
inputContainer.Add(RightPort); // as left side
|
||||
rightPort = new GraphViewPort(parentContentContainer, Direction.Output) { Label = "Ref To" };
|
||||
outputContainer.Add(RightPort as Port); // as left side
|
||||
}
|
||||
|
||||
public override bool Visibility {
|
||||
get => base.Visibility;
|
||||
set {
|
||||
base.Visibility = value;
|
||||
// right(output)
|
||||
foreach (var edge in rightPort.connections) {
|
||||
edge.visible = edge.input.node.visible & visible;
|
||||
}
|
||||
// left(input)
|
||||
foreach (var edge in leftPort.connections) {
|
||||
edge.visible = edge.output.node.visible & visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3343c43624a31f447a1961156a2cac6e
|
||||
guid: 686371b55f14bdb4ca1a0ee236361071
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AsmdefHelper.DependencyGraph.Editor.DependencyNode;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Compilation;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor {
|
||||
public class AsmdefSelectionView : EditorWindow {
|
||||
const int toggleCount = 1000;
|
||||
static EditorWindow graphWindow;
|
||||
readonly ToggleDict groupMasterToggleDict = new ToggleDict();
|
||||
readonly ToggleDict toggleDict = new ToggleDict();
|
||||
IToggleCheckDelegate toggleDelegate;
|
||||
|
||||
public void OnEnable() {
|
||||
graphWindow = GetWindow<AsmdefGraphEditorWindow>();
|
||||
|
||||
// Each editor window contains a root VisualElement object
|
||||
VisualElement root = rootVisualElement;
|
||||
|
||||
// Import UXML
|
||||
var visualTree =
|
||||
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
|
||||
"Assets/AsmdefHelper/DependencyGraph/Editor/AsmdefSelectionView/AsmdefSelectionView.uxml");
|
||||
if (visualTree == null) {
|
||||
visualTree =
|
||||
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
|
||||
"Packages/dev.n5y.asmdefhelper/AsmdefHelper/DependencyGraph/Editor/AsmdefSelectionView/AsmdefSelectionView.uxml");
|
||||
}
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
VisualElement labelFromUXML = visualTree.Instantiate();
|
||||
#else
|
||||
VisualElement labelFromUXML = visualTree.CloneTree();
|
||||
#endif
|
||||
root.Add(labelFromUXML);
|
||||
}
|
||||
|
||||
public void SetAsmdef(Assembly[] assemblies, IToggleCheckDelegate toggleDelegate_) {
|
||||
var sortedAssemblies = assemblies.OrderBy(x => x.name).ToArray();
|
||||
var scrollView = rootVisualElement.Q<ScrollView>(className: "ScrollView");
|
||||
toggleDict.Clear();
|
||||
for (var i = 0; i < toggleCount; i++) {
|
||||
var toggle = rootVisualElement.Q<Toggle>(className: $"toggle{i}");
|
||||
if (i < sortedAssemblies.Length) {
|
||||
var assemblyName = sortedAssemblies[i].name;
|
||||
toggle.text = assemblyName;
|
||||
toggle.value = true;
|
||||
toggleDict.Add(assemblyName, new UiElementToggle(toggle));
|
||||
} else {
|
||||
scrollView.Remove(toggle);
|
||||
}
|
||||
}
|
||||
|
||||
// グループに分ける
|
||||
var group = new DomainGroup();
|
||||
group.Create(sortedAssemblies.Select(x => x.name));
|
||||
var tops = group.GetTopDomainsWithSomeSubDomains().ToArray();
|
||||
foreach (var top in tops) {
|
||||
var topToggle = new Toggle { text = top, value = true};
|
||||
var slaveToggles = new List<IToggle>();
|
||||
Toggle firstToggle = null;
|
||||
var domains = group.GetSubDomains(top);
|
||||
foreach (var domain in domains) {
|
||||
var isLast = domains.Last() == domain;
|
||||
if (toggleDict.TryGetToggle(domain.FullName, out var toggle)) {
|
||||
var keisen = isLast ? "└" : "├";
|
||||
toggle.Name = domain.HasSubDomain() ? $"{keisen} {domain.SubDomain}" : toggle.Name;
|
||||
slaveToggles.Add(toggle);
|
||||
if (firstToggle == null && toggle is UiElementToggle y) {
|
||||
firstToggle = y.Toggle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var toggleGroup = new ToggleGroup(new UiElementToggle(topToggle), slaveToggles);
|
||||
if (firstToggle != null) {
|
||||
var index = scrollView.IndexOf(firstToggle);
|
||||
// グループに属する toggle は box に入れる
|
||||
var box = new Box();
|
||||
scrollView.Insert(index, topToggle);
|
||||
scrollView.Insert(index + 1, box);
|
||||
foreach (var slaveToggle in slaveToggles) {
|
||||
if (slaveToggle is UiElementToggle x) {
|
||||
box.Add(x.Toggle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
groupMasterToggleDict.Add(top, toggleGroup);
|
||||
}
|
||||
|
||||
toggleDelegate = toggleDelegate_;
|
||||
}
|
||||
|
||||
void OnGUI() {
|
||||
// toggle の更新を監視 (onValueChangedが無さそう)
|
||||
// ToggleGroup の長
|
||||
var updatedGroups = groupMasterToggleDict.ScanUpdate().ToArray();
|
||||
groupMasterToggleDict.OverwriteToggles(updatedGroups.Select(x => x.Item1));
|
||||
// 普通の Toggle達
|
||||
var updated = toggleDict.ScanUpdate().ToArray();
|
||||
foreach (var x in updated) {
|
||||
var (key, current) = x;
|
||||
toggleDelegate?.OnSelectionChanged(key, current);
|
||||
}
|
||||
}
|
||||
|
||||
// 片方を閉じる
|
||||
async void OnDestroy() {
|
||||
// 同フレームで OnDestroy を呼ぶと警告が出るので遅延実行
|
||||
await Task.Delay(1);
|
||||
if (graphWindow != null) {
|
||||
graphWindow.Close();
|
||||
}
|
||||
graphWindow = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69bee09693f54d46954fb60401f58b66
|
||||
timeCreated: 1606312787
|
@ -0,0 +1,5 @@
|
||||
Label {
|
||||
font-size: 20px;
|
||||
-unity-font-style: bold;
|
||||
color: rgb(68, 138, 255);
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7906d8f1d4e539745bf53fba8fc20d3a
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
|
||||
disableValidation: 0
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24d749776c208f4408be0cfccb02d1c7
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
@ -0,0 +1,6 @@
|
||||
namespace AsmdefHelper.DependencyGraph.Editor {
|
||||
public interface IToggle {
|
||||
bool IsOn { set; get; }
|
||||
string Name { set; get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f8c1aea6924490e9d1f3745569b7c03
|
||||
timeCreated: 1606663328
|
@ -0,0 +1,5 @@
|
||||
namespace AsmdefHelper.DependencyGraph.Editor {
|
||||
public interface IToggleCheckDelegate {
|
||||
void OnSelectionChanged(string label, bool isChecked);
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c48da7c3f95419cbfc95c4ec2816489
|
||||
timeCreated: 1606313215
|
@ -0,0 +1,58 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor {
|
||||
public class ToggleDict {
|
||||
class TogglePair {
|
||||
public bool prevToggleValue;
|
||||
public readonly IToggle toggle;
|
||||
|
||||
public TogglePair(IToggle toggle) {
|
||||
this.toggle = toggle;
|
||||
prevToggleValue = toggle.IsOn;
|
||||
}
|
||||
}
|
||||
|
||||
readonly IDictionary<string, TogglePair> dict;
|
||||
|
||||
public ToggleDict() {
|
||||
dict = new Dictionary<string, TogglePair>();
|
||||
}
|
||||
|
||||
public void Add(string key, IToggle toggle) {
|
||||
dict.Add(key, new TogglePair(toggle));
|
||||
}
|
||||
|
||||
public IEnumerable<(string, bool)> ScanUpdate() {
|
||||
return dict
|
||||
.Where(x => x.Value.prevToggleValue != x.Value.toggle.IsOn)
|
||||
.Select(x => {
|
||||
// 更新も行う
|
||||
dict[x.Key].prevToggleValue = x.Value.toggle.IsOn;
|
||||
return (x.Key, x.Value.toggle.IsOn);
|
||||
});
|
||||
}
|
||||
|
||||
public void OverwriteToggles(IEnumerable<string> updateKeys) {
|
||||
// UI 上の Toggle の check が変わってもisOnには反映されないのでここで設定
|
||||
foreach (var keys in updateKeys) {
|
||||
var val = dict[keys];
|
||||
val.toggle.IsOn = val.toggle.IsOn;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGetToggle(string key, out IToggle toggle) {
|
||||
if (dict.TryGetValue(key, out var x)) {
|
||||
toggle = x.toggle;
|
||||
return true;
|
||||
}
|
||||
|
||||
toggle = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
dict.Clear();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8725d14bce6043b387ea7f0361a56750
|
||||
timeCreated: 1606747756
|
@ -0,0 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor {
|
||||
public class ToggleGroup : IToggle {
|
||||
readonly IToggle masterToggle;
|
||||
readonly IEnumerable<IToggle> slaveToggles;
|
||||
|
||||
public ToggleGroup(IToggle masterToggle, IEnumerable<IToggle> slaveToggles) {
|
||||
this.masterToggle = masterToggle;
|
||||
this.slaveToggles = slaveToggles;
|
||||
}
|
||||
|
||||
public string Name {
|
||||
get => masterToggle.Name;
|
||||
set => masterToggle.Name = value;
|
||||
}
|
||||
|
||||
public bool IsOn {
|
||||
get => masterToggle.IsOn;
|
||||
set {
|
||||
masterToggle.IsOn = value;
|
||||
foreach (var toggle in slaveToggles) {
|
||||
toggle.IsOn = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5308ff649752450ba423e8ce799f2048
|
||||
timeCreated: 1606663303
|
@ -0,0 +1,10 @@
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor {
|
||||
public class UiElementToggle : IToggle {
|
||||
public readonly Toggle Toggle;
|
||||
public UiElementToggle(Toggle toggle) => Toggle = toggle;
|
||||
public string Name { get => Toggle.text; set => Toggle.text = value; }
|
||||
public bool IsOn { get => Toggle.value; set => Toggle.value = value; }
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: faa82404bed34442b46aceb699aa2fd6
|
||||
timeCreated: 1606663359
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07e92c78d576a8a458ce4a298eeb512d
|
||||
guid: bbaa68e4da2746ed9af5d76e173b5e8c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
@ -0,0 +1,67 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode {
|
||||
public class DomainGroup {
|
||||
readonly Dictionary<string, List<DomainUnit>> dict;
|
||||
|
||||
public DomainGroup() {
|
||||
dict = new Dictionary<string, List<DomainUnit>>();
|
||||
}
|
||||
|
||||
public void Create(IEnumerable<string> all) {
|
||||
dict.Clear();
|
||||
foreach (var str in all) {
|
||||
var unit = new DomainUnit(str, '.');
|
||||
if (!unit.HasSubDomain()) {
|
||||
unit = new DomainUnit(str, '-');
|
||||
}
|
||||
if (!unit.HasSubDomain()) {
|
||||
unit = new DomainUnit(str, '_');
|
||||
}
|
||||
|
||||
if (!unit.HasSubDomain()) {
|
||||
dict.Add(unit.FullName, new List<DomainUnit> { unit });
|
||||
} else {
|
||||
if (dict.TryGetValue(unit.TopDomain, out var list)) {
|
||||
list.Add(unit);
|
||||
} else {
|
||||
dict.Add(unit.TopDomain, new List<DomainUnit> { unit });
|
||||
}
|
||||
}
|
||||
}
|
||||
// 1つしかなかったものを単独とする
|
||||
var soloKeys = GetSoloDomains().ToArray();
|
||||
foreach (var key in soloKeys) {
|
||||
var unit = dict[key].FirstOrDefault();
|
||||
if (unit == null || key == unit.FullName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
dict.Remove(key);
|
||||
var newKey = unit.FullName;
|
||||
if (dict.ContainsKey(newKey)) {
|
||||
dict[newKey].Add(unit);
|
||||
} else {
|
||||
dict.Add(newKey, new List<DomainUnit> { new DomainUnit(unit.FullName, '\0') });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetTopDomains() => dict.Keys;
|
||||
public IEnumerable<string> GetSoloDomains() => dict
|
||||
.Where(x => x.Value.Count == 1)
|
||||
.Select(x => x.Key);
|
||||
|
||||
public IEnumerable<string> GetTopDomainsWithSomeSubDomains() => dict
|
||||
.Keys
|
||||
.Except(GetSoloDomains());
|
||||
|
||||
public IEnumerable<DomainUnit> GetSubDomains(string topDomain) {
|
||||
if (dict.TryGetValue(topDomain, out var list)) {
|
||||
return list;
|
||||
}
|
||||
return new DomainUnit[0];
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9fe84ab1b8c44b0a841738f0ecb37d3
|
||||
timeCreated: 1606659209
|
@ -0,0 +1,27 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode {
|
||||
public class DomainUnit {
|
||||
public readonly string FullName;
|
||||
public readonly string TopDomain;
|
||||
public readonly string SubDomain;
|
||||
|
||||
public DomainUnit(string fullName, char separator) {
|
||||
this.FullName = fullName;
|
||||
if (string.IsNullOrEmpty(FullName)) return;
|
||||
var split = fullName.Split(separator).Where(x => !string.IsNullOrEmpty(x)).ToArray();
|
||||
if (split.Length < 2) {
|
||||
TopDomain = fullName.Replace(separator.ToString(), "");
|
||||
SubDomain = string.Empty;
|
||||
} else {
|
||||
TopDomain = split[0];
|
||||
SubDomain = split.Skip(1).Aggregate((a, b) => $"{a}{separator}{b}");
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasSubDomain() => !string.IsNullOrEmpty(SubDomain);
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2927a4439ddc45a0a386b64e05220d53
|
||||
timeCreated: 1606658272
|
@ -0,0 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode {
|
||||
public class HashSetDependencyNode : IDependencyNode {
|
||||
public NodeProfile Profile { get; }
|
||||
public ICollection<NodeProfile> Sources => sources;
|
||||
public ICollection<NodeProfile> Destinations => destinations;
|
||||
|
||||
readonly HashSet<NodeProfile> sources;
|
||||
readonly HashSet<NodeProfile> destinations;
|
||||
|
||||
public HashSetDependencyNode(NodeProfile profile) {
|
||||
Profile = profile;
|
||||
sources = new HashSet<NodeProfile>();
|
||||
destinations = new HashSet<NodeProfile>();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b278ba5cdda49eca5f5aa0b2941713d
|
||||
timeCreated: 1605450089
|
@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode {
|
||||
public interface IDependencyNode {
|
||||
NodeProfile Profile { get; }
|
||||
ICollection<NodeProfile> Sources { get; }
|
||||
ICollection<NodeProfile> Destinations { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 365c6defe4c649a496963187a24ffca0
|
||||
timeCreated: 1605449577
|
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode {
|
||||
public readonly struct NodeId : IEquatable<NodeId> {
|
||||
public readonly int value;
|
||||
|
||||
public NodeId(int value) => this.value = value;
|
||||
|
||||
public bool Equals(NodeId other) {
|
||||
return value == other.value;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
return obj is NodeId other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
public static bool operator ==(NodeId x, NodeId y) {
|
||||
return x.Equals(y);
|
||||
}
|
||||
|
||||
public static bool operator !=(NodeId x, NodeId y) {
|
||||
return !(x == y);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5785f4c5d9ed634799d54e96aabf408
|
||||
guid: 11a5fcf054a34f8083cdcdb038b4c70c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode {
|
||||
public static class NodeProcessor {
|
||||
|
||||
public static void SetBeRequiredNodes(IEnumerable<IDependencyNode> nodes) {
|
||||
var array = nodes as IDependencyNode[] ?? nodes.ToArray();
|
||||
var dict = array.ToDictionary(x => x.Profile.Id);
|
||||
foreach (var n in array) {
|
||||
foreach (var d in n.Destinations) {
|
||||
dict[d.Id].Sources.Add(n.Profile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetRequireNodes(this IDependencyNode node, IEnumerable<NodeProfile> requireNodes) {
|
||||
node.Sources.Clear();
|
||||
node.Destinations.Clear();
|
||||
foreach (var d in requireNodes) {
|
||||
node.Destinations.Add(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6febd7e408df42d89d561ffe371c602f
|
||||
timeCreated: 1605454341
|
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode {
|
||||
public class NodeProfile : IEquatable<NodeProfile> {
|
||||
public NodeId Id { get; }
|
||||
public string Name { set; get; }
|
||||
|
||||
public NodeProfile(NodeId id, string name) {
|
||||
Id = id;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public bool Equals(NodeProfile other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return Id.Equals(other.Id) && Name == other.Name;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (obj.GetType() != this.GetType()) return false;
|
||||
return Equals((NodeProfile) obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return (Id.GetHashCode() * 397) ^ (Name != null ? Name.GetHashCode() : 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(NodeProfile x, NodeProfile y) {
|
||||
return x.Equals(y);
|
||||
}
|
||||
|
||||
public static bool operator !=(NodeProfile x, NodeProfile y) {
|
||||
return !(x == y);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de8afe620d6667940a15a8871781c62d
|
||||
guid: 8cf71e8ce8054c4b95902fcd1bda7010
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7b935eca30945f5bff132d6a7645320
|
||||
timeCreated: 1605459681
|
@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort {
|
||||
public struct AlignParam {
|
||||
public readonly int tryCount;
|
||||
|
||||
public readonly float basicDistance;
|
||||
public readonly float nodeWidth;
|
||||
public readonly float nodeHeight;
|
||||
|
||||
public readonly float relationK;
|
||||
public readonly float relationNaturalLength;
|
||||
public readonly float repulsivePower;
|
||||
public readonly float threshold;
|
||||
|
||||
public AlignParam(int tryCount, float basicDistance, float nodeWidth, float nodeHeight,
|
||||
float relationK, float relationNaturalLength, float repulsivePower, float threshold) {
|
||||
this.tryCount = tryCount;
|
||||
this.basicDistance = basicDistance;
|
||||
this.nodeWidth = nodeWidth;
|
||||
this.nodeHeight = nodeHeight;
|
||||
this.relationK = relationK;
|
||||
this.relationNaturalLength = relationNaturalLength;
|
||||
this.repulsivePower = repulsivePower;
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
public static AlignParam Default() => new AlignParam(1000, 100, 600, 100, -0.01F, 300, 0.01F, 300.0F);
|
||||
}
|
||||
|
||||
public static class AlignParamEx {
|
||||
public static Vector2 接続したノード同士はばねによって引き合う(this AlignParam align, Vector2 target, Vector2 other) {
|
||||
var k = align.relationK;
|
||||
var nl = align.relationNaturalLength;
|
||||
|
||||
var l = (target - other).magnitude;
|
||||
var delta = l - nl;
|
||||
|
||||
return -(delta * k * (other - target).normalized);
|
||||
}
|
||||
public static Vector2 全ノードは互いに斥力が発生する(this AlignParam align, Vector2 target, Vector2 other) {
|
||||
var l = (other - target).magnitude;
|
||||
if (l < align.threshold)
|
||||
{
|
||||
return -(other - target).normalized * ((align.threshold - l) * align.repulsivePower);
|
||||
}
|
||||
return Vector2.zero;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 949ed302d4b143d3b3fea3039ec3f9e9
|
||||
timeCreated: 1605794098
|
@ -0,0 +1,59 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
//https://github.com/TORISOUP/AnimatorControllerLayouter/blob/master/Assets/TORISOUP/AnimatorControllerLayouter/Editor/LayoutHelper.cs
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort {
|
||||
public class AlignSortStrategy : ISortStrategy {
|
||||
readonly AlignParam alignParam;
|
||||
readonly Vector2 originPosition;
|
||||
|
||||
public AlignSortStrategy(AlignParam alignParam, Vector2 originPosition) {
|
||||
this.alignParam = alignParam;
|
||||
this.originPosition = originPosition;
|
||||
}
|
||||
|
||||
public IEnumerable<SortedNode> Sort(IEnumerable<IDependencyNode> nodes) {
|
||||
var nodeArr = nodes.ToArray();
|
||||
var posDict = nodeArr.ToDictionary(x => x.Profile, _ => originPosition);
|
||||
|
||||
// まず順番に整列させる
|
||||
nodeArr = nodeArr.OrderBy(x => x.Profile.Name).ToArray();
|
||||
var nodeGrid = new NodeGrid(alignParam.nodeWidth, alignParam.nodeHeight, alignParam.basicDistance, nodeArr.Length);
|
||||
for (var i = 0; i < nodeArr.Length; i++) {
|
||||
posDict[nodeArr[i].Profile] += nodeGrid.GridCenterPositions()[i];
|
||||
}
|
||||
|
||||
// ばねによる整列
|
||||
var tryCount = alignParam.tryCount;
|
||||
while (tryCount-- > 0) {
|
||||
foreach (var node in nodeArr) {
|
||||
var target = posDict[node.Profile];
|
||||
var force = Vector2.zero;
|
||||
foreach (var innerNode in nodeArr) {
|
||||
var other = posDict[innerNode.Profile];
|
||||
// ばねの計算
|
||||
if (node.IsConnectedTo(innerNode.Profile)) {
|
||||
force += alignParam.接続したノード同士はばねによって引き合う(target, other);
|
||||
}
|
||||
|
||||
force += alignParam.全ノードは互いに斥力が発生する(target, other);
|
||||
}
|
||||
|
||||
posDict[node.Profile] = target + force * 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// 接続数に応じて左右に移動させる
|
||||
// ref to が多いものが左に、ref by が多いものが右に
|
||||
const float factor = 60.0F;
|
||||
foreach (var dep in nodeArr) {
|
||||
var score = (dep.Sources.Count - dep.Destinations.Count) * factor;
|
||||
var p = posDict[dep.Profile];
|
||||
posDict[dep.Profile] = new Vector2(p.x + score, p.y);
|
||||
}
|
||||
|
||||
return posDict.Select(x => new SortedNode { Profile = x.Key, Position = x.Value });
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ebdb87d853042fd96657c9f78cec1a9
|
||||
timeCreated: 1605793928
|
@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor.Graphs;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort {
|
||||
public static class DependencyNodeExtensions {
|
||||
public static bool IsSourceEmpty(this IDependencyNode node) {
|
||||
return !node.Sources.Any();
|
||||
}
|
||||
public static bool IsDestinationEmpty(this IDependencyNode node) {
|
||||
return !node.Destinations.Any();
|
||||
}
|
||||
public static bool IsEmptyDependency(this IDependencyNode node) {
|
||||
return node.IsSourceEmpty() && node.IsDestinationEmpty();
|
||||
}
|
||||
public static int CountDependencies(this IDependencyNode node) {
|
||||
return node.Sources.Count + node.Destinations.Count;
|
||||
}
|
||||
public static bool ContainsSelfReference(this IDependencyNode node) {
|
||||
return node.Sources.Any(x => x == node.Profile) ||
|
||||
node.Destinations.Any(x => x == node.Profile);
|
||||
}
|
||||
public static IEnumerable<NodeProfile> ConnectedNodes(this IDependencyNode node) {
|
||||
return node.Sources.Concat(node.Destinations);
|
||||
}
|
||||
public static bool IsConnectedTo(this IDependencyNode node, NodeProfile nodeProfile) {
|
||||
return node.Sources.Contains(nodeProfile) || node.Destinations.Contains(nodeProfile);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d0cee1bf7d4c8c47a98a23879a257cb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort {
|
||||
public interface ISortStrategy {
|
||||
IEnumerable<SortedNode> Sort(IEnumerable<IDependencyNode> nodes);
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e2c63741aae4306aa49389ffdcb2e13
|
||||
timeCreated: 1605459681
|
@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort {
|
||||
public class LinerSortStrategy : ISortStrategy {
|
||||
readonly Vector2 originPosition;
|
||||
readonly float basicDistance;
|
||||
readonly float nodeWidth;
|
||||
readonly float nodeHeight;
|
||||
|
||||
public LinerSortStrategy(Vector2 originPosition, float basicDistance, float nodeWidth, float nodeHeight) {
|
||||
this.originPosition = originPosition;
|
||||
this.basicDistance = basicDistance;
|
||||
this.nodeWidth = nodeWidth;
|
||||
this.nodeHeight = nodeHeight;
|
||||
}
|
||||
|
||||
IEnumerable<SortedNode> ISortStrategy.Sort(IEnumerable<IDependencyNode> nodes) {
|
||||
var arr = nodes.ToArray();
|
||||
var posDict = arr
|
||||
.ToDictionary(x => x.Profile, _ => originPosition);
|
||||
// 参照元がないNodeを原点に
|
||||
var left = arr.FirstOrDefault(x => x.IsSourceEmpty());
|
||||
posDict[left.Profile] = originPosition;
|
||||
var right = arr.FirstOrDefault(x => x.Profile != left.Profile);
|
||||
posDict[right.Profile] = new Vector2(nodeWidth / 2.0F + basicDistance, 0.0F) + originPosition;
|
||||
return posDict.Select(x => new SortedNode { Profile = x.Key, Position = x.Value });
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d00de9a7b3041be922c457f9f53b1c0
|
||||
timeCreated: 1605459871
|
@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort {
|
||||
public class NodeGrid {
|
||||
public readonly float GridWidth;
|
||||
public readonly float GridHeight;
|
||||
public readonly float Distance;
|
||||
readonly int gridSideCount;
|
||||
public readonly int GridCount;
|
||||
|
||||
public NodeGrid(float nodeWidth, float nodeHeight, float nodeDistance, int nodeCount) {
|
||||
GridWidth = nodeWidth;
|
||||
GridHeight = nodeHeight;
|
||||
Distance = nodeDistance;
|
||||
gridSideCount = SquareValueProvider.ProvideNearestSquareValue(nodeCount);
|
||||
GridCount = gridSideCount * gridSideCount;
|
||||
}
|
||||
|
||||
public IReadOnlyList<Vector2> GridCenterPositions() {
|
||||
var grids = new Vector2[GridCount];
|
||||
var index = 0;
|
||||
var y = 0.0F;
|
||||
for (var i = 0; i < gridSideCount; i++) {
|
||||
var x = 0.0F;
|
||||
for (var j = 0; j < gridSideCount; j++) {
|
||||
grids[index] = new Vector2(x, y);
|
||||
x += (GridWidth/2.0F) + Distance;
|
||||
index++;
|
||||
}
|
||||
y += (GridHeight/2.0F) + Distance;;
|
||||
}
|
||||
return grids;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf9e7d3635b441398a2011b98e35610b
|
||||
timeCreated: 1605545271
|
@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort {
|
||||
public class RandomSortStrategy : ISortStrategy {
|
||||
readonly Vector2 originPosition;
|
||||
readonly float basicDistance;
|
||||
readonly float nodeWidth;
|
||||
readonly float nodeHeight;
|
||||
|
||||
public RandomSortStrategy(Vector2 originPosition, float basicDistance, float nodeWidth, float nodeHeight) {
|
||||
this.originPosition = originPosition;
|
||||
this.basicDistance = basicDistance;
|
||||
this.nodeWidth = nodeWidth;
|
||||
this.nodeHeight = nodeHeight;
|
||||
}
|
||||
public IEnumerable<SortedNode> Sort(IEnumerable<IDependencyNode> nodes) {
|
||||
var nodeArr = nodes
|
||||
.Select(x => new SortedNode { Profile = x.Profile, Position = originPosition })
|
||||
.ToArray();
|
||||
var nodeGrid = new NodeGrid(nodeWidth, nodeHeight, basicDistance, nodeArr.Length);
|
||||
var positions = nodeGrid.GridCenterPositions();
|
||||
var indexes = Enumerable.Range(0, positions.Count).ToList();
|
||||
|
||||
foreach (var node in nodeArr) {
|
||||
var randomIndex = indexes[Random.Range(0, indexes.Count)];
|
||||
node.Position = positions[randomIndex] + originPosition;
|
||||
indexes.Remove(randomIndex);
|
||||
}
|
||||
|
||||
return nodeArr;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f63fbb77026544bb82b0ddf7e2b507b0
|
||||
timeCreated: 1605544752
|
@ -0,0 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort {
|
||||
public class SortedNode {
|
||||
public NodeProfile Profile { set; get; }
|
||||
public Vector2 Position { set; get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c995f86b2ebe4c83ac65ec6727431ddb
|
||||
timeCreated: 1605459738
|
@ -0,0 +1,19 @@
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort {
|
||||
public static class SquareValueProvider {
|
||||
public static int ProvideNearestSquareValue(int count) {
|
||||
if (count < 1) return 0;
|
||||
if (count == 1) return 1;
|
||||
var value = 1;
|
||||
while (value < 100) {
|
||||
var square = value * value;
|
||||
var nextValue = value + 1;
|
||||
var nextSquare = nextValue * nextValue;
|
||||
value = nextValue;
|
||||
if (square <= count && count <= nextSquare) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8521b362be64b7eb1bcf8174be0ecf8
|
||||
timeCreated: 1605545553
|
@ -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
|
@ -1,5 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9fc0d4010bbf28b4594072e72b8655ab
|
||||
guid: 317ec7aeddbdec848819fcfcfcb8becb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
@ -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
|
@ -0,0 +1,5 @@
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.NodeView {
|
||||
public interface INodeView : IRect, IVisible {
|
||||
string Label { set; get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95c599809404452380ee0c65390284e4
|
||||
timeCreated: 1605457329
|
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
|
23
Assets/AsmdefHelper/DependencyGraph/Editor/NodeView/IRect.cs
Normal file
23
Assets/AsmdefHelper/DependencyGraph/Editor/NodeView/IRect.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.NodeView {
|
||||
public interface IRect {
|
||||
float PositionX { set; get; }
|
||||
float PositionY { set; get; }
|
||||
float Height { get; }
|
||||
float Width { get; }
|
||||
}
|
||||
|
||||
public static class ViewExtension {
|
||||
public static Vector2 GetPositionXY(this IRect rect) {
|
||||
return new Vector2(rect.PositionX, rect.PositionY);
|
||||
}
|
||||
public static void SetPositionXY(this IRect rect, Vector2 pos) {
|
||||
rect.PositionX = pos.x;
|
||||
rect.PositionY = pos.y;
|
||||
}
|
||||
public static Rect AsRect(this IRect rect) {
|
||||
return new Rect(rect.PositionX, rect.PositionY, rect.Width, rect.Height);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ba20ae9f4964efaa46e9fd6f83dd819
|
||||
timeCreated: 1605458617
|
@ -0,0 +1,5 @@
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.NodeView {
|
||||
public interface IVisible {
|
||||
bool Visibility { set; get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aecb56b3d2f84f408ad0aff39ba9e24c
|
||||
timeCreated: 1606396097
|
@ -0,0 +1,31 @@
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.NodeView {
|
||||
public class UiElementsNodeView : Node, INodeView {
|
||||
|
||||
public string Label {
|
||||
get => title;
|
||||
set => title = value;
|
||||
}
|
||||
|
||||
public float PositionX {
|
||||
get => transform.position.x;
|
||||
set => transform.position = new Vector3(value, PositionY, transform.position.z);
|
||||
}
|
||||
|
||||
public float PositionY {
|
||||
get => transform.position.y;
|
||||
set => transform.position = new Vector3(PositionX, value, transform.position.z);
|
||||
}
|
||||
|
||||
public float Height => contentRect.height;
|
||||
|
||||
public float Width => contentRect.width;
|
||||
|
||||
public virtual bool Visibility {
|
||||
get => visible;
|
||||
set => visible = value;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc7014a6a7494dbcbc43466c7dbcdffa
|
||||
timeCreated: 1605457452
|
3
Assets/AsmdefHelper/DependencyGraph/Editor/Tests.meta
Normal file
3
Assets/AsmdefHelper/DependencyGraph/Editor/Tests.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8119c430aef94628a88162f0f2dede2c
|
||||
timeCreated: 1606663500
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "AsmdefHelper.SyncSolution.Editor",
|
||||
{
|
||||
"name": "AsmdefHelper.DependencyGraph.Editor.Tests",
|
||||
"references": [
|
||||
"GUID:211243abc45174c45b3a6c275ea126b9"
|
||||
"GUID:53e113411e7b0e947975fcd498b539aa"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
@ -10,7 +10,7 @@
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcfd308825181f346bc76cac8ae79330
|
||||
guid: 5b1e278775093cb40af4ebe716362ac9
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
@ -0,0 +1,57 @@
|
||||
using System.Collections;
|
||||
using AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine.TestTools;
|
||||
using AsmdefHelper.DependencyGraph.Editor.DependencyNode;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.Tests {
|
||||
public class DependencyNodeExtensionsTest {
|
||||
|
||||
[SetUp]
|
||||
public void SetUpBeforeEveryTest() {
|
||||
Nodes.Init();
|
||||
// [0]--->[1]--->[2]<---[3] [4]
|
||||
Nodes._0.SetRequireNodes(new[] { Profiles._1 });
|
||||
Nodes._1.SetRequireNodes(new[] { Profiles._2 });
|
||||
Nodes._3.SetRequireNodes(new[] { Profiles._2 });
|
||||
NodeProcessor.SetBeRequiredNodes(new[] { Nodes._0, Nodes._1, Nodes._2, Nodes._3, Nodes._4 });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIsSourceEmpty() {
|
||||
Assert.That(Nodes._0.IsSourceEmpty(), Is.True);
|
||||
Assert.That(Nodes._1.IsSourceEmpty(), Is.False);
|
||||
Assert.That(Nodes._2.IsSourceEmpty(), Is.False);
|
||||
Assert.That(Nodes._3.IsSourceEmpty(), Is.True);
|
||||
Assert.That(Nodes._4.IsSourceEmpty(), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIsDestinationEmpty() {
|
||||
Assert.That(Nodes._0.IsDestinationEmpty(), Is.False);
|
||||
Assert.That(Nodes._1.IsDestinationEmpty(), Is.False);
|
||||
Assert.That(Nodes._2.IsDestinationEmpty(), Is.True);
|
||||
Assert.That(Nodes._3.IsDestinationEmpty(), Is.False);
|
||||
Assert.That(Nodes._4.IsDestinationEmpty(), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIsEmptyDependency() {
|
||||
Assert.That(Nodes._0.IsEmptyDependency(), Is.False);
|
||||
Assert.That(Nodes._1.IsEmptyDependency(), Is.False);
|
||||
Assert.That(Nodes._2.IsEmptyDependency(), Is.False);
|
||||
Assert.That(Nodes._3.IsEmptyDependency(), Is.False);
|
||||
Assert.That(Nodes._4.IsEmptyDependency(), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCountDependencies() {
|
||||
Assert.That(Nodes._0.CountDependencies(), Is.EqualTo(1));
|
||||
Assert.That(Nodes._1.CountDependencies(), Is.EqualTo(2));
|
||||
Assert.That(Nodes._2.CountDependencies(), Is.EqualTo(2));
|
||||
Assert.That(Nodes._3.CountDependencies(), Is.EqualTo(1));
|
||||
Assert.That(Nodes._4.CountDependencies(), Is.EqualTo(0));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95cc92d669584f4bacd5faf7b1e78320
|
||||
timeCreated: 1605543283
|
@ -0,0 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using AsmdefHelper.DependencyGraph.Editor.DependencyNode;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.Tests {
|
||||
public class DomainGroupTest {
|
||||
|
||||
readonly string[] inputs ={
|
||||
"unity.hoge",
|
||||
"unity.fuga",
|
||||
"unity.foo.bar",
|
||||
"UniRx",
|
||||
"UniRx.Async",
|
||||
"zenject",
|
||||
"zenject-test-framework",
|
||||
"MyAsmdef",
|
||||
"MyAsmdef2_Test",
|
||||
"MyAsmdef3.hoge",
|
||||
"MyAsmdef3-hoge",
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void TestDomainGroup() {
|
||||
var group = new DomainGroup();
|
||||
group.Create(inputs);
|
||||
Assert.That(group.GetTopDomains().Count(), Is.EqualTo(6));
|
||||
Assert.That(group.GetSubDomains("unity").Count(), Is.EqualTo(3));
|
||||
Assert.That(group.GetSubDomains("UniRx").Count(), Is.EqualTo(2));
|
||||
Assert.That(group.GetSubDomains("zenject").Count(), Is.EqualTo(2));
|
||||
Assert.That(group.GetSubDomains("MyAsmdef").Count(), Is.EqualTo(1));
|
||||
Assert.That(group.GetSubDomains("MyAsmdef2_Test").Count(), Is.EqualTo(1));
|
||||
Assert.That(group.GetSubDomains("MyAsmdef3").Count(), Is.EqualTo(2));
|
||||
|
||||
Assert.That(group.GetTopDomainsWithSomeSubDomains().Count(), Is.EqualTo(4));
|
||||
Assert.That(group.GetSoloDomains().Count(), Is.EqualTo(2));
|
||||
|
||||
Assert.That(group.GetSubDomains("unity").Any(x => x.SubDomain == "hoge"), Is.True);
|
||||
Assert.That(group.GetSubDomains("unity").Any(x => x.SubDomain == "fuga"), Is.True);
|
||||
Assert.That(group.GetSubDomains("unity").Any(x => x.SubDomain == "foo.bar"), Is.True);
|
||||
Assert.That(group.GetSubDomains("UniRx").Any(x => x.SubDomain == ""), Is.True);
|
||||
Assert.That(group.GetSubDomains("UniRx").Any(x => x.SubDomain == "Async"), Is.True);
|
||||
Assert.That(group.GetSubDomains("zenject").Any(x => x.SubDomain == ""), Is.True);
|
||||
Assert.That(group.GetSubDomains("zenject").Any(x => x.SubDomain == "test-framework"), Is.True);
|
||||
Assert.That(group.GetSubDomains("MyAsmdef").Any(x => x.SubDomain == ""), Is.True);
|
||||
Assert.That(group.GetSubDomains("MyAsmdef2_Test").Any(x => x.SubDomain == ""), Is.True);
|
||||
Assert.That(group.GetSubDomains("MyAsmdef3").Any(x => x.SubDomain == "hoge"), Is.True);
|
||||
Assert.That(group.GetSubDomains("MyAsmdef3").Count(x => x.SubDomain == "hoge"), Is.EqualTo(2));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ccc87caf20a4985a4e3c94bfc1c12c6
|
||||
timeCreated: 1606660230
|
@ -0,0 +1,73 @@
|
||||
using System.Collections;
|
||||
using AsmdefHelper.DependencyGraph.Editor.DependencyNode;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.Tests {
|
||||
public class DomainUnitTest {
|
||||
|
||||
[Test]
|
||||
public void TestDomainUnit_HasTopDomain() {
|
||||
var unit = new DomainUnit("abc.def.ghi.jk", '.');
|
||||
Assert.That(unit.FullName, Is.EqualTo("abc.def.ghi.jk"));
|
||||
Assert.That(unit.TopDomain, Is.EqualTo("abc"));
|
||||
Assert.That(unit.SubDomain, Is.EqualTo("def.ghi.jk"));
|
||||
Assert.That(unit.HasSubDomain, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDomainUnit_HasNoTopDomain() {
|
||||
var unit = new DomainUnit("abcdefghijk", '.');
|
||||
Assert.That(unit.FullName, Is.EqualTo("abcdefghijk"));
|
||||
Assert.That(unit.TopDomain, Is.EqualTo("abcdefghijk"));
|
||||
Assert.That(unit.SubDomain, Is.Empty);
|
||||
Assert.That(unit.HasSubDomain, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDomainUnit_StartWithSeparator() {
|
||||
var unit = new DomainUnit(".abc", '.');
|
||||
Assert.That(unit.FullName, Is.EqualTo(".abc"));
|
||||
Assert.That(unit.TopDomain, Is.EqualTo("abc"));
|
||||
Assert.That(unit.SubDomain, Is.Empty);
|
||||
Assert.That(unit.HasSubDomain, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDomainUnit_EndWithSeparator() {
|
||||
var unit = new DomainUnit("abc.", '.');
|
||||
Assert.That(unit.FullName, Is.EqualTo("abc."));
|
||||
Assert.That(unit.TopDomain, Is.EqualTo("abc"));
|
||||
Assert.That(unit.SubDomain, Is.Empty);
|
||||
Assert.That(unit.HasSubDomain, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDomainUnit_StartAndEndWithSeparator() {
|
||||
var unit = new DomainUnit(".abc.def.", '.');
|
||||
Assert.That(unit.FullName, Is.EqualTo(".abc.def."));
|
||||
Assert.That(unit.TopDomain, Is.EqualTo("abc"));
|
||||
Assert.That(unit.SubDomain, Is.EqualTo("def"));
|
||||
Assert.That(unit.HasSubDomain, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDomainUnit_OnlySeparator() {
|
||||
var unit = new DomainUnit(".", '.');
|
||||
Assert.That(unit.FullName, Is.EqualTo("."));
|
||||
Assert.That(unit.TopDomain, Is.Empty);
|
||||
Assert.That(unit.SubDomain, Is.Empty);
|
||||
Assert.That(unit.HasSubDomain, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDomainUnit_OnlySeparators() {
|
||||
var unit = new DomainUnit("...", '.');
|
||||
Assert.That(unit.FullName, Is.EqualTo("..."));
|
||||
Assert.That(unit.TopDomain, Is.Empty);
|
||||
Assert.That(unit.SubDomain, Is.Empty);
|
||||
Assert.That(unit.HasSubDomain, Is.False);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ecc6823b62f94fd3a910f5a885a201dc
|
||||
timeCreated: 1606658361
|
@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using AsmdefHelper.DependencyGraph.Editor.DependencyNode;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.Tests {
|
||||
public class HashSetDependencyNodeTest {
|
||||
|
||||
[Test]
|
||||
public void TestHashSetDependencyNode() {
|
||||
var node = new HashSetDependencyNode(new NodeProfile(new NodeId(1), "node"));
|
||||
Assert.That(node, Is.InstanceOf<IDependencyNode>());
|
||||
Assert.That(node.Profile.Id.value, Is.EqualTo(1));
|
||||
Assert.That(node.Profile.Name, Is.EqualTo("node"));
|
||||
Assert.That(node.Sources, Is.Empty);
|
||||
Assert.That(node.Destinations, Is.Empty);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd573c4b7c3d450da36047e4e1e03824
|
||||
timeCreated: 1605450304
|
@ -0,0 +1,43 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using AsmdefHelper.DependencyGraph.Editor.DependencyNode;
|
||||
using AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.Tests {
|
||||
public class LinerSortStrategyTest {
|
||||
const float d = 10.0F;
|
||||
const float w = 10.0F;
|
||||
const float h = 10.0F;
|
||||
const float e = 0.0001F;
|
||||
ISortStrategy sortStrategy;
|
||||
|
||||
[SetUp]
|
||||
public void SetUpBeforeEveryTest() {
|
||||
Nodes.Init();
|
||||
sortStrategy = new LinerSortStrategy(Vector2.zero, d, w, h);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLinerNodeDependency() {
|
||||
var nodes = new[] { Nodes._0, Nodes._1 };
|
||||
// [0]--->[1]
|
||||
Nodes._0.SetRequireNodes(new[] { Profiles._1});
|
||||
NodeProcessor.SetBeRequiredNodes(nodes);
|
||||
|
||||
var result = sortStrategy.Sort(nodes).ToArray();
|
||||
var node0 = result.FirstOrDefault(x => x.Profile == Profiles._0);
|
||||
var node1 = result.FirstOrDefault(x => x.Profile == Profiles._1);
|
||||
|
||||
Assert.That(node0, Is.Not.Null);
|
||||
Assert.That(node0.Position.x, Is.Zero);
|
||||
Assert.That(node0.Position.y, Is.Zero);
|
||||
Assert.That(node1, Is.Not.Null);
|
||||
Assert.That(node1.Position.x, Is.EqualTo(node0.Position.x + d + (w / 2.0F)).Within(e));
|
||||
Assert.That(node1.Position.y, Is.EqualTo(node0.Position.y).Within(e));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ecac0d687a574143a409b043040ce933
|
||||
timeCreated: 1605460235
|
@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using AsmdefHelper.DependencyGraph.Editor.DependencyNode.Sort;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.Tests {
|
||||
public class NodeGridTest {
|
||||
|
||||
[Test]
|
||||
public void TestNodeGrid() {
|
||||
const float e = 0.000001F;
|
||||
var nodeGrid = new NodeGrid(10.0F, 10.0F, 10.0F, 4);
|
||||
Assert.That(nodeGrid.GridCount, Is.EqualTo(4));
|
||||
var grids = nodeGrid.GridCenterPositions();
|
||||
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[1].x, Is.EqualTo(15.0F).Within(e));
|
||||
Assert.That(grids[1].y, Is.EqualTo(0.0F).Within(e));
|
||||
Assert.That(grids[2].x, Is.EqualTo(0.0F).Within(e));
|
||||
Assert.That(grids[2].y, Is.EqualTo(15.0F).Within(e));
|
||||
Assert.That(grids[3].x, Is.EqualTo(15.0F).Within(e));
|
||||
Assert.That(grids[3].y, Is.EqualTo(15.0F).Within(e));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43541e9cd66e4df59c2cac11ada769fe
|
||||
timeCreated: 1605546997
|
@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using AsmdefHelper.DependencyGraph.Editor.DependencyNode;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.Tests {
|
||||
public class NodeIdTest {
|
||||
[Test]
|
||||
public void TestNodeIdValue() {
|
||||
var nodeId = new NodeId(123);
|
||||
Assert.That(nodeId.value, Is.EqualTo(123));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestNodeIdEquals() {
|
||||
var id1 = new NodeId(111);
|
||||
var id2 = new NodeId(222);
|
||||
var id3 = new NodeId(111);
|
||||
Assert.That(id1, Is.EqualTo(id1));
|
||||
Assert.That(id1, Is.Not.EqualTo(id2));
|
||||
Assert.That(id1, Is.EqualTo(id3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestNodeIdToString() {
|
||||
var nodeId = new NodeId(999);
|
||||
Assert.That(nodeId.ToString(), Is.EqualTo("999"));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 946cb4c27532a5848a9cf8c9dea05df8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,92 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using AsmdefHelper.DependencyGraph.Editor.DependencyNode;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.Tests {
|
||||
public class NodeProcessorTest {
|
||||
|
||||
[SetUp]
|
||||
public void SetUpBeforeEveryTest() {
|
||||
Nodes.Init();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSetRequireNodes() {
|
||||
var node = new HashSetDependencyNode(new NodeProfile(new NodeId(0), "node0"));
|
||||
var p1 = new NodeProfile(new NodeId(1), "node1");
|
||||
var p2 = new NodeProfile(new NodeId(2), "node2");
|
||||
var p3 = new NodeProfile(new NodeId(3), "node3");
|
||||
node.Sources.Add(p3);
|
||||
node.SetRequireNodes(new[] { p1, p2 });
|
||||
Assert.That(node.Destinations.Count, Is.EqualTo(2));
|
||||
Assert.That(node.Destinations.Any(x => x.Equals(p1)));
|
||||
Assert.That(node.Destinations.Any(x => x.Equals(p2)));
|
||||
Assert.That(node.Sources.Count, Is.Zero);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLinerNodeDependency() {
|
||||
// [0]--->[1]
|
||||
Nodes._0.SetRequireNodes(new[] { Profiles._1});
|
||||
NodeProcessor.SetBeRequiredNodes(new[] { Nodes._0, Nodes._1 });
|
||||
Assert.That(Nodes._1.Sources.Any(x => x.Equals(Profiles._0)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSomeNodeDependency() {
|
||||
Nodes.SetSomeNodeDependency();
|
||||
NodeProcessor.SetBeRequiredNodes(Nodes.All);
|
||||
// 0
|
||||
Assert.That(Nodes._0.Sources, Is.Empty);
|
||||
Assert.That(Nodes._0.Destinations.Count, Is.EqualTo(2));
|
||||
Assert.That(Nodes._0.Destinations.Any(x => x == Profiles._1));
|
||||
Assert.That(Nodes._0.Destinations.Any(x => x == Profiles._2));
|
||||
// 1
|
||||
Assert.That(Nodes._1.Destinations.Count, Is.EqualTo(1));
|
||||
Assert.That(Nodes._1.Sources.Any(x => x == Profiles._0));
|
||||
Assert.That(Nodes._1.Destinations.Count, Is.EqualTo(1));
|
||||
Assert.That(Nodes._1.Destinations.Any(x => x == Profiles._4));
|
||||
// 2
|
||||
Assert.That(Nodes._2.Sources.Count, Is.EqualTo(1));
|
||||
Assert.That(Nodes._2.Sources.Any(x => x == Profiles._0));
|
||||
Assert.That(Nodes._2.Destinations.Count, Is.EqualTo(2));
|
||||
Assert.That(Nodes._2.Destinations.Any(x => x == Profiles._3));
|
||||
Assert.That(Nodes._2.Destinations.Any(x => x == Profiles._4));
|
||||
// 3
|
||||
Assert.That(Nodes._3.Sources.Count, Is.EqualTo(2));
|
||||
Assert.That(Nodes._3.Sources.Any(x => x == Profiles._2));
|
||||
Assert.That(Nodes._3.Sources.Any(x => x == Profiles._5));
|
||||
Assert.That(Nodes._3.Destinations, Is.Empty);
|
||||
// 4
|
||||
Assert.That(Nodes._4.Sources.Count, Is.EqualTo(2));
|
||||
Assert.That(Nodes._4.Sources.Any(x => x == Profiles._1));
|
||||
Assert.That(Nodes._4.Sources.Any(x => x == Profiles._2));
|
||||
Assert.That(Nodes._4.Destinations.Count, Is.EqualTo(1));
|
||||
Assert.That(Nodes._4.Destinations.Any(x => x == Profiles._5));
|
||||
// 5
|
||||
Assert.That(Nodes._5.Sources.Count, Is.EqualTo(1));
|
||||
Assert.That(Nodes._5.Sources.Any(x => x == Profiles._4));
|
||||
Assert.That(Nodes._5.Destinations.Count, Is.EqualTo(2));
|
||||
Assert.That(Nodes._5.Destinations.Any(x => x == Profiles._3));
|
||||
Assert.That(Nodes._5.Destinations.Any(x => x == Profiles._6));
|
||||
// 6
|
||||
Assert.That(Nodes._6.Sources.Count, Is.EqualTo(1));
|
||||
Assert.That(Nodes._6.Sources.Any(x => x == Profiles._5));
|
||||
Assert.That(Nodes._6.Destinations, Is.Empty);
|
||||
// 7
|
||||
Assert.That(Nodes._7.Sources, Is.Empty);
|
||||
Assert.That(Nodes._7.Destinations.Count, Is.EqualTo(1));
|
||||
Assert.That(Nodes._7.Destinations.Any(x => x == Profiles._8));
|
||||
// 8
|
||||
Assert.That(Nodes._8.Sources.Count, Is.EqualTo(1));
|
||||
Assert.That(Nodes._8.Sources.Any(x => x == Profiles._7));
|
||||
Assert.That(Nodes._8.Destinations, Is.Empty);
|
||||
// 9
|
||||
Assert.That(Nodes._9.Sources, Is.Empty);
|
||||
Assert.That(Nodes._9.Destinations, Is.Empty);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e86a8d93f3a4bb5a7c6d81b775efb47
|
||||
timeCreated: 1605450647
|
@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine.TestTools;
|
||||
using AsmdefHelper.DependencyGraph.Editor.DependencyNode;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.Tests {
|
||||
public class NodeProfileTest {
|
||||
|
||||
[Test]
|
||||
public void TestNodeProfile() {
|
||||
var nodeProfile = new NodeProfile(new NodeId(123), "testNode");
|
||||
Assert.That(nodeProfile.Id.value, Is.EqualTo(123));
|
||||
Assert.That(nodeProfile.Name, Is.EqualTo("testNode"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestNodeProfileEquals() {
|
||||
var profile1 = new NodeProfile(new NodeId(111), "testNode1");
|
||||
var profile2 = new NodeProfile(new NodeId(222), "testNode1");
|
||||
var profile3 = new NodeProfile(new NodeId(111), "testNode2");
|
||||
var profile4 = new NodeProfile(new NodeId(111), "testNode1");
|
||||
Assert.That(profile1, Is.EqualTo(profile1));
|
||||
Assert.That(profile1, Is.Not.EqualTo(profile2));
|
||||
Assert.That(profile1, Is.Not.EqualTo(profile3));
|
||||
Assert.That(profile1, Is.EqualTo(profile4));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestNodeProfileName() {
|
||||
var nodeProfile = new NodeProfile(new NodeId(123), "hoge");
|
||||
nodeProfile.Name = "testNode";
|
||||
Assert.That(nodeProfile.Name, Is.EqualTo("testNode"));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6550a73c9df44f0092949ddd3ea5ac06
|
||||
timeCreated: 1605448488
|
72
Assets/AsmdefHelper/DependencyGraph/Editor/Tests/Nodes.cs
Normal file
72
Assets/AsmdefHelper/DependencyGraph/Editor/Tests/Nodes.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using AsmdefHelper.DependencyGraph.Editor.DependencyNode;
|
||||
|
||||
namespace AsmdefHelper.DependencyGraph.Editor.Tests {
|
||||
|
||||
public static class Ids {
|
||||
public static readonly NodeId _0 = new NodeId(0);
|
||||
public static readonly NodeId _1 = new NodeId(1);
|
||||
public static readonly NodeId _2 = new NodeId(2);
|
||||
public static readonly NodeId _3 = new NodeId(3);
|
||||
public static readonly NodeId _4 = new NodeId(4);
|
||||
public static readonly NodeId _5 = new NodeId(5);
|
||||
public static readonly NodeId _6 = new NodeId(6);
|
||||
public static readonly NodeId _7 = new NodeId(7);
|
||||
public static readonly NodeId _8 = new NodeId(8);
|
||||
public static readonly NodeId _9 = new NodeId(9);
|
||||
}
|
||||
public static class Profiles {
|
||||
public static readonly NodeProfile _0 = new NodeProfile(Ids._0, "node0");
|
||||
public static readonly NodeProfile _1 = new NodeProfile(Ids._1, "node1");
|
||||
public static readonly NodeProfile _2 = new NodeProfile(Ids._2, "node2");
|
||||
public static readonly NodeProfile _3 = new NodeProfile(Ids._3, "node3");
|
||||
public static readonly NodeProfile _4 = new NodeProfile(Ids._4, "node4");
|
||||
public static readonly NodeProfile _5 = new NodeProfile(Ids._5, "node5");
|
||||
public static readonly NodeProfile _6 = new NodeProfile(Ids._6, "node6");
|
||||
public static readonly NodeProfile _7 = new NodeProfile(Ids._7, "node7");
|
||||
public static readonly NodeProfile _8 = new NodeProfile(Ids._8, "node8");
|
||||
public static readonly NodeProfile _9 = new NodeProfile(Ids._9, "node9");
|
||||
}
|
||||
public static class Nodes {
|
||||
public static readonly IDependencyNode _0 = new HashSetDependencyNode(Profiles._0);
|
||||
public static readonly IDependencyNode _1 = new HashSetDependencyNode(Profiles._1);
|
||||
public static readonly IDependencyNode _2 = new HashSetDependencyNode(Profiles._2);
|
||||
public static readonly IDependencyNode _3 = new HashSetDependencyNode(Profiles._3);
|
||||
public static readonly IDependencyNode _4 = new HashSetDependencyNode(Profiles._4);
|
||||
public static readonly IDependencyNode _5 = new HashSetDependencyNode(Profiles._5);
|
||||
public static readonly IDependencyNode _6 = new HashSetDependencyNode(Profiles._6);
|
||||
public static readonly IDependencyNode _7 = new HashSetDependencyNode(Profiles._7);
|
||||
public static readonly IDependencyNode _8 = new HashSetDependencyNode(Profiles._8);
|
||||
public static readonly IDependencyNode _9 = new HashSetDependencyNode(Profiles._9);
|
||||
|
||||
public static readonly IEnumerable<IDependencyNode> All = new[] {
|
||||
_0, _1, _2, _3, _4, _5, _6, _7, _8, _9
|
||||
};
|
||||
|
||||
public static void Init() {
|
||||
foreach (var n in All) {
|
||||
n.Sources.Clear();
|
||||
n.Destinations.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetSomeNodeDependency() {
|
||||
/*
|
||||
* ┌->[1]-┐
|
||||
* [0]-┴->[2]-┴->[4]--->[5]--->[6]
|
||||
* │ │
|
||||
* V │
|
||||
* [3]<-----------┘
|
||||
*
|
||||
* [7]--->[8] [9]
|
||||
*
|
||||
*/
|
||||
Nodes._0.SetRequireNodes(new[] { Profiles._1, Profiles._2 });
|
||||
Nodes._1.SetRequireNodes(new[] { Profiles._4 });
|
||||
Nodes._2.SetRequireNodes(new[] { Profiles._3, Profiles._4 });
|
||||
Nodes._4.SetRequireNodes(new[] { Profiles._5 });
|
||||
Nodes._5.SetRequireNodes(new[] { Profiles._3, Profiles._6 });
|
||||
Nodes._7.SetRequireNodes(new[] { Profiles._8 });
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55ca469364f847a4827a9f2ed13c7ef4
|
||||
timeCreated: 1605451653
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user