-
Notifications
You must be signed in to change notification settings - Fork 22
InsightModule
uwee edited this page Feb 10, 2019
·
7 revisions
To add functionality to a client or server use InsightModules. First add the ModuleManager component.
Next add each InsightModule as a child gameobject and component.
The module will be initialized when Insight starts. During this time you should register handlers, populate component references, and setup dependencies. Below is an empty example module:
using Insight;
public class ExampleModule : InsightModule
{
public InsightClient client;
public ModuleManager manager;
public ExampleDependancy exampleDependancy;
public void Awake()
{
//Add references Dependancies to other modules in Start.
AddDependency<ExampleDependancy>();
}
public override void Initialize(InsightClient insight, ModuleManager manager)
{
client = insight;
this.manager = manager;
exampleDependancy = this.manager.GetModule<ExampleDependancy>();
RegisterHandlers();
}
void RegisterHandlers()
{
//Be sure to register a MsgID and MessageBase
server.RegisterHandler((short)MsgId.ExampleMsg, HandleExampleMsg);
}
#region Message Handlers
private void HandleExampleMsg(InsightNetworkMessage netMsg)
{
if (server.logNetworkMessages) { UnityEngine.Debug.Log("[ExampleModule] - Handle Example Msg."); }
//Do something with the message
//netMsg.Reply() if needed
}
#endregion
#region Message Senders
public void SendExampleMsg()
{
client.Send((short)MsgId.ExampleMsg, new HandleExampleMsg() { Values = "GoHere"});
}
#endregion
}