This repository was archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Game Instance
Dylan Dumesnil edited this page Jun 30, 2020
·
1 revision
The Game Instance is the heart of the framework. It's where the framework registers callbacks to register your nodes with the framework features, such as Replication or Node Binding.
Most of the framework's customization can be done by extending MDGameInstance. To do this, create a new file and name it (eg. CustomGameInstance.cs) and add this code:
using Godot;
using System;
public class CustomGameInstance : MDGameInstance
{
private const string LOG_CAT = "LogCustomGameInstance";
public override void _Ready()
{
base._Ready();
MDLog.Info(LOG_CAT, "Custom Game Instance Initialized");
}
}
Next, you'll need to change your autoload to use your new custom game instance class, so open project.godot
and change the autoload path to your new file:
[autoload]
GameInstance="*res://Script/CustomGameInstance.cs"
Now you can override methods to customize the framework's features. Each feature's wiki page will call out the methods you can override but the full list is here with the default values:
// Override to change when the console is available
public virtual bool IsConsoleAvailable()
{
#if DEBUG
return true;
#else
return false;
#endif
}
// Override to change when UPNP is used for the server
public virtual bool UseUPNP()
{
return true;
}
// Override to change is MDAutoRegister is required
public virtual bool RequireAutoRegister()
{
return false;
}
// Override this to provide the your GameSession subclass type
protected virtual Type GetGameSessionType()
{
return typeof(MDGameSession);
}
// Override this to provide your own Player class type
public virtual Type GetPlayerInfoType()
{
return typeof(MDPlayerInfo);
}
// Called whenever a node is added to the scene
protected virtual void OnNodeAdded(Node AddedNode)
{
}
// Called whenever a node is removed to the scene
protected virtual void OnNodeRemoved(Node RemovedNode)
{
}