/// <summary> /// Searches this <see cref="Array"/> for an item /// and returns its index or -1 if not found. /// </summary> /// <param name="item">The <see cref="Variant"/> item to search for.</param> /// <returns>The index of the item, or -1 if not found.</returns> public int IndexOf(Variant item) { godot_variant variantValue = (godot_variant)item.NativeVar; var self = (godot_array)NativeValue; return(NativeFuncs.godotsharp_array_index_of(ref self, variantValue)); }
/// <summary> /// Adds an item to the end of this <see cref="Array"/>. /// This is the same as <c>append</c> or <c>push_back</c> in GDScript. /// </summary> /// <param name="item">The <see cref="Variant"/> item to add.</param> public void Add(Variant item) { godot_variant variantValue = (godot_variant)item.NativeVar; var self = (godot_array)NativeValue; _ = NativeFuncs.godotsharp_array_add(ref self, variantValue); }
/// <summary> /// Calls the method represented by this <see cref="Callable"/>. /// Arguments can be passed and should match the method's signature. /// </summary> /// <param name="args">Arguments that will be passed to the method call.</param> /// <returns>The value returned by the method.</returns> public unsafe Variant Call(params Variant[] args) { using godot_callable callable = Marshaling.ConvertCallableToNative(this); int argc = args.Length; Span <godot_variant.movable> argsStoreSpan = argc <= VarArgsSpanThreshold ? stackalloc godot_variant.movable[VarArgsSpanThreshold].Cleared() : new godot_variant.movable[argc]; Span <IntPtr> argsSpan = argc <= 10 ? stackalloc IntPtr[argc] : new IntPtr[argc]; using var variantSpanDisposer = new VariantSpanDisposer(argsStoreSpan); fixed(godot_variant *varargs = &MemoryMarshal.GetReference(argsStoreSpan).DangerousSelfRef) fixed(IntPtr * argsPtr = &MemoryMarshal.GetReference(argsSpan)) { for (int i = 0; i < argc; i++) { varargs[i] = (godot_variant)args[i].NativeVar; argsPtr[i] = new IntPtr(&varargs[i]); } godot_variant ret = NativeFuncs.godotsharp_callable_call(callable, (godot_variant **)argsPtr, argc, out _); return(Variant.CreateTakingOwnershipOfDisposableValue(ret)); } }
/// <summary> /// The variant returned via the <paramref name="elem"/> parameter is owned by the Array and must not be disposed. /// </summary> internal void GetVariantBorrowElementAt(int index, out godot_variant elem) { if (index < 0 || index >= Count) { throw new ArgumentOutOfRangeException(nameof(index)); } GetVariantBorrowElementAtUnchecked(index, out elem); }
public static unsafe object EditorDef(string setting, object defaultValue, bool restartIfChanged = false) { using godot_string settingIn = Marshaling.ConvertStringToNative(setting); using godot_variant defaultValueIn = Marshaling.ConvertManagedObjectToVariant(defaultValue); Internal.godot_icall_Globals_EditorDef(settingIn, defaultValueIn, restartIfChanged, out godot_variant result); using (result) return(Marshaling.ConvertVariantToManagedObject(result)); }
/// <summary> /// Inserts a new item at a given position in the array. /// The position must be a valid position of an existing item, /// or the position at the end of the array. /// Existing items will be moved to the right. /// </summary> /// <param name="index">The index to insert at.</param> /// <param name="item">The <see cref="Variant"/> item to insert.</param> public void Insert(int index, Variant item) { if (index < 0 || index > Count) { throw new ArgumentOutOfRangeException(nameof(index)); } godot_variant variantValue = (godot_variant)item.NativeVar; var self = (godot_array)NativeValue; NativeFuncs.godotsharp_array_insert(ref self, index, variantValue); }
/// <summary> /// The variant returned via the <paramref name="elem"/> parameter is owned by the Array and must not be disposed. /// </summary> internal unsafe void GetVariantBorrowElementAtUnchecked(int index, out godot_variant elem) { elem = NativeValue.DangerousSelfRef.Elements[index]; }