protected override string Label(bool human) { return(UnityAPI.Await(() => { var macro = (UnityObject)unit.nest.macro; return macro != null ? macro.name : BoltFlowNameUtility.UnitTitle(unit.GetType(), false, false); })); }
protected override string Label(bool human) { if (unit.value is UnityObject uo && !uo.IsUnityNull()) { return(UnityAPI.Await(() => uo.name)); } return(unit.type.SelectedName(human) + " Literal"); }
private static IEnumerable<IUnitOption> GetDynamicOptions() { var stateMacros = UnityAPI.Await(() => AssetUtility.GetAllAssetsOfType<StateGraphAsset>().ToArray()); foreach (var stateUnit in stateMacros.Select(statemacro => new StateUnit(statemacro))) { yield return stateUnit.Option(); } }
private IEnumerable <object> SelfChildren() { yield return(typeof(GameObject)); // Self components can be null if no script is assigned to them // https://support.ludiq.io/forums/5-bolt/topics/817-/ foreach (var selfComponentType in UnityAPI.Await(() => self.GetComponents <Component>().NotUnityNull().Select(c => c.GetType()))) { yield return(selfComponentType); } }
protected override string Label(bool human) { return(UnityAPI.Await(() => { var macro = (UnityObject)unit.nest.macro; if (macro != null) { return macro.name; } else { return unit.GetType().HumanName(); } })); }
public static IEnumerable <IUnitOption> Subset(UnitOptionFilter filter, GraphReference reference) { lock (@lock) { if (options == null) { Load(); } var dynamicOptions = UnityAPI.Await(() => GetDynamicOptions().ToHashSet()); var contextualOptions = UnityAPI.Await(() => GetContextualOptions(reference).ToHashSet()); return(LinqUtility.Concat <IUnitOption>(options, dynamicOptions, contextualOptions) .Where((filter ?? UnitOptionFilter.Any).ValidateOption) .ToArray()); } }
public override IEnumerable <object> Root() { if (rootOverride != null && rootOverride.Length > 0) { foreach (var item in rootOverride) { yield return(item); } yield break; } if (filter.CompatibleOutputType != null) { var outputType = filter.CompatibleOutputType; var outputTypeLiteral = options.FirstOrDefault(option => option is LiteralOption literalOption && literalOption.literalType == outputType); if (outputTypeLiteral != null) { yield return(outputTypeLiteral); } HashSet <Type> noSurfaceConstructors = new HashSet <Type>() { typeof(string), typeof(object) }; if (!noSurfaceConstructors.Contains(outputType)) { var outputTypeConstructors = options.Where(option => option is InvokeMemberOption invokeMemberOption && invokeMemberOption.targetType == outputType && invokeMemberOption.unit.member.isConstructor); foreach (var outputTypeConstructor in outputTypeConstructors) { yield return(outputTypeConstructor); } } if (outputType == typeof(bool)) { foreach (var logicOperation in CategoryChildren(new UnitCategory("Logic"))) { yield return(logicOperation); } } if (outputType.IsNumeric()) { foreach (var mathOperation in CategoryChildren(new UnitCategory("Math/Scalar"))) { yield return(mathOperation); } } if (outputType == typeof(Vector2)) { foreach (var mathOperation in CategoryChildren(new UnitCategory("Math/Vector 2"))) { yield return(mathOperation); } } if (outputType == typeof(Vector3)) { foreach (var mathOperation in CategoryChildren(new UnitCategory("Math/Vector 3"))) { yield return(mathOperation); } } if (outputType == typeof(Vector4)) { foreach (var mathOperation in CategoryChildren(new UnitCategory("Math/Vector 4"))) { yield return(mathOperation); } } } if (surfaceCommonTypeLiterals) { foreach (var commonType in EditorTypeUtility.commonTypes) { if (commonType == filter.CompatibleOutputType) { continue; } var commonTypeLiteral = options.FirstOrDefault(option => option is LiteralOption literalOption && literalOption.literalType == commonType); if (commonTypeLiteral != null) { yield return(commonTypeLiteral); } } } if (filter.CompatibleInputType != null) { var inputType = filter.CompatibleInputType; if (!inputType.IsPrimitive && inputType != typeof(object)) { yield return(inputType); } if (inputType == typeof(bool)) { yield return(options.Single(o => o.UnitIs <If>())); yield return(options.Single(o => o.UnitIs <SelectUnit>())); } if (inputType == typeof(bool) || inputType.IsNumeric()) { foreach (var logicOperation in CategoryChildren(new UnitCategory("Logic"))) { yield return(logicOperation); } } if (inputType.IsNumeric()) { foreach (var mathOperation in CategoryChildren(new UnitCategory("Math/Scalar"))) { yield return(mathOperation); } } if (inputType == typeof(Vector2)) { foreach (var mathOperation in CategoryChildren(new UnitCategory("Math/Vector 2"))) { yield return(mathOperation); } } if (inputType == typeof(Vector3)) { foreach (var mathOperation in CategoryChildren(new UnitCategory("Math/Vector 3"))) { yield return(mathOperation); } } if (inputType == typeof(Vector4)) { foreach (var mathOperation in CategoryChildren(new UnitCategory("Math/Vector 4"))) { yield return(mathOperation); } } if (typeof(IEnumerable).IsAssignableFrom(inputType) && (inputType != typeof(string) && inputType != typeof(Transform))) { foreach (var mathOperation in CategoryChildren(new UnitCategory("Collections"), false)) { yield return(mathOperation); } } if (typeof(IList).IsAssignableFrom(inputType)) { foreach (var listOperation in CategoryChildren(new UnitCategory("Collections/Lists"))) { yield return(listOperation); } } if (typeof(IDictionary).IsAssignableFrom(inputType)) { foreach (var dictionaryOperation in CategoryChildren(new UnitCategory("Collections/Dictionaries"))) { yield return(dictionaryOperation); } } } if (UnityAPI.Await ( () => { if (self != null) { selfGroup.label = self.name; selfGroup.icon = self.Icon(); return(true); } return(false); } ) ) { yield return(selfGroup); } foreach (var category in options.Select(option => option.category?.root) .NotNull() .Concat(SpecialCategories()) .Distinct() .OrderBy(c => c.name)) { yield return(category); } foreach (var extensionRootItem in base.Root()) { yield return(extensionRootItem); } if (filter.Self) { var self = options.FirstOrDefault(option => option.UnitIs <This>()); if (self != null) { yield return(self); } } foreach (var unit in CategoryChildren(null)) { yield return(unit); } if (includeNone) { yield return(null); } }
// Perforce and other VCS have a lock mechanism that usually // only makes the file writable once checked out. We need to // check them out before writing to them for auto-generated files. public static void Unlock(string path) { Ensure.That(nameof(path)).IsNotNull(path); UnityAPI.Await ( () => { // The API changed in 2019, adding a third optional ChangeSet parameter // which defaults to null but breaks the compiled signature below // Furthermore, we can't even so much as have the call in the body of this method, // or it will fail even if the if branch evaluates to false. So we if (File.Exists(path) && Provider.enabled && Provider.isActive && Provider.hasCheckoutSupport) { try { var provider = typeof(Provider); if (EditorApplicationUtility.unityVersion >= "2019.1.0") { var method = provider.GetMethods() .FirstOrDefault ( m => m.Name == "Checkout" && m.GetParameters().Length == 3 && m.GetParameters()[0].ParameterType == typeof(string) && m.GetParameters()[1].ParameterType == typeof(CheckoutMode) ); if (method == null) { throw new MissingMemberException(provider.FullName, "Checkout"); } method.InvokeOptimized(null, PathUtility.FromProject(path), CheckoutMode.Both, null); } else { var method = provider.GetMethods() .FirstOrDefault ( m => m.Name == "Checkout" && m.GetParameters().Length == 2 && m.GetParameters()[0].ParameterType == typeof(string) && m.GetParameters()[1].ParameterType == typeof(CheckoutMode) ); if (method == null) { throw new MissingMemberException(provider.FullName, "Checkout"); } method.InvokeOptimized(null, PathUtility.FromProject(path), CheckoutMode.Both); } } catch (Exception ex) { Debug.LogWarning($"Failed to automatically checkout file from version control:\n{path}\n{ex}"); } } if (File.Exists(path)) { var info = new FileInfo(path); if (info.IsReadOnly) { var sb = new StringBuilder(); sb.AppendLine($"File '{info.Name}' is read-only despite attempted checkout. Manually forcing to writable."); sb.AppendLine($"This may cause version control issues. Please report the following debug information:"); sb.AppendLine($"File Exists: {File.Exists(path)}"); sb.AppendLine($"Provider.enabled: {Provider.enabled}"); sb.AppendLine($"Provider.isActive: {Provider.isActive}"); sb.AppendLine($"Provider.hasCheckoutSupport: {Provider.hasCheckoutSupport}"); Debug.LogWarning(sb.ToString()); info.IsReadOnly = false; } } } ); }