Initial Commit

This commit is contained in:
Sebastian Cabrera 2021-08-02 05:44:37 -04:00
parent 53eb92e9af
commit 270ab7d11f
15341 changed files with 700234 additions and 0 deletions

View file

@ -0,0 +1,8 @@
namespace Unity.VisualScripting
{
[Descriptor(typeof(AnyState))]
public class AnyStateDescriptor : StateDescriptor<AnyState>
{
public AnyStateDescriptor(AnyState state) : base(state) { }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0ae8021e59c334368b5ae08b2adfcfaf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,18 @@
namespace Unity.VisualScripting
{
[Widget(typeof(AnyState))]
public class AnyStateWidget : StateWidget<AnyState>
{
public AnyStateWidget(StateCanvas canvas, AnyState state) : base(canvas, state) { }
protected override NodeColorMix color => NodeColorMix.TealReadable;
protected override string summary => null;
public override bool canToggleStart => false;
public override bool canForceEnter => false;
public override bool canForceExit => false;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e7f4def392c07401096915e803a01ebf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
namespace Unity.VisualScripting
{
[Descriptor(typeof(FlowState))]
public class FlowStateDescriptor : NesterStateDescriptor<FlowState>
{
public FlowStateDescriptor(FlowState state) : base(state) { }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f66f8803a57c44b2eb4880f870823740
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
namespace Unity.VisualScripting
{
[Editor(typeof(FlowState))]
public sealed class FlowStateEditor : NesterStateEditor
{
public FlowStateEditor(Metadata metadata) : base(metadata) { }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5290affe00001419e8971554534f83f5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,231 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace Unity.VisualScripting
{
[Widget(typeof(FlowState))]
public sealed class FlowStateWidget : NesterStateWidget<FlowState>, IDragAndDropHandler
{
public FlowStateWidget(StateCanvas canvas, FlowState state) : base(canvas, state)
{
state.nest.beforeGraphChange += BeforeGraphChange;
state.nest.afterGraphChange += AfterGraphChange;
if (state.nest.graph != null)
{
state.nest.graph.elements.CollectionChanged += CacheEventLinesOnUnityThread;
}
}
public override void Dispose()
{
base.Dispose();
state.nest.beforeGraphChange -= BeforeGraphChange;
state.nest.afterGraphChange -= AfterGraphChange;
}
private void BeforeGraphChange()
{
if (state.nest.graph != null)
{
state.nest.graph.elements.CollectionChanged -= CacheEventLinesOnUnityThread;
}
}
private void AfterGraphChange()
{
CacheEventLinesOnUnityThread();
if (state.nest.graph != null)
{
state.nest.graph.elements.CollectionChanged += CacheEventLinesOnUnityThread;
}
}
#region Model
private List<EventLine> eventLines { get; } = new List<EventLine>();
private void CacheEventLinesOnUnityThread()
{
UnityAPI.Async(CacheEventLines);
}
private void CacheEventLines()
{
eventLines.Clear();
if (state.nest.graph != null)
{
eventLines.AddRange(state.nest.graph.units
.OfType<IEventUnit>()
.Select(e => e.GetType())
.Distinct()
.Select(eventType => new EventLine(eventType))
.OrderBy(eventLine => eventLine.content.text));
}
Reposition();
}
protected override void CacheItemFirstTime()
{
base.CacheItemFirstTime();
CacheEventLines();
}
#endregion
#region Positioning
public Dictionary<EventLine, Rect> eventLinesPositions { get; } = new Dictionary<EventLine, Rect>();
public override void CachePosition()
{
base.CachePosition();
eventLinesPositions.Clear();
var y = contentInnerPosition.y;
foreach (var eventLine in eventLines)
{
var eventLinePosition = new Rect
(
contentInnerPosition.x,
y,
contentInnerPosition.width,
eventLine.GetHeight(contentInnerPosition.width)
);
eventLinesPositions.Add(eventLine, eventLinePosition);
y += eventLinePosition.height;
}
}
protected override float GetContentHeight(float width)
{
var eventLinesHeight = 0f;
foreach (var eventLine in eventLines)
{
eventLinesHeight += eventLine.GetHeight(width);
}
return eventLinesHeight;
}
#endregion
#region Drawing
protected override bool showContent => eventLines.Count > 0;
protected override void DrawContent()
{
foreach (var eventLine in eventLines)
{
eventLine.Draw(eventLinesPositions[eventLine]);
}
}
#endregion
#region Drag & Drop
public DragAndDropVisualMode dragAndDropVisualMode => DragAndDropVisualMode.Generic;
public bool AcceptsDragAndDrop()
{
return DragAndDropUtility.Is<ScriptGraphAsset>();
}
public void PerformDragAndDrop()
{
UndoUtility.RecordEditedObject("Drag & Drop Macro");
state.nest.source = GraphSource.Macro;
state.nest.macro = DragAndDropUtility.Get<ScriptGraphAsset>();
state.nest.embed = null;
GUI.changed = true;
}
public void UpdateDragAndDrop() { }
public void DrawDragAndDropPreview()
{
GraphGUI.DrawDragAndDropPreviewLabel(new Vector2(edgePosition.x, outerPosition.yMax), "Replace with: " + DragAndDropUtility.Get<ScriptGraphAsset>().name, typeof(ScriptGraphAsset).Icon());
}
public void ExitDragAndDrop() { }
#endregion
public new static class Styles
{
static Styles()
{
eventLine = new GUIStyle(EditorStyles.label);
eventLine.wordWrap = true;
eventLine.imagePosition = ImagePosition.TextOnly; // The icon is drawn manually
eventLine.padding = new RectOffset(0, 0, 3, 3);
}
public static readonly GUIStyle eventLine;
public static readonly float spaceAroundLineIcon = 5;
}
public class EventLine
{
public EventLine(Type eventType)
{
content = new GUIContent(BoltFlowNameUtility.UnitTitle(eventType, false, true), eventType.Icon()?[IconSize.Small]);
}
public GUIContent content { get; }
public float GetHeight(float width)
{
var labelWidth = width - Styles.spaceAroundLineIcon - IconSize.Small - Styles.spaceAroundLineIcon;
return Styles.eventLine.CalcHeight(content, labelWidth);
}
public void Draw(Rect position)
{
var iconPosition = new Rect
(
position.x + Styles.spaceAroundLineIcon,
position.y + Styles.eventLine.padding.top - 1,
IconSize.Small,
IconSize.Small
);
var labelPosition = new Rect
(
iconPosition.xMax + Styles.spaceAroundLineIcon,
position.y,
position.width - Styles.spaceAroundLineIcon - iconPosition.width - Styles.spaceAroundLineIcon,
position.height
);
if (content.image != null)
{
GUI.DrawTexture(iconPosition, content.image);
}
GUI.Label(labelPosition, content, Styles.eventLine);
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d891a8dfd0a4d464897c1598d1a0f5a0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,7 @@
namespace Unity.VisualScripting
{
public interface IStateWidget : IGraphElementWidget
{
IState state { get; }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a560e5c5437a44f2db6a4291e7ea9182
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,29 @@
using System.Collections.Generic;
namespace Unity.VisualScripting
{
[Analyser(typeof(INesterState))]
public class NesterStateAnalyser<TNesterState> : StateAnalyser<TNesterState>
where TNesterState : class, INesterState
{
public NesterStateAnalyser(GraphReference reference, TNesterState state) : base(reference, state) { }
protected override IEnumerable<Warning> Warnings()
{
foreach (var baseWarning in base.Warnings())
{
yield return baseWarning;
}
if (state.childGraph == null)
{
yield return Warning.Caution("Missing nested graph.");
}
if (state.nest.hasBackgroundEmbed)
{
yield return Warning.Caution("Background embed graph detected.");
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2bca8b8e70d8942bc9e0bed5eddf855d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,21 @@
namespace Unity.VisualScripting
{
[Descriptor(typeof(INesterState))]
public class NesterStateDescriptor<TNesterState> : StateDescriptor<TNesterState>
where TNesterState : class, INesterState
{
public NesterStateDescriptor(TNesterState state) : base(state) { }
[RequiresUnityAPI]
public override string Title()
{
return GraphNesterDescriptor.Title(state);
}
[RequiresUnityAPI]
public override string Summary()
{
return GraphNesterDescriptor.Summary(state);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e5353b3c45ba346d2ae924e8c15518cd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,30 @@
using UnityEngine;
namespace Unity.VisualScripting
{
[Editor(typeof(INesterState))]
public class NesterStateEditor : StateEditor
{
public NesterStateEditor(Metadata metadata) : base(metadata) { }
private Metadata nestMetadata => metadata[nameof(INesterState.nest)];
private Metadata graphMetadata => nestMetadata[nameof(IGraphNest.graph)];
protected override GraphReference headerReference => reference.ChildReference((INesterState)metadata.value, false);
protected override Metadata headerTitleMetadata => graphMetadata[nameof(IGraph.title)];
protected override Metadata headerSummaryMetadata => graphMetadata[nameof(IGraph.summary)];
protected override float GetInspectorHeight(float width)
{
return LudiqGUI.GetEditorHeight(this, nestMetadata, width);
}
protected override void OnInspectorGUI(Rect position)
{
LudiqGUI.Editor(nestMetadata, position);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 26fe4d37196fc4b978c8d67f2bf58df3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
namespace Unity.VisualScripting
{
public abstract class NesterStateWidget<TNesterState> : StateWidget<TNesterState>
where TNesterState : class, INesterState
{
protected NesterStateWidget(StateCanvas canvas, TNesterState state) : base(canvas, state) { }
protected override IEnumerable<DropdownOption> contextOptions
{
get
{
var childReference = reference.ChildReference(state, false);
if (state.childGraph != null)
{
yield return new DropdownOption((Action)(() => window.reference = childReference), "Open");
yield return new DropdownOption((Action)(() => GraphWindow.OpenTab(childReference)), "Open in new window");
}
foreach (var baseOption in base.contextOptions)
{
yield return baseOption;
}
}
}
protected override void OnDoubleClick()
{
if (state.graph.zoom == 1)
{
var childReference = reference.ChildReference(state, false);
if (childReference != null)
{
if (e.ctrlOrCmd)
{
GraphWindow.OpenTab(childReference);
}
else
{
window.reference = childReference;
}
}
e.Use();
}
else
{
base.OnDoubleClick();
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8143bcca23d9e4377b5974c05f42e6dc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,57 @@
using System.Collections.Generic;
namespace Unity.VisualScripting
{
[Analyser(typeof(IState))]
public class StateAnalyser<TState> : Analyser<TState, StateAnalysis>
where TState : class, IState
{
public StateAnalyser(GraphReference reference, TState target) : base(reference, target) { }
public TState state => target;
[Assigns]
protected virtual bool IsEntered()
{
using (var recursion = Recursion.New(1))
{
return IsEntered(state, recursion);
}
}
[Assigns]
protected virtual IEnumerable<Warning> Warnings()
{
if (!IsEntered())
{
yield return Warning.Info("State is never entered.");
}
}
private bool IsEntered(IState state, Recursion recursion)
{
if (state.isStart)
{
return true;
}
if (!recursion?.TryEnter(state) ?? false)
{
return false;
}
foreach (var incomingTransition in state.incomingTransitions)
{
if (IsEntered(incomingTransition.source, recursion) && incomingTransition.Analysis<StateTransitionAnalysis>(context).isTraversed)
{
recursion?.Exit(state);
return true;
}
}
recursion?.Exit(state);
return false;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eb1a4bbdbfdb14545866ce6d30badb33
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,7 @@
namespace Unity.VisualScripting
{
public sealed class StateAnalysis : GraphElementAnalysis
{
public bool isEntered { get; set; }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 90539a84ee39e4c2493af60a32b9adb4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,6 @@
namespace Unity.VisualScripting
{
public sealed class StateDescription : GraphElementDescription
{
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e2102ddc23fbd412ca4aaec620483938
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,30 @@
namespace Unity.VisualScripting
{
[Descriptor(typeof(IState))]
public class StateDescriptor<TState> : Descriptor<TState, StateDescription>
where TState : class, IState
{
public StateDescriptor(TState target) : base(target) { }
public TState state => target;
[Assigns]
public override string Title()
{
return state.GetType().HumanName();
}
[Assigns]
public override string Summary()
{
return state.GetType().Summary();
}
[Assigns]
[RequiresUnityAPI]
public override EditorTexture Icon()
{
return state.GetType().Icon();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c2ac946d6d90843948d6f9062367a87e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,12 @@
namespace Unity.VisualScripting
{
[Editor(typeof(IState))]
public class StateEditor : GraphElementEditor<StateGraphContext>
{
public StateEditor(Metadata metadata) : base(metadata) { }
protected IState state => (IState)element;
protected new StateDescription description => (StateDescription)base.description;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: af7367866b51441ce9687566c007cb62
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,7 @@
namespace Unity.VisualScripting
{
public sealed class StateTransitionAnalysis : GraphElementAnalysis
{
public bool isTraversed { get; set; }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 920ab3a8f1eff44d99181bd337fb849a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,632 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace Unity.VisualScripting
{
public abstract class StateWidget<TState> : NodeWidget<StateCanvas, TState>, IStateWidget
where TState : class, IState
{
protected StateWidget(StateCanvas canvas, TState state) : base(canvas, state)
{
minResizeSize = new Vector2(State.DefaultWidth, 0);
}
public virtual bool canForceEnter => true;
public virtual bool canForceExit => true;
public virtual bool canToggleStart => true;
#region Model
protected TState state => element;
protected IStateDebugData stateDebugData => GetDebugData<IStateDebugData>();
protected State.Data stateData => reference.hasData ? reference.GetElementData<State.Data>(state) : null;
IState IStateWidget.state => state;
protected StateDescription description { get; private set; }
protected StateAnalysis analysis => state.Analysis<StateAnalysis>(context);
protected override void CacheDescription()
{
description = state.Description<StateDescription>();
title = description.title;
summary = description.summary;
titleContent.text = " " + title;
titleContent.image = description.icon?[IconSize.Small];
summaryContent.text = summary;
Reposition();
}
#endregion
#region Lifecycle
public override void BeforeFrame()
{
base.BeforeFrame();
if (currentContentOuterHeight != targetContentOuterHeight)
{
Reposition();
}
}
public override void HandleInput()
{
if (e.IsMouseDrag(MouseButton.Left) &&
e.ctrlOrCmd &&
!canvas.isCreatingTransition)
{
if (state.canBeSource)
{
canvas.StartTransition(state);
}
else
{
Debug.LogWarning("Cannot create a transition from this state.\n");
}
e.Use();
}
else if (e.IsMouseDrag(MouseButton.Left) && canvas.isCreatingTransition)
{
e.Use();
}
else if (e.IsMouseUp(MouseButton.Left) && canvas.isCreatingTransition)
{
var source = canvas.transitionSource;
var destination = (canvas.hoveredWidget as IStateWidget)?.state;
if (destination == null)
{
canvas.CompleteTransitionToNewState();
}
else if (destination == source)
{
canvas.CancelTransition();
}
else if (destination.canBeDestination)
{
canvas.EndTransition(destination);
}
else
{
Debug.LogWarning("Cannot create a transition to this state.\n");
canvas.CancelTransition();
}
e.Use();
}
base.HandleInput();
}
#endregion
#region Contents
protected virtual string title { get; set; }
protected virtual string summary { get; set; }
private GUIContent titleContent { get; } = new GUIContent();
private GUIContent summaryContent { get; } = new GUIContent();
#endregion
#region Positioning
public override IEnumerable<IWidget> positionDependers => state.transitions.Select(transition => (IWidget)canvas.Widget(transition));
public Rect titlePosition { get; private set; }
public Rect summaryPosition { get; private set; }
public Rect contentOuterPosition { get; private set; }
public Rect contentBackgroundPosition { get; private set; }
public Rect contentInnerPosition { get; private set; }
private float targetContentOuterHeight;
private float currentContentOuterHeight;
private bool revealInitialized;
private Rect _position;
public override Rect position
{
get { return _position; }
set
{
state.position = value.position;
state.width = value.width;
}
}
public override void CachePosition()
{
var edgeOrigin = state.position;
var edgeX = edgeOrigin.x;
var edgeY = edgeOrigin.y;
var edgeWidth = state.width;
var innerOrigin = EdgeToInnerPosition(new Rect(edgeOrigin, Vector2.zero)).position;
var innerX = innerOrigin.x;
var innerY = innerOrigin.y;
var innerWidth = EdgeToInnerPosition(new Rect(0, 0, edgeWidth, 0)).width;
var innerHeight = 0f;
var y = innerY;
if (showTitle)
{
using (LudiqGUIUtility.iconSize.Override(IconSize.Small))
{
titlePosition = new Rect
(
innerX,
y,
innerWidth,
Styles.title.CalcHeight(titleContent, innerWidth)
);
y += titlePosition.height;
innerHeight += titlePosition.height;
}
}
if (showTitle && showSummary)
{
y += Styles.spaceBetweenTitleAndSummary;
innerHeight += Styles.spaceBetweenTitleAndSummary;
}
if (showSummary)
{
summaryPosition = new Rect
(
innerX,
y,
innerWidth,
Styles.summary.CalcHeight(summaryContent, innerWidth)
);
y += summaryPosition.height;
innerHeight += summaryPosition.height;
}
if (showContent)
{
var contentInnerWidth = edgeWidth - Styles.contentBackground.padding.left - Styles.contentBackground.padding.right;
targetContentOuterHeight = revealContent ? (Styles.spaceBeforeContent + Styles.contentBackground.padding.top + GetContentHeight(contentInnerWidth) + Styles.contentBackground.padding.bottom) : 0;
if (!revealInitialized)
{
currentContentOuterHeight = targetContentOuterHeight;
revealInitialized = true;
}
currentContentOuterHeight = Mathf.Lerp(currentContentOuterHeight, targetContentOuterHeight, canvas.repaintDeltaTime * Styles.contentRevealSpeed);
if (Mathf.Abs(targetContentOuterHeight - currentContentOuterHeight) < 1)
{
currentContentOuterHeight = targetContentOuterHeight;
}
contentOuterPosition = new Rect
(
edgeX,
y,
edgeWidth,
currentContentOuterHeight
);
contentBackgroundPosition = new Rect
(
0,
Styles.spaceBeforeContent,
edgeWidth,
currentContentOuterHeight - Styles.spaceBeforeContent
);
contentInnerPosition = new Rect
(
Styles.contentBackground.padding.left,
Styles.spaceBeforeContent + Styles.contentBackground.padding.top,
contentInnerWidth,
contentBackgroundPosition.height - Styles.contentBackground.padding.top
);
y += contentOuterPosition.height;
innerHeight += contentOuterPosition.height;
}
var edgeHeight = InnerToEdgePosition(new Rect(0, 0, 0, innerHeight)).height;
_position = new Rect
(
edgeX,
edgeY,
edgeWidth,
edgeHeight
);
}
protected virtual float GetContentHeight(float width) => 0;
#endregion
#region Drawing
protected virtual bool showTitle => true;
protected virtual bool showSummary => !StringUtility.IsNullOrWhiteSpace(summary);
protected virtual bool showContent => false;
protected virtual NodeColorMix baseColor => NodeColor.Gray;
protected override NodeColorMix color
{
get
{
if (stateDebugData.runtimeException != null)
{
return NodeColor.Red;
}
var color = baseColor;
if (state.isStart)
{
color = NodeColor.Green;
}
if (stateData?.isActive ?? false)
{
color = NodeColor.Blue;
}
else if (EditorApplication.isPaused)
{
if (EditorTimeBinding.frame == stateDebugData.lastEnterFrame)
{
color = NodeColor.Blue;
}
}
else
{
color.blue = Mathf.Lerp(1, 0, (EditorTimeBinding.time - stateDebugData.lastExitTime) / Styles.enterFadeDuration);
}
return color;
}
}
protected override NodeShape shape => NodeShape.Square;
private bool revealContent
{
get
{
switch (BoltState.Configuration.statesReveal)
{
case StateRevealCondition.Always:
return true;
case StateRevealCondition.Never:
return false;
case StateRevealCondition.OnHover:
return isMouseOver;
case StateRevealCondition.OnHoverWithAlt:
return isMouseOver && e.alt;
case StateRevealCondition.WhenSelected:
return selection.Contains(state);
case StateRevealCondition.OnHoverOrSelected:
return isMouseOver || selection.Contains(state);
case StateRevealCondition.OnHoverWithAltOrSelected:
return isMouseOver && e.alt || selection.Contains(state);
default:
throw new UnexpectedEnumValueException<StateRevealCondition>(BoltState.Configuration.statesReveal);
}
}
}
private bool revealedContent;
private void CheckReveal()
{
var revealContent = this.revealContent;
if (revealContent != revealedContent)
{
Reposition();
}
revealedContent = revealContent;
}
protected override bool dim
{
get
{
var dim = BoltCore.Configuration.dimInactiveNodes && !analysis.isEntered;
if (isMouseOver || isSelected)
{
dim = false;
}
return dim;
}
}
public override void DrawForeground()
{
BeginDim();
base.DrawForeground();
if (showTitle)
{
DrawTitle();
}
if (showSummary)
{
DrawSummary();
}
if (showContent)
{
DrawContentWrapped();
}
EndDim();
CheckReveal();
}
private void DrawTitle()
{
using (LudiqGUIUtility.iconSize.Override(IconSize.Small))
{
GUI.Label(titlePosition, titleContent, invertForeground ? Styles.titleInverted : Styles.title);
}
}
private void DrawSummary()
{
GUI.Label(summaryPosition, summaryContent, invertForeground ? Styles.summaryInverted : Styles.summary);
}
private void DrawContentWrapped()
{
GUI.BeginClip(contentOuterPosition);
DrawContentBackground();
DrawContent();
GUI.EndClip();
}
protected virtual void DrawContentBackground()
{
if (e.IsRepaint)
{
Styles.contentBackground.Draw(contentBackgroundPosition, false, false, false, false);
}
}
protected virtual void DrawContent() { }
#endregion
#region Selecting
public override bool canSelect => true;
#endregion
#region Dragging
protected override bool snapToGrid => BoltCore.Configuration.snapToGrid;
public override bool canDrag => true;
public override void ExpandDragGroup(HashSet<IGraphElement> dragGroup)
{
if (BoltCore.Configuration.carryChildren)
{
foreach (var transition in state.outgoingTransitions)
{
if (dragGroup.Contains(transition.destination))
{
continue;
}
dragGroup.Add(transition.destination);
canvas.Widget(transition.destination).ExpandDragGroup(dragGroup);
}
}
}
#endregion
#region Deleting
public override bool canDelete => true;
#endregion
#region Resizing
public override bool canResizeHorizontal => true;
#endregion
#region Clipboard
public override void ExpandCopyGroup(HashSet<IGraphElement> copyGroup)
{
copyGroup.UnionWith(state.transitions.Cast<IGraphElement>());
}
#endregion
#region Actions
protected override IEnumerable<DropdownOption> contextOptions
{
get
{
if (Application.isPlaying && reference.hasData)
{
if (canForceEnter)
{
yield return new DropdownOption((Action)ForceEnter, "Force Enter");
}
if (canForceExit)
{
yield return new DropdownOption((Action)ForceExit, "Force Exit");
}
}
if (canToggleStart)
{
yield return new DropdownOption((Action)ToggleStart, "Toggle Start");
}
if (state.canBeSource)
{
yield return new DropdownOption((Action)MakeTransition, "Make Transition");
}
if (state.canBeSource && state.canBeDestination)
{
yield return new DropdownOption((Action)MakeSelfTransition, "Make Self Transition");
}
foreach (var baseOption in base.contextOptions)
{
yield return baseOption;
}
}
}
private void ForceEnter()
{
using (var flow = Flow.New(reference))
{
state.OnEnter(flow, StateEnterReason.Forced);
}
}
private void ForceExit()
{
using (var flow = Flow.New(reference))
{
state.OnExit(flow, StateExitReason.Forced);
}
}
protected void MakeTransition()
{
canvas.StartTransition(state);
}
protected void MakeSelfTransition()
{
canvas.StartTransition(state);
canvas.EndTransition(state);
}
protected void ToggleStart()
{
UndoUtility.RecordEditedObject("Toggle State Start");
state.isStart = !state.isStart;
}
#endregion
public static class Styles
{
static Styles()
{
title = new GUIStyle(BoltCore.Styles.nodeLabel);
title.fontSize = 12;
title.alignment = TextAnchor.MiddleCenter;
title.wordWrap = true;
summary = new GUIStyle(BoltCore.Styles.nodeLabel);
summary.fontSize = 10;
summary.alignment = TextAnchor.MiddleCenter;
summary.wordWrap = true;
titleInverted = new GUIStyle(title);
titleInverted.normal.textColor = ColorPalette.unityBackgroundDark;
summaryInverted = new GUIStyle(summary);
summaryInverted.normal.textColor = ColorPalette.unityBackgroundDark;
contentBackground = new GUIStyle("In BigTitle");
contentBackground.padding = new RectOffset(0, 0, 4, 4);
}
public static readonly GUIStyle title;
public static readonly GUIStyle summary;
public static readonly GUIStyle titleInverted;
public static readonly GUIStyle summaryInverted;
public static readonly GUIStyle contentBackground;
public static readonly float spaceBeforeContent = 5;
public static readonly float spaceBetweenTitleAndSummary = 0;
public static readonly float enterFadeDuration = 0.5f;
public static readonly float contentRevealSpeed = 15;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 03a1be6398ca64d4fa9e4810eb77c472
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
namespace Unity.VisualScripting
{
[Descriptor(typeof(SuperState))]
public class SuperStateDescriptor : NesterStateDescriptor<SuperState>
{
public SuperStateDescriptor(SuperState state) : base(state) { }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7079eea8915904f1aa73089daa0789e4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
namespace Unity.VisualScripting
{
[Editor(typeof(SuperState))]
public sealed class SuperStateEditor : NesterStateEditor
{
public SuperStateEditor(Metadata metadata) : base(metadata) { }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 14623fc883ca546f2af2de01ae7a8590
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,44 @@
using UnityEditor;
using UnityEngine;
namespace Unity.VisualScripting
{
[Widget(typeof(SuperState))]
public sealed class SuperStateWidget : NesterStateWidget<SuperState>, IDragAndDropHandler
{
public SuperStateWidget(StateCanvas canvas, SuperState state) : base(canvas, state) { }
#region Drag & Drop
public DragAndDropVisualMode dragAndDropVisualMode => DragAndDropVisualMode.Generic;
public bool AcceptsDragAndDrop()
{
return DragAndDropUtility.Is<StateGraphAsset>();
}
public void PerformDragAndDrop()
{
UndoUtility.RecordEditedObject("Drag & Drop Macro");
state.nest.source = GraphSource.Macro;
state.nest.macro = DragAndDropUtility.Get<StateGraphAsset>();
state.nest.embed = null;
GUI.changed = true;
}
public void UpdateDragAndDrop()
{
}
public void DrawDragAndDropPreview()
{
GraphGUI.DrawDragAndDropPreviewLabel(new Vector2(edgePosition.x, outerPosition.yMax), "Replace with: " + DragAndDropUtility.Get<StateGraphAsset>().name, typeof(StateGraphAsset).Icon());
}
public void ExitDragAndDrop()
{
}
#endregion
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 99e3f3703a7fd4b78928d46762518767
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: