No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IUnitOption.cs 2.2KB

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