Update some C# examples

- Rename members that have been renamed in Godot's C# API for 4.0.
- Change `delta` parameter type to `double`.
- Ensure parameters match base declaration.
- Follow our code style more closely.
- Other minor code fixes.
This commit is contained in:
Raul Santos
2023-05-18 12:27:34 +02:00
parent 97b6f53622
commit c457ab79ec
16 changed files with 106 additions and 96 deletions

View File

@@ -499,12 +499,11 @@ accesses:
public partial class Child : Node
{
public FuncRef FN = null;
public Callable? Callable { get; set; }
public void MyMethod()
{
Debug.Assert(FN != null);
FN.CallFunc();
Callable?.Call();
}
}
@@ -513,18 +512,18 @@ accesses:
public partial class Parent : Node
{
public Node Child;
private Child _child;
public void _Ready()
{
Child = GetNode("Child");
Child.Set("FN", GD.FuncRef(this, "PrintMe"));
Child.MyMethod();
_child = GetNode<Child>("Child");
_child.Callable = Callable.From(PrintMe);
_child.MyMethod();
}
public void PrintMe() {
{
GD.Print(GetClass());
GD.Print(Name);
}
}

View File

@@ -128,9 +128,9 @@ deltatime methods as needed.
}
// Called during every input event. Equally true for _input().
public void _UnhandledInput(InputEvent event)
public void _UnhandledInput(InputEvent @event)
{
switch (event)
switch (@event)
{
case InputEventKey:
if (Input.IsActionJustPressed("ui_accept"))
@@ -242,7 +242,7 @@ nodes that one might create at runtime.
var parent_cache
func connection_check():
return parent.has_user_signal("interacted_with")
return parent_cache.has_user_signal("interacted_with")
func _notification(what):
match what:
@@ -263,34 +263,34 @@ nodes that one might create at runtime.
public partial class MyNode : Node
{
public Node ParentCache = null;
private Node _parentCache;
public void ConnectionCheck()
{
return ParentCache.HasUserSignal("InteractedWith");
return _parentCache.HasUserSignal("InteractedWith");
}
public void _Notification(int what)
{
switch (what)
{
case NOTIFICATION_PARENTED:
ParentCache = GetParent();
case NotificationParented:
_parentCache = GetParent();
if (ConnectionCheck())
{
ParentCache.Connect("InteractedWith", OnParentInteractedWith);
_parentCache.Connect("InteractedWith", Callable.From(OnParentInteractedWith));
}
break;
case NOTIFICATION_UNPARENTED:
case NotificationUnparented:
if (ConnectionCheck())
{
ParentCache.Disconnect("InteractedWith", OnParentInteractedWith);
_parentCache.Disconnect("InteractedWith", Callable.From(OnParentInteractedWith));
}
break;
}
}
public void OnParentInteractedWith()
private void OnParentInteractedWith()
{
GD.Print("I'm reacting to my parent's interaction!");
}