test
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
public interface IUnitOption : IFuzzyOption
|
||||
{
|
||||
IUnit unit { get; }
|
||||
|
||||
IUnit InstantiateUnit();
|
||||
void PreconfigureUnit(IUnit unit);
|
||||
|
||||
HashSet<string> sourceScriptGuids { get; }
|
||||
int order { get; }
|
||||
UnitCategory category { get; }
|
||||
string favoriteKey { get; }
|
||||
bool favoritable { get; }
|
||||
Type unitType { get; }
|
||||
|
||||
#region Serialization
|
||||
|
||||
void Deserialize(UnitOptionRow row);
|
||||
UnitOptionRow Serialize();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Filtering
|
||||
|
||||
int controlInputCount { get; }
|
||||
int controlOutputCount { get; }
|
||||
HashSet<Type> valueInputTypes { get; }
|
||||
HashSet<Type> valueOutputTypes { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Search
|
||||
|
||||
string haystack { get; }
|
||||
string formerHaystack { get; }
|
||||
string SearchResultLabel(string query);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static class XUnitOption
|
||||
{
|
||||
public static bool UnitIs(this IUnitOption option, Type type)
|
||||
{
|
||||
return type.IsAssignableFrom(option.unitType);
|
||||
}
|
||||
|
||||
public static bool UnitIs<T>(this IUnitOption option)
|
||||
{
|
||||
return option.UnitIs(typeof(T));
|
||||
}
|
||||
|
||||
public static bool HasCompatibleValueInput(this IUnitOption option, Type outputType)
|
||||
{
|
||||
Ensure.That(nameof(outputType)).IsNotNull(outputType);
|
||||
|
||||
foreach (var valueInputType in option.valueInputTypes)
|
||||
{
|
||||
if (ConversionUtility.CanConvert(outputType, valueInputType, false))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool HasCompatibleValueOutput(this IUnitOption option, Type inputType)
|
||||
{
|
||||
Ensure.That(nameof(inputType)).IsNotNull(inputType);
|
||||
|
||||
foreach (var valueOutputType in option.valueOutputTypes)
|
||||
{
|
||||
if (ConversionUtility.CanConvert(valueOutputType, inputType, false))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd6fd6310ecb2405fae7d988941661de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a03c32ec404b64125b88769f42e5b8a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,16 @@
|
||||
using System.Linq;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
[FuzzyOption(typeof(UnitCategory))]
|
||||
public class UnitCategoryOption : FuzzyOption<UnitCategory>
|
||||
{
|
||||
public UnitCategoryOption(UnitCategory category)
|
||||
{
|
||||
value = category;
|
||||
label = category.name.Split('/').Last().Prettify();
|
||||
UnityAPI.Async(() => icon = BoltFlow.Icons.UnitCategory(category));
|
||||
parentOnly = true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1bc17db44a4104432a5abc99035fe920
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37d8f9a231f5545c8aa227756649439d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,351 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
public sealed class UnitOptionFilter : ICloneable
|
||||
{
|
||||
public UnitOptionFilter(bool @default)
|
||||
{
|
||||
NoControlInput = @default;
|
||||
SingleControlInput = @default;
|
||||
MultipleControlInputs = @default;
|
||||
|
||||
NoValueInput = @default;
|
||||
SingleValueInput = @default;
|
||||
MultipleValueInputs = @default;
|
||||
|
||||
NoControlOutput = @default;
|
||||
SingleControlOutput = @default;
|
||||
MultipleControlOutputs = @default;
|
||||
|
||||
NoValueOutput = @default;
|
||||
SingleValueOutput = @default;
|
||||
MultipleValueOutputs = @default;
|
||||
|
||||
Normals = @default;
|
||||
Self = @default;
|
||||
Events = @default;
|
||||
Literals = @default;
|
||||
Variables = @default;
|
||||
Members = @default;
|
||||
Nesters = @default;
|
||||
Expose = @default;
|
||||
NoConnection = @default;
|
||||
Obsolete = false;
|
||||
AllowSelfNestedGraph = false;
|
||||
}
|
||||
|
||||
public bool NoControlInput { get; set; }
|
||||
public bool SingleControlInput { get; set; }
|
||||
public bool MultipleControlInputs { get; set; }
|
||||
|
||||
public bool NoValueInput { get; set; }
|
||||
public bool SingleValueInput { get; set; }
|
||||
public bool MultipleValueInputs { get; set; }
|
||||
|
||||
public bool NoControlOutput { get; set; }
|
||||
public bool SingleControlOutput { get; set; }
|
||||
public bool MultipleControlOutputs { get; set; }
|
||||
|
||||
public bool NoValueOutput { get; set; }
|
||||
public bool SingleValueOutput { get; set; }
|
||||
public bool MultipleValueOutputs { get; set; }
|
||||
|
||||
public bool Normals { get; set; }
|
||||
public bool NoConnection { get; set; }
|
||||
public bool Self { get; set; }
|
||||
public bool Events { get; set; }
|
||||
public bool Literals { get; set; }
|
||||
public bool Variables { get; set; }
|
||||
public bool Members { get; set; }
|
||||
public bool Nesters { get; set; }
|
||||
public bool Expose { get; set; }
|
||||
public bool Obsolete { get; set; }
|
||||
public bool AllowSelfNestedGraph { get; set; }
|
||||
|
||||
public Type CompatibleInputType { get; set; }
|
||||
public Type CompatibleOutputType { get; set; }
|
||||
|
||||
public int GraphHashCode { get; set; }
|
||||
|
||||
object ICloneable.Clone()
|
||||
{
|
||||
return Clone();
|
||||
}
|
||||
|
||||
public UnitOptionFilter Clone()
|
||||
{
|
||||
return new UnitOptionFilter(true)
|
||||
{
|
||||
NoControlInput = NoControlInput,
|
||||
SingleControlInput = SingleControlInput,
|
||||
MultipleControlInputs = MultipleControlInputs,
|
||||
NoValueInput = NoValueInput,
|
||||
SingleValueInput = SingleValueInput,
|
||||
MultipleValueInputs = MultipleValueInputs,
|
||||
NoControlOutput = NoControlOutput,
|
||||
SingleControlOutput = SingleControlOutput,
|
||||
MultipleControlOutputs = MultipleControlOutputs,
|
||||
NoValueOutput = NoValueOutput,
|
||||
SingleValueOutput = SingleValueOutput,
|
||||
MultipleValueOutputs = MultipleValueOutputs,
|
||||
Normals = Normals,
|
||||
Self = Self,
|
||||
Events = Events,
|
||||
Literals = Literals,
|
||||
Variables = Variables,
|
||||
Members = Members,
|
||||
Nesters = Nesters,
|
||||
Expose = Expose,
|
||||
Obsolete = Obsolete,
|
||||
NoConnection = NoConnection,
|
||||
CompatibleInputType = CompatibleInputType,
|
||||
CompatibleOutputType = CompatibleOutputType,
|
||||
AllowSelfNestedGraph = AllowSelfNestedGraph,
|
||||
GraphHashCode = GraphHashCode
|
||||
};
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var other = obj as UnitOptionFilter;
|
||||
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return NoControlInput == other.NoControlInput &&
|
||||
SingleControlInput == other.SingleControlInput &&
|
||||
MultipleControlInputs == other.MultipleControlInputs &&
|
||||
NoValueInput == other.NoValueInput &&
|
||||
SingleValueInput == other.SingleValueInput &&
|
||||
MultipleValueInputs == other.MultipleValueInputs &&
|
||||
NoControlOutput == other.NoControlOutput &&
|
||||
SingleControlOutput == other.SingleControlOutput &&
|
||||
MultipleControlOutputs == other.MultipleControlOutputs &&
|
||||
NoValueOutput == other.NoValueOutput &&
|
||||
SingleValueOutput == other.SingleValueOutput &&
|
||||
MultipleValueOutputs == other.MultipleValueOutputs &&
|
||||
Normals == other.Normals &&
|
||||
Self == other.Self &&
|
||||
Events == other.Events &&
|
||||
Literals == other.Literals &&
|
||||
Variables == other.Variables &&
|
||||
Members == other.Members &&
|
||||
Nesters == other.Nesters &&
|
||||
Expose == other.Expose &&
|
||||
Obsolete == other.Obsolete &&
|
||||
NoConnection == other.NoConnection &&
|
||||
CompatibleInputType == other.CompatibleInputType &&
|
||||
CompatibleOutputType == other.CompatibleOutputType &&
|
||||
AllowSelfNestedGraph == other.AllowSelfNestedGraph &&
|
||||
GraphHashCode == other.GraphHashCode;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hash = 17;
|
||||
|
||||
hash = hash * 23 + NoControlInput.GetHashCode();
|
||||
hash = hash * 23 + SingleControlInput.GetHashCode();
|
||||
hash = hash * 23 + MultipleControlInputs.GetHashCode();
|
||||
|
||||
hash = hash * 23 + NoValueInput.GetHashCode();
|
||||
hash = hash * 23 + SingleValueInput.GetHashCode();
|
||||
hash = hash * 23 + MultipleValueInputs.GetHashCode();
|
||||
|
||||
hash = hash * 23 + NoControlOutput.GetHashCode();
|
||||
hash = hash * 23 + SingleControlOutput.GetHashCode();
|
||||
hash = hash * 23 + MultipleControlOutputs.GetHashCode();
|
||||
|
||||
hash = hash * 23 + NoValueOutput.GetHashCode();
|
||||
hash = hash * 23 + SingleValueOutput.GetHashCode();
|
||||
hash = hash * 23 + MultipleValueOutputs.GetHashCode();
|
||||
|
||||
hash = hash * 23 + Self.GetHashCode();
|
||||
hash = hash * 23 + Events.GetHashCode();
|
||||
hash = hash * 23 + Literals.GetHashCode();
|
||||
hash = hash * 23 + Variables.GetHashCode();
|
||||
hash = hash * 23 + Members.GetHashCode();
|
||||
hash = hash * 23 + Nesters.GetHashCode();
|
||||
hash = hash * 23 + Expose.GetHashCode();
|
||||
hash = hash * 23 + NoConnection.GetHashCode();
|
||||
hash = hash * 23 + Obsolete.GetHashCode();
|
||||
hash = hash * 23 + AllowSelfNestedGraph.GetHashCode();
|
||||
|
||||
hash = hash * 23 + (CompatibleInputType?.GetHashCode() ?? 0);
|
||||
hash = hash * 23 + (CompatibleOutputType?.GetHashCode() ?? 0);
|
||||
|
||||
hash = hash * 23 + GraphHashCode;
|
||||
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ValidateOption(IUnitOption option)
|
||||
{
|
||||
Ensure.That(nameof(option)).IsNotNull(option);
|
||||
|
||||
if (!NoControlInput && option.controlInputCount == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!SingleControlInput && option.controlInputCount == 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!MultipleControlInputs && option.controlInputCount > 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NoValueInput && option.valueInputTypes.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!SingleValueInput && option.valueInputTypes.Count == 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!MultipleValueInputs && option.valueInputTypes.Count > 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NoControlOutput && option.controlOutputCount == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!SingleControlOutput && option.controlOutputCount == 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!MultipleControlOutputs && option.controlOutputCount > 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NoValueOutput && option.valueOutputTypes.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!SingleValueOutput && option.valueOutputTypes.Count == 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!MultipleValueOutputs && option.valueOutputTypes.Count > 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var unitType = option.unitType;
|
||||
|
||||
if (!Normals && !unitType.HasAttribute<SpecialUnitAttribute>())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Self && option.UnitIs<This>())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Events && option.UnitIs<IEventUnit>())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Literals && option.UnitIs<Literal>())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Variables && option.UnitIs<IUnifiedVariableUnit>())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Members && option.UnitIs<MemberUnit>())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Nesters && option.UnitIs<INesterUnit>())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Expose && option.UnitIs<Expose>())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Obsolete && unitType.HasAttribute<ObsoleteAttribute>())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CompatibleInputType != null && !option.HasCompatibleValueInput(CompatibleInputType))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CompatibleOutputType != null && !option.HasCompatibleValueOutput(CompatibleOutputType))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!AllowSelfNestedGraph && option.UnitIs<SubgraphUnit>())
|
||||
{
|
||||
if (((SubgraphUnit)option.unit).nest.graph.GetHashCode() == GraphHashCode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine($"NoControlInput: {NoControlInput}");
|
||||
sb.AppendLine($"SingleControlInput: {SingleControlInput}");
|
||||
sb.AppendLine($"MultipleControlInputs: {MultipleControlInputs}");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"NoValueInput: {NoValueInput}");
|
||||
sb.AppendLine($"SingleValueInput: {SingleValueInput}");
|
||||
sb.AppendLine($"MultipleValueInputs: {MultipleValueInputs}");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"NoControlOutput: {NoControlOutput}");
|
||||
sb.AppendLine($"SingleControlOutput: {SingleControlOutput}");
|
||||
sb.AppendLine($"MultipleControlOutputs: {MultipleControlOutputs}");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"NoValueOutput: {NoValueOutput}");
|
||||
sb.AppendLine($"SingleValueOutput: {SingleValueOutput}");
|
||||
sb.AppendLine($"MultipleValueOutputs: {MultipleValueOutputs}");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"Self: {Self}");
|
||||
sb.AppendLine($"Events: {Events}");
|
||||
sb.AppendLine($"Literals: {Literals}");
|
||||
sb.AppendLine($"Variables: {Variables}");
|
||||
sb.AppendLine($"Members: {Members}");
|
||||
sb.AppendLine($"Nesters: {Nesters}");
|
||||
sb.AppendLine($"Expose: {Expose}");
|
||||
sb.AppendLine($"Obsolete: {Obsolete}");
|
||||
sb.AppendLine($"NoConnection: {NoConnection}");
|
||||
sb.AppendLine($"AllowSelfNestedGraph: {AllowSelfNestedGraph}");
|
||||
sb.AppendLine($"GraphHashCode: {GraphHashCode}");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static UnitOptionFilter Any => new UnitOptionFilter(true);
|
||||
public static UnitOptionFilter None => new UnitOptionFilter(false);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f22a86a3605947029c82ebdf322c9f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,15 @@
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
public static class XUnitOptionProvider
|
||||
{
|
||||
public static IUnitOption Option(this IUnit unit)
|
||||
{
|
||||
return FuzzyOptionProvider.instance.GetDecorator<IUnitOption>(unit);
|
||||
}
|
||||
|
||||
public static IUnitOption Option<TOption>(this IUnit unit) where TOption : IUnitOption
|
||||
{
|
||||
return FuzzyOptionProvider.instance.GetDecorator<TOption>(unit);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2b9227c78ca546fcb92bb352fcab92d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using Unity.VisualScripting.Dependencies.Sqlite;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
public sealed class UnitOptionRow
|
||||
{
|
||||
[AutoIncrement, PrimaryKey]
|
||||
public int id { get; set; }
|
||||
|
||||
public string sourceScriptGuids { get; set; }
|
||||
|
||||
public string optionType { get; set; }
|
||||
public string unitType { get; set; }
|
||||
public string labelHuman { get; set; }
|
||||
public string labelProgrammer { get; set; }
|
||||
public string category { get; set; }
|
||||
public int order { get; set; }
|
||||
public string haystackHuman { get; set; }
|
||||
public string haystackProgrammer { get; set; }
|
||||
public string favoriteKey { get; set; }
|
||||
public string tag1 { get; set; }
|
||||
public string tag2 { get; set; }
|
||||
public string tag3 { get; set; }
|
||||
public string unit { get; set; }
|
||||
|
||||
public int controlInputCount { get; set; }
|
||||
public int controlOutputCount { get; set; }
|
||||
public string valueInputTypes { get; set; }
|
||||
public string valueOutputTypes { get; set; }
|
||||
|
||||
public IUnitOption ToOption()
|
||||
{
|
||||
using (ProfilingUtility.SampleBlock("Row to option"))
|
||||
{
|
||||
var optionType = Codebase.DeserializeType(this.optionType);
|
||||
|
||||
IUnitOption option;
|
||||
|
||||
option = (IUnitOption)Activator.CreateInstance(optionType);
|
||||
|
||||
option.Deserialize(this);
|
||||
|
||||
return option;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65a6a75d9580f437b84420c6b5e36cbd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0aff9d906147244d6b9be227b986021a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,7 @@
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
public static class UnitOptionUtility
|
||||
{
|
||||
public const string GenerateUnitDatabasePath = "Edit > Project Settings > Visual Scripting > Node Library > Regenerate Nodes";
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e22fa013a1894b7f94abb820d303fb35
|
||||
timeCreated: 1605214947
|
Reference in New Issue
Block a user