Search Unity

Unet HLAPI Ext

Discussion in 'UNet' started by Driiades, Dec 12, 2017.

  1. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    Hello here,

    I share here my bit of code for the rewritting of a really good HLAPI partially based on what UNET HLAPI provide.

    For the moment I worked on Movement synchronization but I want to provide others improvements on UNET HLAPI.

    I don't want to be compatible with current HLAPI. It's totally the opposite : provide a new HLAPI.

    There is the link : https://github.com/Driiade/Unet_HLAPI_Ext .

    What you have for the moment :

    -Movement synchronization working on current UNET HLAPI.
    -NetworkingSystem for replacement of NetworkManager.
    -MatchmakingSystem for finding match on Unet server or LAN (broadcast and all sort of things like that :D)


    What I plan to do for the moment :

    -Compress information for rotation extrapolation on Rigidbody (priority : High)
    -Rigidbody2D synchronization (priority : High )

    -Download the entire HLAPI from UNET and modify it by :
    --Rewriting NetworkServer / NetworkClient because this wrappers seem so useless.
    --And so more...

    Known problems :

    -Movement syncronization is inefficient if you do not set NetworkServer.maxDelay to something like 10ms. Solution is not under our control, and we wait for direct udp message in LLAPI.


    For testing purpose you can build the current test scene (Rigidbody synchronization) and join your game on localHost.


    You have to understand that it is purely prototype. Share here improvement if you want :) .

    I have no much time right now to work on, but I provide this because it can be usefull for some people (And I am bored of "NetworkTransform doesn't work, halp me plz :p ).
     
  2. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    Hi,

    I ended up to write new networked system with gameObject system and Command/Rpc/AutoRpc/TargetRpc.

    The features are :

    -No more disabling gameObject when no server is running
    -You can send command/rpc etc from any client (not just the one with authority)
    -Multiple server is possible, but only the "main" server can handle object (I will modify this in next updates).
    -NetworkingBehaviour (The "old" NetworkBehaviour) have some callbacks (OnStartServer, OnStartAuthority etc...)

    You can also build a Server apart of the Client Unity project. GameObject are still working in case you are sure that NetworkingIdentity.AssetId and NetworkingIdentity.SceneId are the same.

    You can "Replicate" a gameObject in a scene. For exemple imagine you have a character, you connect to the server without any change in scene, your character is now replicated accross network and appear on other clients. It is not destroyed during server connection.

    There is many others little things, I don't really have so much time so :

    The adress if you want to look : https://github.com/Driiade/Unet_HLAPI_Ext/tree/master/Unet_HLAPI_Ext_Experimental

    Enjoy :)
     
    Last edited: Feb 24, 2018
    Denian16 and Munchy2007 like this.
  3. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    Hey,

    New Update :

    -You can specify a server for "replicated" object in scene, so if you connect to a server tagged by "MainServer" and your player is managed by "MainServer" it will be replicated for every client on this server.

    With this you will be able to manage different objects in scene if you connect to different server (like chat server and zone server and.. etc)

    -SendToOwner(NetworkingIdentity, ... ) function so from a client you can call a function to the owner of a gameObject. The owner is the client that manager a gameObject (example : a replicate player, the owner is the client who play with this player locally).

    -System for aware connection in networkingIdentity : a connection that know that this gameObject exist and have spawned it.

    -System for listening connection server side, a listening connection will receive all Rpc (auto rpc, and simple rpc). You have some callbacks server side like "OnServerAddListener(NetworkingConnection conn)" / OnServerAware(NetworkingConnection conn)" to send specific informations for synchronizing information (for example).

    ----Some others fix, like m_serverConnection in the networkingBehaviour (the owner connection server side) which was not well configured.

    IMPORTANT :

    2 preprocessor symbol : SERVER / CLIENT to specify if your project is a SERVER and/or CLIENT project. This will hide some part of code server side and client side. I use that to minimize useless compiled code and to protect code implementation on server side so client doesn't know what's the server side logic.


    Say if you want something. I have now to implement synchronized variables on networkingBehaviour. A long task, and not my priority ^^.

    Cheers.
     
    Last edited: Mar 10, 2018
    Denian16 likes this.
  4. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    Hello everyone,


    You now have the syncvar fonctionality :
    -Implement both IDirtable and ISerializable interface
    -Add a [NetworkedVariable] attribute on the variable.

    Like...humm... this :


    Code (CSharp):
    1.         [NetworkedVariable]
    2.         SyncVarWithAction<string> message1 = new SyncVarWithAction<string>("blabla");
    3.  
    4.  
    5.         private void Awake()
    6.         {
    7.             message1.callback += SetText;
    8.         }
    9.  
    10.  
    11.         private void SetText(string message)
    12.         {
    13.             Debug.Log(message);
    14.             text.text = message;
    15.         }
    16.  
    17.  
    Here it's a syncvar with an action, so each time it is deserialize to a client, the action is called.
    But you can make the logic you want !

    The logic for syncvar are : if you are owner you can update it, if there is no owner (like sceneObject) only the server can update it to all clients.


    You can also serialize a lot of things now, like enum or your own class !
    You just have to inherite from ISerializable and your function can come very powerful :


    Code (CSharp):
    1.     public class TestSerializationClass : ISerializable
    2.     {
    3.         public string message = "blabla";
    4.  
    5.         public void OnSerialize(NetworkingWriter writer)
    6.         {
    7.             writer.Write(": Serialization is possible " + Random.Range(0,100));
    8.         }
    9.  
    10.         public void OnDeserialize(NetworkingReader reader, NetworkingConnection clientConn, NetworkingConnection serverConn)
    11.         {
    12.             message = reader.ReadString();
    13.         }
    14.     }

    Code (CSharp):
    1.             if (isClient)
    2.             {
    3.                 SendToServer("Test", NetworkingChannel.DefaultReliableSequenced, "[Command] hello world : ", cpt, testClass);
    4.                 AutoSendToConnections("Test", NetworkingChannel.DefaultReliableSequenced, "[Auto Rpc] hello world : ", cpt, testClass);
    5.             }
    Code (CSharp):
    1.     [NetworkedFunction]
    2.     void Test(string message, int cpt, TestSerializationClass testClass)
    3.     {
    4.         Debug.Log(message + cpt + testClass.message);
    5.     }
    Now send what you want !


    Next update :
    -Timer for syncvar (because for now they are update the moment they are changed).
    -Better scene management.