Thomas ICHÉ
6 年前
当前提交
8c666b84
共有 131 个文件被更改,包括 3307 次插入 和 1 次删除
-
4Editor/GameplayIngredients-Editor.asmdef
-
63Editor/HiearchyItems.cs
-
11Editor/HiearchyItems.cs.meta
-
8NodeGraphProcessor.meta
-
8NodeGraphProcessor/Editor.meta
-
81NodeGraphProcessor/Editor/BaseGraphWindow.cs
-
11NodeGraphProcessor/Editor/BaseGraphWindow.cs.meta
-
8NodeGraphProcessor/Editor/Callbacks.meta
-
93NodeGraphProcessor/Editor/Callbacks/NodeScriptCreation.cs
-
11NodeGraphProcessor/Editor/Callbacks/NodeScriptCreation.cs.meta
-
22NodeGraphProcessor/Editor/Callbacks/NodeTemplate.cs.txt
-
7NodeGraphProcessor/Editor/Callbacks/NodeTemplate.cs.txt.meta
-
21NodeGraphProcessor/Editor/Callbacks/NodeViewTemplate.cs.txt
-
7NodeGraphProcessor/Editor/Callbacks/NodeViewTemplate.cs.txt.meta
-
26NodeGraphProcessor/Editor/Callbacks/OnBaseGraphDeleted.cs
-
11NodeGraphProcessor/Editor/Callbacks/OnBaseGraphDeleted.cs.meta
-
19NodeGraphProcessor/Editor/EditorAttributes.cs
-
11NodeGraphProcessor/Editor/EditorAttributes.cs.meta
-
8NodeGraphProcessor/Editor/Logic.meta
-
60NodeGraphProcessor/Editor/Logic/EdgeConnectorListener.cs
-
11NodeGraphProcessor/Editor/Logic/EdgeConnectorListener.cs.meta
-
8NodeGraphProcessor/Editor/Manipulators.meta
-
125NodeGraphProcessor/Editor/Manipulators/BorderResizer.cs
-
11NodeGraphProcessor/Editor/Manipulators/BorderResizer.cs.meta
-
75NodeGraphProcessor/Editor/Manipulators/ConfinedDragger.cs
-
11NodeGraphProcessor/Editor/Manipulators/ConfinedDragger.cs.meta
-
8NodeGraphProcessor/Editor/PortBehaviors.meta
-
19NodeGraphProcessor/Editor/PortBehaviors/DefaultPortBehavior.cs
-
11NodeGraphProcessor/Editor/PortBehaviors/DefaultPortBehavior.cs.meta
-
98NodeGraphProcessor/Editor/PortBehaviors/MultiPortBehavior.cs
-
11NodeGraphProcessor/Editor/PortBehaviors/MultiPortBehavior.cs.meta
-
41NodeGraphProcessor/Editor/PortBehaviors/PortBehaviorFactory.cs
-
11NodeGraphProcessor/Editor/PortBehaviors/PortBehaviorFactory.cs.meta
-
8NodeGraphProcessor/Editor/Resources.meta
-
8NodeGraphProcessor/Editor/Resources/GraphProcessorStyles.meta
-
4NodeGraphProcessor/Editor/Resources/GraphProcessorStyles/BaseGraphView.uss
-
10NodeGraphProcessor/Editor/Resources/GraphProcessorStyles/BaseGraphView.uss.meta
-
7NodeGraphProcessor/Editor/Resources/GraphProcessorStyles/BaseNodeView.uss
-
10NodeGraphProcessor/Editor/Resources/GraphProcessorStyles/BaseNodeView.uss.meta
-
4NodeGraphProcessor/Editor/Resources/GraphProcessorStyles/CommentBlockView.uss
-
10NodeGraphProcessor/Editor/Resources/GraphProcessorStyles/CommentBlockView.uss.meta
-
3NodeGraphProcessor/Editor/Resources/GraphProcessorStyles/EdgeView.uss
-
10NodeGraphProcessor/Editor/Resources/GraphProcessorStyles/EdgeView.uss.meta
-
50NodeGraphProcessor/Editor/Resources/GraphProcessorStyles/PinnedElementView.uss
-
10NodeGraphProcessor/Editor/Resources/GraphProcessorStyles/PinnedElementView.uss.meta
-
50NodeGraphProcessor/Editor/Resources/GraphProcessorStyles/PortView.uss
-
10NodeGraphProcessor/Editor/Resources/GraphProcessorStyles/PortView.uss.meta
-
8NodeGraphProcessor/Editor/Utils.meta
-
14NodeGraphProcessor/Editor/Utils/CopyPasteHelper.cs
-
11NodeGraphProcessor/Editor/Utils/CopyPasteHelper.cs.meta
-
114NodeGraphProcessor/Editor/Utils/FieldFactory.cs
-
11NodeGraphProcessor/Editor/Utils/FieldFactory.cs.meta
-
102NodeGraphProcessor/Editor/Utils/NodeProvider.cs
-
11NodeGraphProcessor/Editor/Utils/NodeProvider.cs.meta
-
8NodeGraphProcessor/Editor/Views.meta
-
585NodeGraphProcessor/Editor/Views/BaseGraphView.cs
-
11NodeGraphProcessor/Editor/Views/BaseGraphView.cs.meta
-
245NodeGraphProcessor/Editor/Views/BaseNodeView.cs
-
11NodeGraphProcessor/Editor/Views/BaseNodeView.cs.meta
-
98NodeGraphProcessor/Editor/Views/CommentBlockView.cs
-
11NodeGraphProcessor/Editor/Views/CommentBlockView.cs.meta
-
17NodeGraphProcessor/Editor/Views/EdgeView.cs
-
11NodeGraphProcessor/Editor/Views/EdgeView.cs.meta
-
22NodeGraphProcessor/Editor/Views/MiniMapView.cs
-
11NodeGraphProcessor/Editor/Views/MiniMapView.cs.meta
-
58NodeGraphProcessor/Editor/Views/PinnedElementView.cs
-
11NodeGraphProcessor/Editor/Views/PinnedElementView.cs.meta
-
99NodeGraphProcessor/Editor/Views/PortView.cs
-
11NodeGraphProcessor/Editor/Views/PortView.cs.meta
-
36NodeGraphProcessor/Editor/Views/ProcessorView.cs
-
11NodeGraphProcessor/Editor/Views/ProcessorView.cs.meta
-
101NodeGraphProcessor/Editor/Views/ToolbarView.cs
-
11NodeGraphProcessor/Editor/Views/ToolbarView.cs.meta
-
16NodeGraphProcessor/Editor/com.alelievr.NodeGraphProcessor-Editor.asmdef
-
7NodeGraphProcessor/Editor/com.alelievr.NodeGraphProcessor-Editor.asmdef.meta
-
21NodeGraphProcessor/LICENSE
-
7NodeGraphProcessor/LICENSE.meta
-
8NodeGraphProcessor/Runtime.meta
-
8NodeGraphProcessor/Runtime/Elements.meta
-
216NodeGraphProcessor/Runtime/Elements/BaseNode.cs
-
11NodeGraphProcessor/Runtime/Elements/BaseNode.cs.meta
-
29NodeGraphProcessor/Runtime/Elements/CommentBlock.cs
-
11NodeGraphProcessor/Runtime/Elements/CommentBlock.cs.meta
-
161NodeGraphProcessor/Runtime/Elements/NodePort.cs
-
11NodeGraphProcessor/Runtime/Elements/NodePort.cs.meta
-
20NodeGraphProcessor/Runtime/Elements/PinnedElement.cs
-
11NodeGraphProcessor/Runtime/Elements/PinnedElement.cs.meta
-
8NodeGraphProcessor/Runtime/Graph.meta
|
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
|
|||
namespace GameplayIngredients |
|||
{ |
|||
static class HiearchyItems |
|||
{ |
|||
#region TRIGGERS
|
|||
|
|||
[MenuItem("GameObject/GameplayIngredients/Hooks/Trigger (Box)", false, 10)] |
|||
static void CreateTriggerBox() |
|||
{ |
|||
var go = new GameObject(); |
|||
var col = go.AddComponent<BoxCollider>(); |
|||
col.isTrigger = true; |
|||
var hook = go.AddComponent<Hooks.OnTriggerHook>(); |
|||
go.name = "Box Trigger"; |
|||
|
|||
if (Selection.activeGameObject != null) |
|||
go.transform.parent = Selection.activeGameObject.transform; |
|||
} |
|||
|
|||
[MenuItem("GameObject/GameplayIngredients/Hooks/Trigger (Sphere)", false, 10)] |
|||
static void CreateTriggerSphere() |
|||
{ |
|||
var go = new GameObject(); |
|||
var col = go.AddComponent<SphereCollider>(); |
|||
col.isTrigger = true; |
|||
var hook = go.AddComponent<Hooks.OnTriggerHook>(); |
|||
go.name = "Sphere Trigger"; |
|||
|
|||
if (Selection.activeGameObject != null) |
|||
go.transform.parent = Selection.activeGameObject.transform; |
|||
} |
|||
|
|||
[MenuItem("GameObject/GameplayIngredients/Hooks/Trigger (Capsule)", false, 10)] |
|||
static void CreateTriggerCapsule() |
|||
{ |
|||
var go = new GameObject(); |
|||
var col = go.AddComponent<CapsuleCollider>(); |
|||
col.isTrigger = true; |
|||
var hook = go.AddComponent<Hooks.OnTriggerHook>(); |
|||
go.name = "Capsule Trigger"; |
|||
|
|||
if (Selection.activeGameObject != null) |
|||
go.transform.parent = Selection.activeGameObject.transform; |
|||
} |
|||
|
|||
[MenuItem("GameObject/GameplayIngredients/Hooks/On Awake", false, 10)] |
|||
static void CreateOnAwake() |
|||
{ |
|||
var go = new GameObject(); |
|||
var hook = go.AddComponent<Hooks.OnAwakeHook>(); |
|||
go.name = "OnAwake Hook"; |
|||
|
|||
if (Selection.activeGameObject != null) |
|||
go.transform.parent = Selection.activeGameObject.transform; |
|||
} |
|||
#endregion
|
|||
|
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 28d66973767a30643a54411070050920 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a7f14529a2d38974cb3d53b8d5014fb0 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 232f899daeba5461ebf015a1f96643b3 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEngine.Assertions; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
|
|||
namespace GraphProcessor |
|||
{ |
|||
[System.Serializable] |
|||
public abstract class BaseGraphWindow : EditorWindow |
|||
{ |
|||
protected VisualElement rootView; |
|||
protected BaseGraphView graphView; |
|||
|
|||
[SerializeField] |
|||
protected BaseGraph graph; |
|||
|
|||
public bool isGraphLoaded |
|||
{ |
|||
get { return graphView != null && graphView.graph != null; } |
|||
} |
|||
|
|||
protected void OnEnable() |
|||
{ |
|||
InitializeRootView(); |
|||
|
|||
if (graph != null) |
|||
InitializeGraph(graph); |
|||
} |
|||
|
|||
protected void OnDisable() |
|||
{ |
|||
if (graph != null) |
|||
graphView.SaveGraphToDisk(); |
|||
} |
|||
|
|||
void InitializeRootView() |
|||
{ |
|||
rootView = this.GetRootVisualContainer(); |
|||
|
|||
rootView.name = "graphRootView"; |
|||
|
|||
rootView.AddStyleSheetPath("GraphProcessorStyles/BaseGraphView"); |
|||
} |
|||
|
|||
public void InitializeGraph(BaseGraph graph) |
|||
{ |
|||
this.graph = graph; |
|||
|
|||
if (graphView != null) |
|||
rootView.Remove(graphView); |
|||
|
|||
//Initialize will provide the BaseGraphView
|
|||
Initialize(graph); |
|||
|
|||
graphView = rootView.Children().FirstOrDefault(e => e is BaseGraphView) as BaseGraphView; |
|||
|
|||
if (graphView == null) |
|||
{ |
|||
Debug.LogError("GraphView has not been added to the BaseGraph root view !"); |
|||
return ; |
|||
} |
|||
|
|||
graphView.Initialize(graph); |
|||
} |
|||
|
|||
public virtual void OnGraphDeleted() |
|||
{ |
|||
if (graph != null) |
|||
rootView.Remove(graphView); |
|||
|
|||
graphView = null; |
|||
} |
|||
|
|||
protected abstract void Initialize(BaseGraph graph); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2b4b18f42b137457bbc04f077fe5fd56 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 63fdfc474ed0f4db7aa1432eaf667691 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using System.IO; |
|||
using System.Reflection; |
|||
using UnityEditor.ProjectWindowCallback; |
|||
|
|||
namespace ProceduralWorlds.Editor |
|||
{ |
|||
public static class NodeScriptMenuItem |
|||
{ |
|||
static readonly string nodeBaseName = "Node.cs"; |
|||
static readonly string nodeViewBaseName = "NodeView.cs"; |
|||
static readonly string nodeTemplatePath = "Assets/NodeGraphProcessor/Editor/Callbacks/NodeTemplate.cs.txt"; |
|||
static readonly string nodeViewTemplatePath = "Assets/NodeGraphProcessor/Editor/Callbacks/NodeViewTemplate.cs.txt"; |
|||
|
|||
static string GetCurrentPath() |
|||
{ |
|||
var path = ""; |
|||
var obj = Selection.activeObject; |
|||
|
|||
if (obj == null) |
|||
return null; |
|||
else |
|||
path = AssetDatabase.GetAssetPath(obj.GetInstanceID()); |
|||
|
|||
if (path.Length > 0) |
|||
{ |
|||
if (Directory.Exists(path)) |
|||
return path; |
|||
else |
|||
return new FileInfo(path).Directory.FullName; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
[MenuItem("Assets/Create/Node C# Script", false, 20)] |
|||
private static void CreateNodeCSharpScritpt() |
|||
{ |
|||
string path = GetCurrentPath() + "/" + nodeBaseName; |
|||
path = AssetDatabase.GenerateUniqueAssetPath(path); |
|||
|
|||
ProjectWindowUtil.StartNameEditingIfProjectWindowExists( |
|||
0, |
|||
ScriptableObject.CreateInstance< DoCreateNodeScript >(), |
|||
path, |
|||
EditorGUIUtility.FindTexture("cs Script Icon"), |
|||
Path.GetFullPath(nodeTemplatePath) |
|||
); |
|||
|
|||
AssetDatabase.Refresh(); |
|||
} |
|||
|
|||
[MenuItem("Assets/Create/Node View C# Script", false, 21)] |
|||
private static void CreateNodeViewCSharpScritpt() |
|||
{ |
|||
string path = GetCurrentPath() + "/" + nodeViewBaseName; |
|||
path = AssetDatabase.GenerateUniqueAssetPath(path); |
|||
|
|||
ProjectWindowUtil.StartNameEditingIfProjectWindowExists( |
|||
0, |
|||
ScriptableObject.CreateInstance< DoCreateNodeScript >(), |
|||
path, |
|||
EditorGUIUtility.FindTexture("cs Script Icon"), |
|||
Path.GetFullPath(nodeViewTemplatePath) |
|||
); |
|||
|
|||
AssetDatabase.Refresh(); |
|||
} |
|||
|
|||
class DoCreateNodeScript : EndNameEditAction |
|||
{ |
|||
static MethodInfo createScriptAsset = typeof(ProjectWindowUtil).GetMethod("CreateScriptAssetFromTemplate", BindingFlags.Static | BindingFlags.NonPublic); |
|||
|
|||
public override void Action(int instanceId, string pathName, string resourceFile) |
|||
{ |
|||
if (!File.Exists(resourceFile)) |
|||
{ |
|||
Debug.LogError("Can't find template: " + resourceFile); |
|||
return ; |
|||
} |
|||
|
|||
createScriptAsset.Invoke(null, new object[]{ pathName, resourceFile }); |
|||
|
|||
var asset = AssetDatabase.LoadAssetAtPath(pathName, typeof(MonoScript)); |
|||
ProjectWindowUtil.ShowCreatedAsset(asset); |
|||
|
|||
AssetDatabase.Refresh(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a2c7e2490c5456c4ca6d567178222b16 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using GraphProcessor; |
|||
using System.Linq; |
|||
|
|||
[System.Serializable, NodeMenuItem("Custom/#NAME#")] |
|||
public class #SCRIPTNAME# : BaseNode |
|||
{ |
|||
[Input(name = "In")] |
|||
public float input; |
|||
|
|||
[Output(name = "Out")] |
|||
public float output; |
|||
|
|||
public override string name => "#NAME#"; |
|||
|
|||
protected override void Process() |
|||
{ |
|||
output = input * 42; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a9cbafe2f8c9a0042ad9fcc60c538f05 |
|||
TextScriptImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using GraphProcessor; |
|||
|
|||
[NodeCustomEditor(typeof(NODE_TYPE))] |
|||
public class #SCRIPTNAME# : BaseNodeView |
|||
{ |
|||
public override void Enable() |
|||
{ |
|||
var node = nodeTarget as NODE_TYPE; |
|||
|
|||
// Create your fields using node's variables and add them to the controlsContainer |
|||
|
|||
controlsContainer.Add(new Label("Hello World !")); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1cff9adb4a6bd6b4aac3a5472648a524 |
|||
TextScriptImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEditor.Callbacks; |
|||
|
|||
namespace GraphProcessor |
|||
{ |
|||
[ExecuteInEditMode] |
|||
public class DeleteCallback : UnityEditor.AssetModificationProcessor |
|||
{ |
|||
static AssetDeleteResult OnWillDeleteAsset(string path, RemoveAssetOptions options) |
|||
{ |
|||
var graph = AssetDatabase.LoadAssetAtPath(path, typeof(BaseGraph)); |
|||
|
|||
if (graph != null) |
|||
{ |
|||
foreach (var graphWindow in Resources.FindObjectsOfTypeAll< BaseGraphWindow >()) |
|||
graphWindow.OnGraphDeleted(); |
|||
} |
|||
|
|||
return AssetDeleteResult.DidNotDelete; |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 59cb170ad7b9d4c7394a1a7bfd6b11a1 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using System; |
|||
|
|||
namespace GraphProcessor |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Class)] |
|||
public class NodeCustomEditor : Attribute |
|||
{ |
|||
public Type nodeType; |
|||
|
|||
public NodeCustomEditor(Type nodeType) |
|||
{ |
|||
this.nodeType = nodeType; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5c50a793169754f699b4987ff8e0733f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ae3080c0c3f0d42f38d4300d12b41091 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace GraphProcessor |
|||
{ |
|||
public sealed class EdgeConnectorListener : IEdgeConnectorListener |
|||
{ |
|||
readonly BaseGraphView graphView; |
|||
|
|||
Dictionary< Edge, PortView > edgeInputPorts = new Dictionary< Edge, PortView >(); |
|||
Dictionary< Edge, PortView > edgeOutputPorts = new Dictionary< Edge, PortView >(); |
|||
|
|||
public EdgeConnectorListener(BaseGraphView graphView) |
|||
{ |
|||
this.graphView = graphView; |
|||
} |
|||
|
|||
public void OnDropOutsidePort(Edge edge, Vector2 position) |
|||
{ |
|||
this.graphView.RegisterCompleteObjectUndo("Disconnect edge"); |
|||
|
|||
//If the edge was already existing, remove it
|
|||
if (!edge.isGhostEdge) |
|||
graphView.Disconnect(edge as EdgeView); |
|||
|
|||
//TODO: open new nodes selector and connect the created node if there is one
|
|||
} |
|||
|
|||
public void OnDrop(GraphView graphView, Edge edge) |
|||
{ |
|||
var edgeView = edge as EdgeView; |
|||
bool wasOnTheSamePort = false; |
|||
|
|||
if (edgeView?.input == null || edgeView?.output == null) |
|||
return ; |
|||
|
|||
//If the edge was moved to another port
|
|||
if (edgeView.isConnected) |
|||
{ |
|||
if (edgeInputPorts.ContainsKey(edge) && edgeOutputPorts.ContainsKey(edge)) |
|||
if (edgeInputPorts[edge] == edge.input && edgeOutputPorts[edge] == edge.output) |
|||
wasOnTheSamePort = true; |
|||
|
|||
if (!wasOnTheSamePort) |
|||
this.graphView.Disconnect(edgeView); |
|||
} |
|||
|
|||
if (edgeView.input.node == null || edgeView.output.node == null) |
|||
return; |
|||
|
|||
edgeInputPorts[edge] = edge.input as PortView; |
|||
edgeOutputPorts[edge] = edge.output as PortView; |
|||
this.graphView.RegisterCompleteObjectUndo("Connected " + edgeView.input.node.name + " and " + edgeView.output.node.name); |
|||
this.graphView.Connect(edge as EdgeView, autoDisconnectInputs: !wasOnTheSamePort); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 594eed6e129424e83abd868b8d10d7a7 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c6072e601ba164a9baaee07146ebd0a2 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using UnityEngine; |
|||
|
|||
namespace GraphProcessor |
|||
{ |
|||
public class BorderResizer : MouseManipulator |
|||
{ |
|||
bool active; |
|||
Vector2 startMousePosition; |
|||
Vector2 startComponentSize; |
|||
Vector2 startComponentPosition; |
|||
|
|||
readonly int dragBorderSize = 15; |
|||
Vector2 dragDirection; |
|||
|
|||
readonly string cursorBorderStyleSheet = "GraphProcessorStyles/BorderResizer"; |
|||
|
|||
GraphElement elem; |
|||
|
|||
public BorderResizer() |
|||
{ |
|||
activators.Add(new ManipulatorActivationFilter { button = MouseButton.LeftMouse }); |
|||
} |
|||
|
|||
protected override void RegisterCallbacksOnTarget() |
|||
{ |
|||
elem = target as GraphElement; |
|||
|
|||
if (elem == null) |
|||
throw new System.InvalidOperationException("BorderReiszer can only be added to a GraphElement"); |
|||
|
|||
target.RegisterCallback< MouseDownEvent >(OnMouseDown); |
|||
target.RegisterCallback< MouseMoveEvent >(OnMouseMove); |
|||
target.RegisterCallback< MouseUpEvent >(OnMouseUp); |
|||
|
|||
if (!target.HasStyleSheetPath(cursorBorderStyleSheet)) |
|||
target.AddStyleSheetPath(cursorBorderStyleSheet); |
|||
} |
|||
|
|||
protected override void UnregisterCallbacksFromTarget() |
|||
{ |
|||
target.UnregisterCallback< MouseDownEvent >(OnMouseDown); |
|||
target.UnregisterCallback< MouseMoveEvent >(OnMouseMove); |
|||
target.UnregisterCallback< MouseUpEvent >(OnMouseUp); |
|||
} |
|||
|
|||
void OnMouseDown(MouseDownEvent e) |
|||
{ |
|||
if (active) |
|||
{ |
|||
e.StopPropagation(); |
|||
return ; |
|||
} |
|||
|
|||
if (MouseCaptureController.IsMouseCaptured()) |
|||
return ; |
|||
|
|||
if (!IsMouseOverBorders(e.localMousePosition)) |
|||
return; |
|||
|
|||
if (CanStartManipulation(e)) |
|||
{ |
|||
active = true; |
|||
target.CaptureMouse(); |
|||
e.StopPropagation(); |
|||
|
|||
startComponentSize = new Vector2(elem.style.width, elem.style.height); |
|||
startMousePosition = e.localMousePosition; |
|||
startComponentPosition = elem.transform.position; |
|||
} |
|||
else |
|||
Debug.Log("can't start manipulation !"); |
|||
} |
|||
|
|||
void OnMouseMove(MouseMoveEvent e) |
|||
{ |
|||
if (!active) |
|||
return ; |
|||
|
|||
Vector2 delta = e.localMousePosition - startMousePosition + (Vector2)elem.transform.position - startComponentPosition; |
|||
|
|||
elem.style.width = startComponentSize.x + delta.x * dragDirection.x; |
|||
elem.style.height = startComponentSize.y + delta.y * dragDirection.y; |
|||
|
|||
elem.transform.position -= (Vector3)(e.mouseDelta * Vector2.Min(Vector2.zero, dragDirection)); |
|||
} |
|||
|
|||
void OnMouseUp(MouseUpEvent e) |
|||
{ |
|||
if (!active) |
|||
return ; |
|||
|
|||
if (CanStopManipulation(e)) |
|||
{ |
|||
target.ReleaseMouse(); |
|||
e.StopPropagation(); |
|||
|
|||
GraphView graphView = elem.GetFirstAncestorOfType<GraphView>(); |
|||
if (graphView != null && graphView.elementResized != null) |
|||
graphView.elementResized(elem); |
|||
} |
|||
|
|||
active = false; |
|||
} |
|||
|
|||
bool IsMouseOverBorders(Vector2 mousePosition) |
|||
{ |
|||
Rect borders = new Rect(Vector2.zero, target.localBound.size); |
|||
|
|||
dragDirection = Vector2.zero; |
|||
|
|||
if (mousePosition.x - borders.xMin < dragBorderSize) |
|||
dragDirection.x = -1; |
|||
if (borders.xMax - mousePosition.x < dragBorderSize) |
|||
dragDirection.x = 1; |
|||
if (mousePosition.y - borders.yMin < dragBorderSize) |
|||
dragDirection.y = -1; |
|||
if (borders.yMax - mousePosition.y < dragBorderSize) |
|||
dragDirection.y = 1; |
|||
|
|||
return dragDirection != Vector2.zero; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2184598ff73294c1b9dd5255d8545679 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine.Experimental.UIElements.StyleSheets; |
|||
|
|||
namespace GraphProcessor |
|||
{ |
|||
public class ConfinedDragger : MouseManipulator |
|||
{ |
|||
bool active; |
|||
Vector3 offset; |
|||
|
|||
VisualElement container; |
|||
VisualElement handle; |
|||
|
|||
public Action onDragEnd; |
|||
|
|||
public ConfinedDragger(VisualElement container) |
|||
{ |
|||
this.container = container; |
|||
active = false; |
|||
} |
|||
|
|||
protected override void RegisterCallbacksOnTarget() |
|||
{ |
|||
handle = target; |
|||
|
|||
handle.RegisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), TrickleDown.NoTrickleDown); |
|||
handle.RegisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), TrickleDown.NoTrickleDown); |
|||
handle.RegisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), TrickleDown.NoTrickleDown); |
|||
} |
|||
|
|||
protected override void UnregisterCallbacksFromTarget() |
|||
{ |
|||
handle.UnregisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), TrickleDown.NoTrickleDown); |
|||
handle.UnregisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), TrickleDown.NoTrickleDown); |
|||
handle.UnregisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), TrickleDown.NoTrickleDown); |
|||
} |
|||
|
|||
void OnMouseDown(MouseDownEvent evt) |
|||
{ |
|||
active = true; |
|||
|
|||
offset = evt.mousePosition - (Vector2)target.transform.position; |
|||
|
|||
handle.CaptureMouse(); |
|||
evt.StopImmediatePropagation(); |
|||
} |
|||
|
|||
void OnMouseMove(MouseMoveEvent evt) |
|||
{ |
|||
if (active) |
|||
{ |
|||
Vector3 position = (Vector3)evt.mousePosition - offset; |
|||
position.x = Mathf.Clamp(position.x, -target.layout.position.x, container.layout.width - target.layout.position.x - target.localBound.size.x); |
|||
position.y = Mathf.Clamp(position.y, -target.layout.position.y, container.layout.height - target.layout.position.y - target.localBound.size.y); |
|||
|
|||
target.transform.position = position; |
|||
} |
|||
} |
|||
|
|||
void OnMouseUp(MouseUpEvent evt) |
|||
{ |
|||
active = false; |
|||
|
|||
if (handle.HasMouseCapture()) |
|||
handle.ReleaseMouse(); |
|||
evt.StopImmediatePropagation(); |
|||
|
|||
if (onDragEnd != null) |
|||
onDragEnd(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8984ae8e754a344d7a6361c06cd1b9b1 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: cffd7e4ce183a9f48927dc1c49f90616 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.Experimental.UIElements.StyleEnums; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine; |
|||
using System.Reflection; |
|||
using System.Linq; |
|||
|
|||
namespace GraphProcessor |
|||
{ |
|||
public class DefaultPortBehavior |
|||
{ |
|||
public DefaultPortBehavior(BaseNodeView nodeView, FieldInfo fieldInfo, Direction direction, EdgeConnectorListener listener, bool isMultiple, string name) |
|||
{ |
|||
nodeView.AddPort(fieldInfo, direction, listener, isMultiple, name); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0c02c9f760c77ef44a7696e41c76d3a9 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.Experimental.UIElements.StyleEnums; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine; |
|||
using System.Reflection; |
|||
using System.Linq; |
|||
|
|||
namespace GraphProcessor |
|||
{ |
|||
[CustomPortBehavior(typeof(MultiPorts))] |
|||
public class MultiPortBehavior |
|||
{ |
|||
MultiPorts multiPorts; |
|||
BaseNodeView node; |
|||
Dictionary< Edge, PortView > portViews = new Dictionary< Edge, PortView >(); |
|||
|
|||
FieldInfo fieldInfo; |
|||
Direction direction; |
|||
EdgeConnectorListener listener; |
|||
bool isMultiple; |
|||
string name; |
|||
|
|||
public MultiPortBehavior(BaseNodeView nodeView, FieldInfo fieldInfo, Direction direction, EdgeConnectorListener listener, bool isMultiple, string name) |
|||
{ |
|||
this.multiPorts = fieldInfo.GetValue(nodeView.nodeTarget) as MultiPorts; |
|||
this.node = nodeView; |
|||
this.fieldInfo = fieldInfo; |
|||
this.direction = direction; |
|||
this.listener = listener; |
|||
this.isMultiple = isMultiple; |
|||
this.name = name; |
|||
|
|||
// Initialize the MultiPort field if null
|
|||
if (multiPorts == null) |
|||
{ |
|||
multiPorts = new MultiPorts(); |
|||
fieldInfo.SetValue(nodeView.nodeTarget, multiPorts); |
|||
} |
|||
|
|||
// Instantiate all ports needed to create the serialized connections
|
|||
// Minus one because we count our current instance
|
|||
for (int i = 0; i < multiPorts.portCount; i++) |
|||
AddPort(); |
|||
} |
|||
|
|||
void AddPort() |
|||
{ |
|||
PortView pv = node.AddPort(fieldInfo, direction, listener, isMultiple, name); |
|||
|
|||
// We force the AddPort in the BaseNode class because the port list is not updated except at the construction of the class
|
|||
node.nodeTarget.AddPort(direction == Direction.Input, pv.fieldName); |
|||
|
|||
pv.OnConnected += OnPortConnected; |
|||
pv.OnDisconnected += OnPortDisconnected; |
|||
} |
|||
|
|||
public void OnPortConnected(PortView pv, Edge edge) |
|||
{ |
|||
// Fix port datas
|
|||
if (pv.direction == Direction.Input) |
|||
edge.input = pv; |
|||
else |
|||
edge.output = pv; |
|||
|
|||
// If the edge is already connected, ignore it
|
|||
if (portViews.ContainsKey(edge)) |
|||
return ; |
|||
|
|||
portViews[edge] = pv; |
|||
|
|||
if (pv.GetEdges().Count == 0) |
|||
{ |
|||
multiPorts.AddUniqueId(multiPorts.GetUniqueId()); |
|||
AddPort(); |
|||
} |
|||
} |
|||
|
|||
public void OnPortDisconnected(PortView pv, Edge edge) |
|||
{ |
|||
if (pv.GetEdges().Count == 0) |
|||
{ |
|||
if ((edge as EdgeView).isConnected && portViews.ContainsKey(edge)) |
|||
{ |
|||
var portToRemove = portViews[edge]; |
|||
|
|||
node.RemovePort(portToRemove); |
|||
|
|||
node.nodeTarget.RemovePort(direction == Direction.Input, portToRemove.fieldName); |
|||
|
|||
portViews.Remove(edge); |
|||
multiPorts.RemoveUniqueId(0); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9a47c447ebb4fe54c8922feadb2782f5 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System; |
|||
using System.Reflection; |
|||
using System.Linq; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace GraphProcessor |
|||
{ |
|||
public static class PortBehaviorFactory |
|||
{ |
|||
static Dictionary<Type, Type> portBehaviors = new Dictionary<Type, Type>(); |
|||
|
|||
static PortBehaviorFactory() |
|||
{ |
|||
foreach (var type in AppDomain.CurrentDomain.GetAllTypes()) |
|||
{ |
|||
var customPortBehaviorAttr = type.GetCustomAttribute< CustomPortBehaviorAttribute >(); |
|||
|
|||
if (customPortBehaviorAttr == null) |
|||
continue ; |
|||
|
|||
portBehaviors[customPortBehaviorAttr.targetType] = type; |
|||
} |
|||
} |
|||
|
|||
public static void CreatePortBehavior(BaseNodeView nodeView, FieldInfo field, Direction direction, EdgeConnectorListener listener, bool isMultiple, string name) |
|||
{ |
|||
Type behaviorType; |
|||
|
|||
portBehaviors.TryGetValue(field.FieldType, out behaviorType); |
|||
|
|||
if (behaviorType == null) |
|||
behaviorType = typeof(DefaultPortBehavior); |
|||
|
|||
Activator.CreateInstance(behaviorType, nodeView, field, direction, listener, isMultiple, name); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 379e2785adbd6ab43adf7682b6d77b69 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a15334d6fa12046e5afcb22ac791a43d |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 6562f61ebe4c045d29fe4b1a3457379a |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#graphRootView |
|||
{ |
|||
background-color: #101010; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2769cf0fb82ce4c2691edb49469f5f17 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: stylesheet |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} |
|
|||
#node { |
|||
background-color: rgba(0, 63, 63, 0.8); |
|||
} |
|||
|
|||
#controls { |
|||
background-color: rgba(63, 63, 63, 0.8); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7aed4ab0823d4432996ae4614575bc7c |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: stylesheet |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} |
|
|||
#headerColorPicker { |
|||
width: 50; |
|||
align: right; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 778f73de1e04f4acd871308e30971a42 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: stylesheet |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} |
|
|||
EdgeView.Single { |
|||
color: #800080 |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 28f83445e912a4e25aa30a4f0cd22636 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: stylesheet |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} |
|
|||
#PinnedElementView { |
|||
flex-direction: column; |
|||
position-type: absolute; |
|||
position-right: 10; |
|||
position-bottom: 10; |
|||
background-color: rgb(79, 79, 79); |
|||
justify-content: flex-start; |
|||
border-radius: 6; |
|||
border-top-width: 1; |
|||
border-bottom-width: 1; |
|||
border-left-width: 1; |
|||
border-right-width: 1; |
|||
border-color: rgb(25,25,25); |
|||
} |
|||
|
|||
#PinnedElementView > #header { |
|||
flex-direction: row; |
|||
justify-content: space-between; |
|||
background-color: rgb(64, 64, 64); |
|||
padding-top: 8; |
|||
padding-bottom: 8; |
|||
padding-left: 8; |
|||
padding-right: 8; |
|||
border-top-left-radius: 6; |
|||
border-top-right-radius: 6; |
|||
} |
|||
|
|||
#PinnedElementView > #header > #title { |
|||
font-size: 12; |
|||
text-color: rgb(180, 180, 180); |
|||
padding-top: 1; |
|||
padding-bottom: 2; |
|||
padding-left: 2; |
|||
padding-right: 2; |
|||
} |
|||
|
|||
#PinnedElementView > #content { |
|||
flex-grow: 1; |
|||
border-width: 10; |
|||
flex-direction: row; |
|||
border-color: rgb(0,10,190); |
|||
} |
|||
|
|||
#PinnedElementView.collapsed{ |
|||
background-color: rgb(206, 53, 185); |
|||
} |
|||
|
|||
#PinnedElementView.expanded{ |
|||
background-color: rgb(206, 53, 185); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2fdbf4d830a3942a18aafb8fd7a5fa53 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: stylesheet |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} |
|
|||
PortView { |
|||
height: 24; |
|||
align-items: center; |
|||
padding-left: 4; |
|||
padding-right: 4; |
|||
port-color: rgb(200, 200, 00); |
|||
disabled-port-color: rgb(0, 70, 70); |
|||
} |
|||
|
|||
PortView.input { |
|||
flex-direction: row; |
|||
} |
|||
|
|||
PortView.output { |
|||
flex-direction: row-reverse; |
|||
} |
|||
|
|||
PortView > #connector { |
|||
border-color: rgb(255, 255, 0); |
|||
background-color: #212121; |
|||
width: 8; |
|||
height: 8; |
|||
border-radius: 8; |
|||
align-items: center; |
|||
justify-content: center; |
|||
|
|||
margin-left: 4; |
|||
margin-right: 4; |
|||
border-left-width:1; |
|||
border-top-width:1; |
|||
border-right-width:1; |
|||
border-bottom-width:1; |
|||
} |
|||
|
|||
PortView > #connector:hover { |
|||
border-color: #f0f0f0 |
|||
} |
|||
|
|||
PortView > #connector > #cap |
|||
{ |
|||
background-color: #212121; |
|||
width: 4; |
|||
height: 4; |
|||
border-radius: 4; |
|||
} |
|||
|
|||
PortView > #connector > #cap:hover |
|||
{ |
|||
background-color: #f0f0f0; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7f9f1707b6119456581ab1a100d96aaa |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: stylesheet |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5e5f8827aa14940f59f6f29179b03d0c |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace GraphProcessor |
|||
{ |
|||
[System.Serializable] |
|||
public class CopyPasteHelper |
|||
{ |
|||
public List< JsonElement > copiedNodes = new List< JsonElement >(); |
|||
|
|||
public List< JsonElement > copiedCommentBlocks = new List< JsonElement >(); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ad4ab8e74dd9540cab3bc65ba3b8b58c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using System; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
|
|||
namespace GraphProcessor |
|||
{ |
|||
public static class FieldFactory |
|||
{ |
|||
static readonly Dictionary< Type, Type > fieldDrawers = new Dictionary< Type, Type >(); |
|||
|
|||
static readonly MethodInfo createFieldMethod = typeof(FieldFactory).GetMethod("CreateFieldSpecific", BindingFlags.Static | BindingFlags.Public); |
|||
|
|||
static FieldFactory() |
|||
{ |
|||
foreach (var type in AppDomain.CurrentDomain.GetAllTypes()) |
|||
{ |
|||
var drawerAttribute = type.GetCustomAttributes(typeof(FieldDrawerAttribute), false).FirstOrDefault() as FieldDrawerAttribute; |
|||
|
|||
if (drawerAttribute == null) |
|||
continue ; |
|||
|
|||
AddDrawer(drawerAttribute.fieldType, type); |
|||
} |
|||
|
|||
// щ(ºДºщ) ...
|
|||
AddDrawer(typeof(int), typeof(IntegerField)); |
|||
AddDrawer(typeof(long), typeof(LongField)); |
|||
AddDrawer(typeof(float), typeof(FloatField)); |
|||
AddDrawer(typeof(double), typeof(DoubleField)); |
|||
AddDrawer(typeof(string), typeof(TextField)); |
|||
AddDrawer(typeof(Bounds), typeof(BoundsField)); |
|||
AddDrawer(typeof(Color), typeof(ColorField)); |
|||
AddDrawer(typeof(Vector2), typeof(Vector2Field)); |
|||
AddDrawer(typeof(Vector3), typeof(Vector3Field)); |
|||
AddDrawer(typeof(Vector4), typeof(Vector4Field)); |
|||
AddDrawer(typeof(AnimationCurve), typeof(CurveField)); |
|||
AddDrawer(typeof(Enum), typeof(EnumField)); |
|||
AddDrawer(typeof(Gradient), typeof(GradientField)); |
|||
AddDrawer(typeof(UnityEngine.Object), typeof(ObjectField)); |
|||
AddDrawer(typeof(Rect), typeof(RectField)); |
|||
} |
|||
|
|||
static void AddDrawer(Type fieldType, Type drawerType) |
|||
{ |
|||
var iNotifyType = typeof(INotifyValueChanged<>).MakeGenericType(fieldType); |
|||
|
|||
if (!iNotifyType.IsAssignableFrom(drawerType)) |
|||
{ |
|||
Debug.LogWarning("The custom field drawer " + drawerType + " does not implements INotifyValueChanged< " + fieldType + " >"); |
|||
return ; |
|||
} |
|||
|
|||
fieldDrawers[fieldType] = drawerType; |
|||
} |
|||
|
|||
public static INotifyValueChanged< T > CreateField< T >() |
|||
{ |
|||
return CreateField(typeof(T)) as INotifyValueChanged< T >; |
|||
} |
|||
|
|||
public static VisualElement CreateField(Type t) |
|||
{ |
|||
Type drawerType; |
|||
|
|||
fieldDrawers.TryGetValue(t, out drawerType); |
|||
|
|||
if (drawerType == null) |
|||
drawerType = fieldDrawers.FirstOrDefault(kp => kp.Key.IsReallyAssignableFrom(t)).Value; |
|||
|
|||
if (drawerType == null) |
|||
{ |
|||
Debug.LogWarning("Can't find field drawer for type: " + t); |
|||
return null; |
|||
} |
|||
|
|||
var field = Activator.CreateInstance(drawerType); |
|||
|
|||
// For mutiline
|
|||
if (field is TextField) |
|||
{ |
|||
(field as TextField).multiline = true; |
|||
} |
|||
|
|||
return field as VisualElement; |
|||
} |
|||
|
|||
public static INotifyValueChanged< T > CreateFieldSpecific< T >(FieldInfo field, T value, Action< object > onValueChanged) |
|||
{ |
|||
var fieldDrawer = CreateField< T >(); |
|||
|
|||
if (fieldDrawer == null) |
|||
return null; |
|||
|
|||
fieldDrawer.value = value; |
|||
fieldDrawer.OnValueChanged((e) => { |
|||
onValueChanged(e.newValue); |
|||
}); |
|||
|
|||
return fieldDrawer as INotifyValueChanged< T >; |
|||
} |
|||
|
|||
public static VisualElement CreateField(FieldInfo field, object value, Action< object > onValueChanged) |
|||
{ |
|||
var createFieldSpecificMethod = createFieldMethod.MakeGenericMethod(field.FieldType); |
|||
|
|||
return createFieldSpecificMethod.Invoke(null, new object[]{field, value, onValueChanged}) as VisualElement; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8e070bfe6917e4be9bff3e56c4cda092 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using System; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using System.Linq; |
|||
|
|||
namespace GraphProcessor |
|||
{ |
|||
public static class NodeProvider |
|||
{ |
|||
static Dictionary< Type, Type > nodeViewPerType = new Dictionary< Type, Type >(); |
|||
static Dictionary< string, Type > nodePerMenuTitle = new Dictionary< string, Type >(); |
|||
static Dictionary< Type, string > nodeViewScripts = new Dictionary< Type, string >(); |
|||
static Dictionary< Type, string > nodeScripts = new Dictionary< Type, string >(); |
|||
|
|||
static NodeProvider() |
|||
{ |
|||
foreach (var type in AppDomain.CurrentDomain.GetAllTypes()) |
|||
{ |
|||
if (type.IsClass && !type.IsAbstract) |
|||
{ |
|||
if (type.IsSubclassOf(typeof(BaseNode))) |
|||
AddNodeType(type); |
|||
if (type.IsSubclassOf(typeof(BaseNodeView))) |
|||
AddNodeViewType(type); |
|||
} |
|||
} |
|||
} |
|||
|
|||
static void AddNodeType(Type type) |
|||
{ |
|||
var attrs = type.GetCustomAttributes(typeof(NodeMenuItemAttribute), false) as NodeMenuItemAttribute[]; |
|||
|
|||
if (attrs != null && attrs.Length > 0) |
|||
nodePerMenuTitle[attrs.First().menuTitle] = type; |
|||
|
|||
var nodeScriptAsset = FindScriptFromClassName(type.Name); |
|||
if (nodeScriptAsset != null) |
|||
nodeScripts[type] = nodeScriptAsset; |
|||
} |
|||
|
|||
static void AddNodeViewType(Type type) |
|||
{ |
|||
var attrs = type.GetCustomAttributes(typeof(NodeCustomEditor), false) as NodeCustomEditor[]; |
|||
|
|||
if (attrs != null && attrs.Length > 0) |
|||
{ |
|||
Type nodeType = attrs.First().nodeType; |
|||
nodeViewPerType[nodeType] = type; |
|||
|
|||
var nodeViewScriptAsset = FindScriptFromClassName(type.Name); |
|||
|
|||
if (nodeViewScriptAsset != null) |
|||
nodeViewScripts[type] = nodeViewScriptAsset; |
|||
} |
|||
} |
|||
|
|||
static string FindScriptFromClassName(string className) |
|||
{ |
|||
var scriptGUIDs = AssetDatabase.FindAssets(className); |
|||
|
|||
if (scriptGUIDs.Length == 0) |
|||
return null; |
|||
|
|||
return AssetDatabase.GUIDToAssetPath(scriptGUIDs[0]); |
|||
} |
|||
|
|||
public static Type GetNodeViewTypeFromType(Type nodeType) |
|||
{ |
|||
Type view; |
|||
|
|||
nodeViewPerType.TryGetValue(nodeType, out view); |
|||
|
|||
return view; |
|||
} |
|||
|
|||
public static Dictionary< string, Type > GetNodeMenuEntries() |
|||
{ |
|||
return nodePerMenuTitle; |
|||
} |
|||
|
|||
public static string GetNodeViewScript(Type type) |
|||
{ |
|||
string scriptPath; |
|||
|
|||
nodeViewScripts.TryGetValue(type, out scriptPath); |
|||
|
|||
return scriptPath; |
|||
} |
|||
|
|||
public static string GetNodeScript(Type type) |
|||
{ |
|||
string scriptPath; |
|||
|
|||
nodeScripts.TryGetValue(type, out scriptPath); |
|||
|
|||
return scriptPath; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0f90580539cbf48d58ba35c626500169 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 600ac8da8b308477fa0dfcd14d40ce53 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using System.Linq; |
|||
using System; |
|||
|
|||
using StatusFlags = UnityEngine.Experimental.UIElements.DropdownMenu.MenuAction.StatusFlags; |
|||
|
|||
using Object = UnityEngine.Object; |
|||
|
|||
namespace GraphProcessor |
|||
{ |
|||
public class BaseGraphView : GraphView |
|||
{ |
|||
public BaseGraph graph; |
|||
|
|||
public EdgeConnectorListener connectorListener; |
|||
|
|||
public List< BaseNodeView > nodeViews = new List< BaseNodeView >(); |
|||
public Dictionary< BaseNode, BaseNodeView > nodeViewsPerNode = new Dictionary< BaseNode, BaseNodeView >(); |
|||
public List< EdgeView > edgeViews = new List< EdgeView >(); |
|||
public List< CommentBlockView > commentBlockViews = new List< CommentBlockView >(); |
|||
|
|||
Dictionary< Type, PinnedElementView > pinnedElements = new Dictionary< Type, PinnedElementView >(); |
|||
|
|||
public delegate void ComputeOrderUpdatedDelegate(); |
|||
|
|||
public event Action initialized; |
|||
public event ComputeOrderUpdatedDelegate computeOrderUpdated; |
|||
|
|||
public BaseGraphView() |
|||
{ |
|||
serializeGraphElements = SerializeGraphElementsCallback; |
|||
canPasteSerializedData = CanPasteSerializedDataCallback; |
|||
unserializeAndPaste = UnserializeAndPasteCallback; |
|||
graphViewChanged = GraphViewChangedCallback; |
|||
viewTransformChanged = ViewTransformChangedCallback; |
|||
elementResized = ElementResizedCallback; |
|||
|
|||
InitializeManipulators(); |
|||
|
|||
RegisterCallback< KeyDownEvent >(KeyDownCallback); |
|||
|
|||
SetupZoom(0.05f, 2f); |
|||
|
|||
Undo.undoRedoPerformed += ReloadView; |
|||
|
|||
this.StretchToParentSize(); |
|||
} |
|||
|
|||
#region Callbacks
|
|||
|
|||
protected override bool canCopySelection |
|||
{ |
|||
get { return selection.Any(e => e is BaseNodeView || e is CommentBlockView); } |
|||
} |
|||
|
|||
protected override bool canCutSelection |
|||
{ |
|||
get { return selection.Any(e => e is BaseNodeView || e is CommentBlockView); } |
|||
} |
|||
|
|||
string SerializeGraphElementsCallback(IEnumerable<GraphElement> elements) |
|||
{ |
|||
var data = new CopyPasteHelper(); |
|||
|
|||
foreach (var nodeView in elements.Where(e => e is BaseNodeView)) |
|||
{ |
|||
var node = ((nodeView) as BaseNodeView).nodeTarget; |
|||
data.copiedNodes.Add(JsonSerializer.Serialize< BaseNode >(node)); |
|||
} |
|||
|
|||
foreach (var commentBlockView in elements.Where(e => e is CommentBlockView)) |
|||
{ |
|||
var commentBlock = (commentBlockView as CommentBlockView).commentBlock; |
|||
data.copiedCommentBlocks.Add(JsonSerializer.Serialize< CommentBlock >(commentBlock)); |
|||
} |
|||
|
|||
ClearSelection(); |
|||
|
|||
return JsonUtility.ToJson(data, true); |
|||
} |
|||
|
|||
bool CanPasteSerializedDataCallback(string serializedData) |
|||
{ |
|||
try { |