This commit is contained in:
2021-06-13 10:28:03 +02:00
parent eb70603c85
commit df2d24cbd3
7487 changed files with 943244 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Unity.VisualScripting
{
[Analyser(typeof(For))]
public class ForAnalyser : UnitAnalyser<For>
{
public ForAnalyser(GraphReference reference, For target)
: base(reference, target) { }
protected override IEnumerable<Warning> Warnings()
{
foreach (var baseWarning in base.Warnings())
{
yield return baseWarning;
}
if (unit.IsStepValueZero())
{
yield return Warning.Caution("The step value is 0. This will prevent the For unit to be executed or can cause an infinite loop.");
}
}
}
}

View File

@@ -0,0 +1,19 @@
namespace Unity.VisualScripting
{
[Descriptor(typeof(ForEach))]
public class ForEachDescriptor : UnitDescriptor<ForEach>
{
public ForEachDescriptor(ForEach unit) : base(unit) { }
protected override void DefinedPort(IUnitPort port, UnitPortDescription description)
{
base.DefinedPort(port, description);
if (unit.dictionary && port == unit.currentItem)
{
description.label = "Value";
description.summary = "The value of the current item of the loop.";
}
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
namespace Unity.VisualScripting
{
[Descriptor(typeof(SelectOnEnum))]
public class SelectOnEnumDescriptor : UnitDescriptor<SelectOnEnum>
{
public SelectOnEnumDescriptor(SelectOnEnum unit) : base(unit) { }
protected override void DefinedPort(IUnitPort port, UnitPortDescription description)
{
base.DefinedPort(port, description);
foreach (var branch in unit.branches)
{
if (branch.Value == port)
{
var enumValue = (Enum)branch.Key;
description.label = enumValue.DisplayName();
description.summary = $"The value to return if the enum has the value '{enumValue}'.";
}
}
}
}
}

View File

@@ -0,0 +1,34 @@
namespace Unity.VisualScripting
{
[Descriptor(typeof(SelectOnFlow))]
public class SelectOnFlowDescriptor : UnitDescriptor<SelectOnFlow>
{
public SelectOnFlowDescriptor(SelectOnFlow unit) : base(unit) { }
protected override void DefinedPort(IUnitPort port, UnitPortDescription description)
{
base.DefinedPort(port, description);
foreach (var branch in unit.branches)
{
if (port == branch.Key || port == branch.Value)
{
var index = int.Parse(port.key.PartAfter('_'));
var letter = ((char)('A' + index)).ToString();
description.label = letter;
if (port == branch.Key)
{
description.summary = $"Trigger to select the {letter} value.";
}
else if (port == branch.Value)
{
description.summary = $"The value to return if the {letter} control input is triggered.";
}
}
}
}
}
}

View File

@@ -0,0 +1,13 @@
namespace Unity.VisualScripting
{
[Descriptor(typeof(SelectOnInteger))]
public class SelectOnIntegerDescriptor : SelectUnitDescriptor<int>
{
public SelectOnIntegerDescriptor(SelectOnInteger unit) : base(unit) { }
protected override string GetLabelForOption(int option)
{
return option.ToString();
}
}
}

View File

@@ -0,0 +1,18 @@
namespace Unity.VisualScripting
{
[Descriptor(typeof(SelectOnString))]
public class SelectOnStringDescriptor : SelectUnitDescriptor<string>
{
public SelectOnStringDescriptor(SelectOnString unit) : base(unit) { }
protected override string GetLabelForOption(string option)
{
if (string.IsNullOrEmpty(option))
{
return "Null / Empty";
}
return $"\"{option}\"";
}
}
}

View File

@@ -0,0 +1,28 @@
namespace Unity.VisualScripting
{
public class SelectUnitDescriptor<T> : UnitDescriptor<SelectUnit<T>>
{
public SelectUnitDescriptor(SelectUnit<T> unit) : base(unit) { }
protected virtual string GetLabelForOption(T option)
{
return option.ToString();
}
protected override void DefinedPort(IUnitPort port, UnitPortDescription description)
{
base.DefinedPort(port, description);
foreach (var branch in unit.branches)
{
if (branch.Value == port)
{
var option = branch.Key;
description.label = GetLabelForOption(option);
description.summary = $"The value to return if the enum has the value {GetLabelForOption(option)}.";
}
}
}
}
}

View File

@@ -0,0 +1,23 @@
namespace Unity.VisualScripting
{
[Descriptor(typeof(Sequence))]
public class SequenceDescriptor : UnitDescriptor<Sequence>
{
public SequenceDescriptor(Sequence unit) : base(unit) { }
protected override void DefinedPort(IUnitPort port, UnitPortDescription description)
{
base.DefinedPort(port, description);
if (port is ControlOutput)
{
var index = unit.multiOutputs.IndexOf((ControlOutput)port);
if (index >= 0)
{
description.label = index.ToString();
}
}
}
}
}

View File

@@ -0,0 +1,23 @@
namespace Unity.VisualScripting
{
[Descriptor(typeof(SwitchOnEnum))]
public class SwitchOnEnumDescriptor : UnitDescriptor<SwitchOnEnum>
{
public SwitchOnEnumDescriptor(SwitchOnEnum unit) : base(unit) { }
protected override void DefinedPort(IUnitPort port, UnitPortDescription description)
{
base.DefinedPort(port, description);
foreach (var branch in unit.branches)
{
if (branch.Value == port)
{
var enumValue = branch.Key;
description.label = enumValue.DisplayName();
description.summary = $"The action to execute if the enum has the value '{enumValue}'.";
}
}
}
}
}

View File

@@ -0,0 +1,13 @@
namespace Unity.VisualScripting
{
[Descriptor(typeof(SwitchOnInteger))]
public class SwitchOnIntegerDescriptor : SwitchUnitDescriptor<int>
{
public SwitchOnIntegerDescriptor(SwitchOnInteger unit) : base(unit) { }
protected override string GetLabelForOption(int option)
{
return option.ToString();
}
}
}

View File

@@ -0,0 +1,18 @@
namespace Unity.VisualScripting
{
[Descriptor(typeof(SwitchOnString))]
public class SwitchOnStringDescriptor : SwitchUnitDescriptor<string>
{
public SwitchOnStringDescriptor(SwitchOnString unit) : base(unit) { }
protected override string GetLabelForOption(string option)
{
if (string.IsNullOrEmpty(option))
{
return "Null / Empty";
}
return $"\"{option}\"";
}
}
}

View File

@@ -0,0 +1,28 @@
namespace Unity.VisualScripting
{
public class SwitchUnitDescriptor<T> : UnitDescriptor<SwitchUnit<T>>
{
public SwitchUnitDescriptor(SwitchUnit<T> unit) : base(unit) { }
protected virtual string GetLabelForOption(T option)
{
return option.ToString();
}
protected override void DefinedPort(IUnitPort port, UnitPortDescription description)
{
base.DefinedPort(port, description);
foreach (var branch in unit.branches)
{
if (branch.Value == port)
{
var option = branch.Key;
description.label = GetLabelForOption(option);
description.summary = $"The action to execute if the selector has the value {GetLabelForOption(option)}.";
}
}
}
}
}