Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Serializable] // MUST have this attribute.
- public class ExampleModule : Module
- {
- #region MEMBERS
- // Add all your serializable fields.
- public string Text;
- /* public string Text { get; set; }
- * This auto-property would work too. Auto-properties are just wrappers for fields.
- */
- // This field will not be sent across the network because it has the [NonSerialized] attribute.
- // This is useful for fields that define local behavior and should not be sent as data.
- [field: NonSerialized]
- public int NotSentAcrossNet;
- /* public readonly int ReadOnlyField;
- * public int ReadOnlyAutoProperty { get; }
- *
- * These readonly members would be ignored, because NetEasy can't set them.
- */
- /* [field: NonSerialized]
- * public Player CannotSendAcrossNet;
- *
- * This field MUST not be sent across the network because the Player type does not have the SerializableAttribute.
- * Visual Studio will even warn you if it's not marked as NonSerialized.
- * As such, you must mark it with the NonSerialized attribute.
- */
- #endregion
- #region MODULE METHODS
- // (Required)
- // Handle the behavior for this module.
- // This code is run for everyone who receives the net message (and, optionally, the person who sent the message).
- protected override void Receive()
- {
- // This will only print nonzero if received locally from the person who sent it.
- // That's because it has the NonSerialized attribute.
- Main.NewText(NotSentAcrossNet);
- //
- Main.NewText(Text);
- }
- // (Optional)
- // Lets you foolproof the module and do stuff before it's sent.
- protected override bool PreSend(Node? ignoreClient, Node? toClient)
- {
- return base.PreSend(ignoreClient, toClient);
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement