Example #1
0
        public static FuncRef FuncRef(Object instance, StringName funcName)
        {
            var ret = new FuncRef();

            ret.SetInstance(instance);
            ret.SetFunction(funcName);
            return(ret);
        }
Example #2
0
 public bool Equals(StringName other)
 {
     if (other is null)
     {
         return(false);
     }
     return(NativeValue.DangerousSelfRef == other.NativeValue.DangerousSelfRef);
 }
Example #3
0
        public SignalAwaiter(Object source, StringName signal, Object target)
        {
            var awaiterGcHandle = CustomGCHandle.AllocStrong(this);

            using godot_string_name signalSrc = NativeFuncs.godotsharp_string_name_new_copy(
                      (godot_string_name)(signal?.NativeValue ?? default));
            NativeFuncs.godotsharp_internal_signal_awaiter_connect(Object.GetPtr(source), in signalSrc,
                                                                   Object.GetPtr(target), GCHandle.ToIntPtr(awaiterGcHandle));
        }
        internal static IntPtr GetPtr(StringName instance)
        {
            if (instance == null)
            {
                throw new NullReferenceException($"The instance of type {nameof(StringName)} is null.");
            }

            if (instance.ptr == IntPtr.Zero)
            {
                throw new ObjectDisposedException(instance.GetType().FullName);
            }

            return(instance.ptr);
        }
Example #5
0
 /// <summary>
 /// Returns whether the given class exists in <see cref="ClassDB"/>.
 /// </summary>
 /// <returns>If the class exists in <see cref="ClassDB"/>.</returns>
 public static bool TypeExists(StringName type)
 {
     return(godot_icall_GD_type_exists(StringName.GetPtr(type)));
 }
Example #6
0
 public SignalAwaiter(Object source, StringName signal, Object target)
 {
     godot_icall_SignalAwaiter_connect(Object.GetPtr(source), StringName.GetPtr(signal), Object.GetPtr(target), this);
 }
Example #7
0
 internal static IntPtr __ClassDB_get_method(StringName type, string method)
 {
     return(godot_icall_Object_ClassDB_get_method(StringName.GetPtr(type), method));
 }
Example #8
0
 /// <summary>
 /// Returns a new <see cref="Godot.SignalAwaiter"/> awaiter configured to complete when the instance
 /// <paramref name="source"/> emits the signal specified by the <paramref name="signal"/> parameter.
 /// </summary>
 /// <param name="source">
 /// The instance the awaiter will be listening to.
 /// </param>
 /// <param name="signal">
 /// The signal the awaiter will be waiting for.
 /// </param>
 /// <example>
 /// This sample prints a message once every frame up to 100 times.
 /// <code>
 /// public override void _Ready()
 /// {
 ///     for (int i = 0; i &lt; 100; i++)
 ///     {
 ///         await ToSignal(GetTree(), "idle_frame");
 ///         GD.Print($"Frame {i}");
 ///     }
 /// }
 /// </code>
 /// </example>
 public SignalAwaiter ToSignal(Object source, StringName signal)
 {
     return(new SignalAwaiter(source, signal, this));
 }
Example #9
0
 /// <summary>
 /// Constructs a new <see cref="Callable"/> for the given <paramref name="delegate"/>.
 /// </summary>
 /// <param name="delegate">Delegate method that will be called.</param>
 public Callable(Delegate @delegate)
 {
     _target   = null;
     _method   = null;
     _delegate = @delegate;
 }
Example #10
0
 /// <summary>
 /// Constructs a new <see cref="Callable"/> for the method called <paramref name="method"/>
 /// in the specified <paramref name="target"/>.
 /// </summary>
 /// <param name="target">Object that contains the method.</param>
 /// <param name="method">Name of the method that will be called.</param>
 public Callable(Object target, StringName method)
 {
     _target   = target;
     _method   = method;
     _delegate = null;
 }
Example #11
0
 /// <summary>
 /// Returns a list of all nodes assigned to the given <paramref name="group"/>.
 /// </summary>
 /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam>
 public Array <T> GetNodesInGroup <T>(StringName group) where T : class
 {
     return(new Array <T>(godot_icall_SceneTree_get_nodes_in_group_Generic(GetPtr(this), StringName.GetPtr(group), typeof(T))));
 }