A game about forced loneliness, made by TACStudios
1using System;
2using System.Collections.Generic;
3
4namespace Unity.VisualScripting
5{
6 public interface IUnitOption : IFuzzyOption
7 {
8 IUnit unit { get; }
9
10 IUnit InstantiateUnit();
11 void PreconfigureUnit(IUnit unit);
12
13 HashSet<string> sourceScriptGuids { get; }
14 int order { get; }
15 UnitCategory category { get; }
16 string favoriteKey { get; }
17 bool favoritable { get; }
18 Type unitType { get; }
19
20 #region Serialization
21
22 void Deserialize(UnitOptionRow row);
23 UnitOptionRow Serialize();
24
25 #endregion
26
27 #region Filtering
28
29 int controlInputCount { get; }
30 int controlOutputCount { get; }
31 HashSet<Type> valueInputTypes { get; }
32 HashSet<Type> valueOutputTypes { get; }
33
34 #endregion
35
36 #region Search
37
38 string haystack { get; }
39 string formerHaystack { get; }
40 string SearchResultLabel(string query);
41
42 #endregion
43 }
44
45 public static class XUnitOption
46 {
47 public static bool UnitIs(this IUnitOption option, Type type)
48 {
49 return type.IsAssignableFrom(option.unitType);
50 }
51
52 public static bool UnitIs<T>(this IUnitOption option)
53 {
54 return option.UnitIs(typeof(T));
55 }
56
57 public static bool HasCompatibleValueInput(this IUnitOption option, Type outputType)
58 {
59 Ensure.That(nameof(outputType)).IsNotNull(outputType);
60
61 foreach (var valueInputType in option.valueInputTypes)
62 {
63 if (ConversionUtility.CanConvert(outputType, valueInputType, false))
64 {
65 return true;
66 }
67 }
68
69 return false;
70 }
71
72 public static bool HasCompatibleValueOutput(this IUnitOption option, Type inputType)
73 {
74 Ensure.That(nameof(inputType)).IsNotNull(inputType);
75
76 foreach (var valueOutputType in option.valueOutputTypes)
77 {
78 if (ConversionUtility.CanConvert(valueOutputType, inputType, false))
79 {
80 return true;
81 }
82 }
83
84 return false;
85 }
86 }
87}