Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[Released] Easy Unet Packets

Discussion in 'Assets and Asset Store' started by spaceapple, Jan 27, 2018.

  1. spaceapple

    spaceapple

    Joined:
    Jan 15, 2018
    Posts:
    2


    Status: Published [2018 03 09] [Link]
    GitHub (documentation): [Link] Read it to get a glimpse of what this asset is all about
    Price: 8 USD

    What is this?

    Easy Packets (EP) is an Unity asset which makes it more convenient to send and handle messages in your Unet HLAPI applications. Unet RPC's make everything ugly and complex, and standard messages lack a lot of convenient functionality, which is why I made this asset. I've been using it for quite a while, and I can't imagine working with Unet HLAPI without it.

    This packet is not something BIG that you add to your games - it's something extremelly small, simple, and makes it a lot more enjoying to write networking code.

    Why would you use it?

    • Can be used as framework/base for building your networked applications
    • Allows replying to messages directly (main reason why I wrote this)
    • Messages can be created on the fly (written directly to writers)
    • On the server, it is easy to see who sent a message (which peer) and modify it's state
    • Uses same transportation method as Unet HLAPI messages
    • It makes your code beautiful (check out the examples)
    • It's small, robust and performant

    Introduction/history (not necessary to read, but in case you're interested ;))


    For the past year, I have been working on a few multiplayer games with UNet. What I found was that it was a very common use-case to reply to messages, sent by users - for example, when a client sends a request to buy something, server needs to respond about the status of purchase.

    As projects grew bigger, it became a huge hassle to use standard Unet messaging API (inheriting MessageBase) or RPC's (creates bunch of spaghetti code). To remedy that, I wrote a few small wrapper scripts and other convenient methods, which became a base for any Unet app that I write.

    As time went by, I found myself copying these wrappers to use from one project to another, as work without them became very tedious. I shared it with some of my collegues, and they kept insisting - "why don't you make it into an asset? I'm sure there are more people who could use this".

    So here I am, sharing this as my first asset, hoping to make a few extra bucks on the way, haha
     
    Last edited: Mar 12, 2018
    Flurgle likes this.
  2. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,218
    Hey there, just picked this up and am excited to try it out.
     
  3. spaceapple

    spaceapple

    Joined:
    Jan 15, 2018
    Posts:
    2
    Hey!

    Thanks! Let me know how it goes or if you have any problems or suggestions ;)
     
  4. artbotva

    artbotva

    Joined:
    Nov 8, 2014
    Posts:
    23
    Hey! I can’t understand why you are ignoring the email, it’s quite possible that the question is too dumb, but this is just one question. I can’t continue to work on the project because of this problem for 2 weeks.

    And I can not ask this question to anyone else, because for this I will have to somehow show the rest of the bunch of Multiroon-expample-Epackets code. It is unlikely anyone will want to figure this out.

    Therefore, I ask this question here hoping for luck.

    My project works well until I made the implementation of the "character selection" before the game.

    I did it like that:


    Code (CSharp):
    1.  
    2. /////////////[server side]////////////////////////////////////////////////////////////////
    3. protected virtual IEnumerator GameLoop()
    4.         {
    5. //...........Other_Code.................//
    6. StartCoroutine(PickedPresident(user_array));
    7.             //just need wait all pick, then continue game loop
    8.  
    9.             while (!_allpick) yield return null;
    10.             StopCoroutine(PickedPresident(user_array));
    11. //............Other_Code................//
    12.         }
    13.  
    14.  
    15. private protected virtual IEnumerator PickedPresident(User []user_array)
    16.         {
    17.             int checker = 0;
    18.             Ep.Server.SetHandler(1, message =>
    19.             {
    20.                 var peer = message.Peer;
    21.                 string president = message.Reader.ReadString();
    22.                 message.Respond(ResponseStatus.Success, "Picked");
    23.                 for (int i = 0; i < _roomSize; i++)
    24.                 {
    25.                     if (peer == user_array[i].id_in_room)
    26.                     {
    27.                         if (user_array[i].president == null)
    28.                         {
    29.                             user_array[i].president = president;
    30.                             checker++;
    31.                             if (checker == _roomSize)
    32.                             {
    33.                                 _allpick = true;
    34.                             }
    35.                         }
    36.                     }
    37.  
    38.                 }
    39.  
    40.             });
    41.             yield return new WaitForSeconds(1f);
    42.  
    43.         }
    44. /////////////////////////////////////[client side]/////////////////////////////////////////////////////////////////////////
    45. public void ClickedToPick()
    46.         {
    47.            //.....Other_Code....//
    48.             Ep.Client.Send(1, writer => writer.Write(president), response => { Debug.Log("Response received: " + response.Status + " " + response.ToString());});
    49.         }
    50.  
    And everything works as it should, as long as there is only one room on the server. But when you want to create another room, it is not created and the following error is displayed.

    Screenshot_132.png
     
  5. AngleYF

    AngleYF

    Joined:
    Oct 31, 2018
    Posts:
    2
    I use mirror version 30.5.3,and then this package log err,plz help to fix it. Assets\SpaceApple\EasyPackets\Scripts\ByteMessage.cs(9,32): error CS0619: 'MessageBase' is obsolete: 'Implement NetworkMessage instead. Use extension methods instead of Serialize/Deserialize, see https://github.com/vis2k/Mirror/pull/2317'
     
  6. nick_dv

    nick_dv

    Joined:
    Mar 26, 2016
    Posts:
    14
    Why do I get this error? Assets\SpaceApple\Networking.Core\NetWriter.cs(385,21): error CS0103: The name 'LogFilter' does not exist in the current context

    Now do I fix that?
     
    Last edited: May 14, 2021
  7. nick_dv

    nick_dv

    Joined:
    Mar 26, 2016
    Posts:
    14
    I get an error. Assets\SpaceApple\Multiroom.PvP\Editor\Scripts\QuickBuild.cs(5,32): error CS0234: The type or namespace name 'UIElements' does not exist in the namespace 'UnityEngine.Experimental' (are you missing an assembly reference?)

    I change using UnityEngine.Experimental.UIElements;
    to using UnityEngine.UIElements;

    seen to work
     
  8. trw009

    trw009

    Joined:
    Jan 8, 2015
    Posts:
    2
    Did you end up finding the fix for this?
     
  9. gamer2300

    gamer2300

    Joined:
    Jan 16, 2013
    Posts:
    30
    from a clean install with unity 2019 and last mirror version
     

    Attached Files: