| − | All modbehaviours have access to their '''ParentMod''', this is the class that manages your mod, and through this you can load files using the methods '''LoadTexture'''(png, jpg, jpeg), '''LoadTydFile'''(tyd), '''LoadAudio'''(mp3, wav, ogg), '''LoadGLTF'''(gltf, glb, only loads the first mesh and its morph targets) and '''LoadOBJ'''(obj). Note that these methods all use relative paths from where your mod is installed and using '''../''' won't work. | + | All modbehaviours have access to their '''ParentMod''', this is the class that manages your mod, and through this you can load files using the methods '''LoadTexture'''(png, jpg, jpeg), '''LoadXMLFile'''(xml, only first tag), '''LoadFullXMLFile'''(xml, all tags in a list), '''LoadTydFile'''(tyd), '''LoadAudio'''(mp3, wav, ogg), '''LoadGLTF'''(gltf, glb, only loads the first mesh and its morph targets) and '''LoadOBJ'''(obj). Note that these methods all use relative paths from where your mod is installed and using '''../''' won't work. |
| | + | To send messages you have to call '''ParentMod.SendNetworkMessage'''(byte[] data, ModBehaviour.MessageTarget target, byte targetID) in your ModBehaviour, where target can be everyone(default), everyone but me(so avoid sending message to self), everyone except(everyone player with targetID), specifically (only player with targetID) and host. For performance reasons, I recommend instantiating a MemoryStream when your mod loads and when you want to send data, call MemoryStream.SetLength(0) to reset its data and then use the extension methods that Software Inc. comes with to write arbitrary data to the stream, finally call MemoryStream.ToArray() to send the data. Please be careful about how much data you send, you should keep the packages as small as possible. |
| | + | When you want to receive data, override '''ModMeta.ReceiveNetworkMessage'''(SINetworking.NetworkPlayer player, MemoryStream stream), and just use the Stream extension methods to turn the bytes in the MemoryStream back into data you use, in the same order you sent it. |
| | + | The extension methods Software Inc. has for Stream objects include the ability to write strings, most simple types, like integers. They will be called ReadX or WriteX. It also has generic methods to write lists and dictionaries. If you implement the interface IByteData and add a static '''Type ReadData(Stream st)''' method, you can also quickly write that object using the Stream.Read/WriteByteObject extension methods. You can also use Stream.WriteObject to write arbitrary data, however this will quickly balloon in size and is very slow, so use it carefully, |