Initial Commit
This commit is contained in:
parent
53eb92e9af
commit
270ab7d11f
15341 changed files with 700234 additions and 0 deletions
|
@ -0,0 +1,39 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
[Widget(typeof(ControlConnection))]
|
||||
public sealed class ControlConnectionWidget : UnitConnectionWidget<ControlConnection>
|
||||
{
|
||||
public ControlConnectionWidget(FlowCanvas canvas, ControlConnection connection) : base(canvas, connection) { }
|
||||
|
||||
|
||||
#region Drawing
|
||||
|
||||
public override Color color => Color.white;
|
||||
|
||||
protected override bool colorIfActive => !BoltFlow.Configuration.animateControlConnections || !BoltFlow.Configuration.animateValueConnections;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Droplets
|
||||
|
||||
protected override bool showDroplets => BoltFlow.Configuration.animateControlConnections;
|
||||
|
||||
protected override Vector2 GetDropletSize()
|
||||
{
|
||||
return BoltFlow.Icons.valuePortConnected?[12].Size() ?? 12 * Vector2.one;
|
||||
}
|
||||
|
||||
protected override void DrawDroplet(Rect position)
|
||||
{
|
||||
if (BoltFlow.Icons.valuePortConnected != null)
|
||||
{
|
||||
GUI.DrawTexture(position, BoltFlow.Icons.valuePortConnected[12]);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d88c7deff78ad4226b20ab4dfc84f89c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,9 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
public interface IUnitConnectionWidget : IGraphElementWidget
|
||||
{
|
||||
Color color { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9ed635d3114774915b9f96a96a330dca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,28 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
[Widget(typeof(InvalidConnection))]
|
||||
public sealed class InvalidConnectionWidget : UnitConnectionWidget<InvalidConnection>
|
||||
{
|
||||
public InvalidConnectionWidget(FlowCanvas canvas, InvalidConnection connection) : base(canvas, connection) { }
|
||||
|
||||
|
||||
#region Drawing
|
||||
|
||||
public override Color color => UnitConnectionStyles.invalidColor;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Droplets
|
||||
|
||||
protected override bool showDroplets => false;
|
||||
|
||||
protected override Vector2 GetDropletSize() => Vector2.zero;
|
||||
|
||||
protected override void DrawDroplet(Rect position) { }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 54bd5c4a9de7845ab9aaea996b90656d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,19 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
public static class UnitConnectionStyles
|
||||
{
|
||||
public static readonly Color activeColor = new Color(0.37f, 0.66f, 0.95f);
|
||||
|
||||
public static readonly Color highlightColor = new Color(1, 0.95f, 0f);
|
||||
|
||||
public static readonly Color invalidColor = new Color(1, 0, 0);
|
||||
|
||||
public static readonly Color disconnectColor = new Color(0.95f, 0.1f, 0.1f);
|
||||
|
||||
public static readonly float minBend = 15;
|
||||
|
||||
public static readonly float relativeBend = 1 / 4f;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f7fbf7894024a473ab12d0bec2b9b5e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,247 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
public abstract class UnitConnectionWidget<TConnection> : GraphElementWidget<FlowCanvas, TConnection>, IUnitConnectionWidget
|
||||
where TConnection : class, IUnitConnection
|
||||
{
|
||||
protected UnitConnectionWidget(FlowCanvas canvas, TConnection connection) : base(canvas, connection) { }
|
||||
|
||||
|
||||
#region Model
|
||||
|
||||
protected TConnection connection => element;
|
||||
|
||||
protected IUnitConnectionDebugData ConnectionDebugData => GetDebugData<IUnitConnectionDebugData>();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Lifecycle
|
||||
|
||||
public override void BeforeFrame()
|
||||
{
|
||||
base.BeforeFrame();
|
||||
|
||||
if (showDroplets)
|
||||
{
|
||||
GraphGUI.UpdateDroplets(canvas, droplets, ConnectionDebugData.lastInvokeFrame, ref lastInvokeTime, ref dropTime);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Positioning
|
||||
|
||||
public override IEnumerable<IWidget> positionDependencies
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return canvas.Widget(connection.source);
|
||||
yield return canvas.Widget(connection.destination);
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool snapToGrid => false;
|
||||
|
||||
public Rect sourceHandlePosition { get; private set; }
|
||||
|
||||
public Rect destinationHandlePosition { get; private set; }
|
||||
|
||||
public Vector2 sourceHandleEdgeCenter { get; private set; }
|
||||
|
||||
public Vector2 destinationHandleEdgeCenter { get; private set; }
|
||||
|
||||
public Vector2 middlePosition;
|
||||
|
||||
private Rect _position;
|
||||
|
||||
private Rect _clippingPosition;
|
||||
|
||||
public override Rect position
|
||||
{
|
||||
get { return _position; }
|
||||
set { }
|
||||
}
|
||||
|
||||
public override Rect clippingPosition => _clippingPosition;
|
||||
|
||||
public override void CachePosition()
|
||||
{
|
||||
base.CachePosition();
|
||||
|
||||
sourceHandlePosition = canvas.Widget<IUnitPortWidget>(connection.source).handlePosition;
|
||||
destinationHandlePosition = canvas.Widget<IUnitPortWidget>(connection.destination).handlePosition;
|
||||
|
||||
sourceHandleEdgeCenter = sourceHandlePosition.GetEdgeCenter(Edge.Right);
|
||||
destinationHandleEdgeCenter = destinationHandlePosition.GetEdgeCenter(Edge.Left);
|
||||
|
||||
middlePosition = (sourceHandlePosition.center + destinationHandlePosition.center) / 2;
|
||||
|
||||
_position = new Rect
|
||||
(
|
||||
middlePosition.x,
|
||||
middlePosition.y,
|
||||
0,
|
||||
0
|
||||
);
|
||||
|
||||
_clippingPosition = _position.Encompass(sourceHandleEdgeCenter).Encompass(destinationHandleEdgeCenter);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Drawing
|
||||
|
||||
protected virtual bool colorIfActive => true;
|
||||
|
||||
public abstract Color color { get; }
|
||||
|
||||
protected override bool dim
|
||||
{
|
||||
get
|
||||
{
|
||||
var dim = BoltCore.Configuration.dimInactiveNodes && !connection.destination.unit.Analysis<UnitAnalysis>(context).isEntered;
|
||||
|
||||
if (BoltCore.Configuration.dimIncompatibleNodes && canvas.isCreatingConnection)
|
||||
{
|
||||
dim = true;
|
||||
}
|
||||
|
||||
return dim;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawBackground()
|
||||
{
|
||||
base.DrawBackground();
|
||||
|
||||
BeginDim();
|
||||
|
||||
DrawConnection();
|
||||
|
||||
if (showDroplets)
|
||||
{
|
||||
DrawDroplets();
|
||||
}
|
||||
|
||||
EndDim();
|
||||
}
|
||||
|
||||
protected virtual void DrawConnection()
|
||||
{
|
||||
var color = this.color;
|
||||
|
||||
var sourceWidget = canvas.Widget<IUnitPortWidget>(connection.source);
|
||||
var destinationWidget = canvas.Widget<IUnitPortWidget>(connection.destination);
|
||||
|
||||
var highlight = !canvas.isCreatingConnection && (sourceWidget.isMouseOver || destinationWidget.isMouseOver);
|
||||
|
||||
var willDisconnect = sourceWidget.willDisconnect || destinationWidget.willDisconnect;
|
||||
|
||||
if (willDisconnect)
|
||||
{
|
||||
color = UnitConnectionStyles.disconnectColor;
|
||||
}
|
||||
else if (highlight)
|
||||
{
|
||||
color = UnitConnectionStyles.highlightColor;
|
||||
}
|
||||
else if (colorIfActive)
|
||||
{
|
||||
if (EditorApplication.isPaused)
|
||||
{
|
||||
if (EditorTimeBinding.frame == ConnectionDebugData.lastInvokeFrame)
|
||||
{
|
||||
color = UnitConnectionStyles.activeColor;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
color = Color.Lerp(UnitConnectionStyles.activeColor, color, (EditorTimeBinding.time - ConnectionDebugData.lastInvokeTime) / UnitWidget<IUnit>.Styles.invokeFadeDuration);
|
||||
}
|
||||
}
|
||||
|
||||
var thickness = 3;
|
||||
|
||||
GraphGUI.DrawConnection(color, sourceHandleEdgeCenter, destinationHandleEdgeCenter, Edge.Right, Edge.Left, null, Vector2.zero, UnitConnectionStyles.relativeBend, UnitConnectionStyles.minBend, thickness);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Selecting
|
||||
|
||||
public override bool canSelect => false;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Dragging
|
||||
|
||||
public override bool canDrag => false;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Deleting
|
||||
|
||||
public override bool canDelete => true;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Droplets
|
||||
|
||||
private readonly List<float> droplets = new List<float>();
|
||||
|
||||
private float dropTime;
|
||||
|
||||
private float lastInvokeTime;
|
||||
|
||||
private const float handleAlignmentMargin = 0.1f;
|
||||
|
||||
protected virtual bool showDroplets => true;
|
||||
|
||||
protected abstract Vector2 GetDropletSize();
|
||||
|
||||
protected abstract void DrawDroplet(Rect position);
|
||||
|
||||
protected virtual void DrawDroplets()
|
||||
{
|
||||
foreach (var droplet in droplets)
|
||||
{
|
||||
Vector2 position;
|
||||
|
||||
if (droplet < handleAlignmentMargin)
|
||||
{
|
||||
var t = droplet / handleAlignmentMargin;
|
||||
position = Vector2.Lerp(sourceHandlePosition.center, sourceHandleEdgeCenter, t);
|
||||
}
|
||||
else if (droplet > 1 - handleAlignmentMargin)
|
||||
{
|
||||
var t = (droplet - (1 - handleAlignmentMargin)) / handleAlignmentMargin;
|
||||
position = Vector2.Lerp(destinationHandleEdgeCenter, destinationHandlePosition.center, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
var t = (droplet - handleAlignmentMargin) / (1 - 2 * handleAlignmentMargin);
|
||||
position = GraphGUI.GetPointOnConnection(t, sourceHandleEdgeCenter, destinationHandleEdgeCenter, Edge.Right, Edge.Left, UnitConnectionStyles.relativeBend, UnitConnectionStyles.minBend);
|
||||
}
|
||||
|
||||
var size = GetDropletSize();
|
||||
|
||||
using (LudiqGUI.color.Override(GUI.color * color))
|
||||
{
|
||||
DrawDroplet(new Rect(position.x - size.x / 2, position.y - size.y / 2, size.x, size.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e9d80f8d221a84498906e6f54205e6d3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,150 @@
|
|||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
[Widget(typeof(ValueConnection))]
|
||||
public sealed class ValueConnectionWidget : UnitConnectionWidget<ValueConnection>
|
||||
{
|
||||
public ValueConnectionWidget(FlowCanvas canvas, ValueConnection connection) : base(canvas, connection) { }
|
||||
|
||||
private new ValueConnection.DebugData ConnectionDebugData => GetDebugData<ValueConnection.DebugData>();
|
||||
|
||||
|
||||
#region Drawing
|
||||
|
||||
public override Color color => DetermineColor(connection.source.type, connection.destination.type);
|
||||
|
||||
protected override bool colorIfActive => !BoltFlow.Configuration.animateControlConnections || !BoltFlow.Configuration.animateValueConnections;
|
||||
|
||||
public override void DrawForeground()
|
||||
{
|
||||
base.DrawForeground();
|
||||
|
||||
if (BoltFlow.Configuration.showConnectionValues)
|
||||
{
|
||||
var showLastValue = EditorApplication.isPlaying && ConnectionDebugData.assignedLastValue;
|
||||
var showPredictedvalue = BoltFlow.Configuration.predictConnectionValues && !EditorApplication.isPlaying && Flow.CanPredict(connection.source, reference);
|
||||
|
||||
if (showLastValue || showPredictedvalue)
|
||||
{
|
||||
var previousIconSize = EditorGUIUtility.GetIconSize();
|
||||
EditorGUIUtility.SetIconSize(new Vector2(IconSize.Small, IconSize.Small));
|
||||
|
||||
object value;
|
||||
|
||||
if (showLastValue)
|
||||
{
|
||||
value = ConnectionDebugData.lastValue;
|
||||
}
|
||||
else // if (showPredictedvalue)
|
||||
{
|
||||
value = Flow.Predict(connection.source, reference);
|
||||
}
|
||||
|
||||
var label = new GUIContent(value.ToShortString(), Icons.Type(value?.GetType())?[IconSize.Small]);
|
||||
var labelSize = Styles.prediction.CalcSize(label);
|
||||
var labelPosition = new Rect(position.position - labelSize / 2, labelSize);
|
||||
|
||||
BeginDim();
|
||||
|
||||
GUI.Label(labelPosition, label, Styles.prediction);
|
||||
|
||||
EndDim();
|
||||
|
||||
EditorGUIUtility.SetIconSize(previousIconSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Color DetermineColor(Type source, Type destination)
|
||||
{
|
||||
if (destination == typeof(object))
|
||||
{
|
||||
return DetermineColor(source);
|
||||
}
|
||||
|
||||
return DetermineColor(destination);
|
||||
}
|
||||
|
||||
public static Color DetermineColor(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
return new Color(0.8f, 0.8f, 0.8f);
|
||||
}
|
||||
|
||||
if (type == typeof(string))
|
||||
{
|
||||
return new Color(1.0f, 0.62f, 0.35f);
|
||||
}
|
||||
|
||||
if (type == typeof(bool))
|
||||
{
|
||||
return new Color(0.86f, 0.55f, 0.92f);
|
||||
}
|
||||
|
||||
if (type == typeof(char))
|
||||
{
|
||||
return new Color(1.0f, 0.90f, 0.40f);
|
||||
}
|
||||
|
||||
if (type.IsEnum)
|
||||
{
|
||||
return new Color(1.0f, 0.63f, 0.66f);
|
||||
}
|
||||
|
||||
if (type.IsNumeric())
|
||||
{
|
||||
return new Color(0.45f, 0.78f, 1f);
|
||||
}
|
||||
|
||||
if (type.IsNumericConstruct())
|
||||
{
|
||||
return new Color(0.45f, 1.00f, 0.82f);
|
||||
}
|
||||
|
||||
return new Color(0.60f, 0.88f, 0.00f);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Droplets
|
||||
|
||||
protected override bool showDroplets => BoltFlow.Configuration.animateValueConnections;
|
||||
|
||||
protected override Vector2 GetDropletSize()
|
||||
{
|
||||
return BoltFlow.Icons.valuePortConnected?[12].Size() ?? 12 * Vector3.one;
|
||||
}
|
||||
|
||||
protected override void DrawDroplet(Rect position)
|
||||
{
|
||||
if (BoltFlow.Icons.valuePortConnected != null)
|
||||
{
|
||||
GUI.DrawTexture(position, BoltFlow.Icons.valuePortConnected?[12]);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
private static class Styles
|
||||
{
|
||||
static Styles()
|
||||
{
|
||||
prediction = new GUIStyle(EditorStyles.label);
|
||||
prediction.normal.textColor = Color.white;
|
||||
prediction.fontSize = 9;
|
||||
prediction.normal.background = new Color(0, 0, 0, 0.25f).GetPixel();
|
||||
prediction.padding = new RectOffset(4, 6, 3, 3);
|
||||
prediction.margin = new RectOffset(0, 0, 0, 0);
|
||||
prediction.alignment = TextAnchor.MiddleCenter;
|
||||
}
|
||||
|
||||
public static readonly GUIStyle prediction;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b1568bb10360a435d9c58e96f304fa98
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue