Unity Community


Page 2 of 4 FirstFirst 1234 LastLast
Results 21 to 40 of 68

  1. Location
    Pennsylvania
    Posts
    2,954
    So when you say its event based and not stream based, does that mean no serialization? Everything is reliable/unreliable RPC's?


  2. Location
    Sweden
    Posts
    1,413
    Quote Originally Posted by legend411 View Post
    So when you say its event based and not stream based, does that mean no serialization? Everything is reliable/unreliable RPC's?
    There is a stream for tranform data + extra data you can attach, but it's mostly handled automatically by the engine and not something you need to think of. You can write your own position tranform/data stream synchronizer if you for example only need 2 axes (2.5D game, etc) or only one axis of rotation, etc. Or if you want to attach some extra data like rigidbody velocity.

    But in general, most of the data you send back and forth is done using events (not RPCs, they exist also, but are of little real use other then for one off things like "Login", "enter world", etc.).
    Last edited by fholm; 02-21-2012 at 07:23 AM.
    My Open Source Projects: UdpKit, IronJS, Free Unity Assets
    Need unity consulting? Contact me over PM or Here


  3. Location
    Pennsylvania
    Posts
    2,954
    Quote Originally Posted by fholm View Post
    There is a stream for tranform data + extra data you can attach, but it's mostly handled automatically by the engine and not something you need to think of. You can write your own position tranform/data stream synchronizer if you for example only need 2 axes (2.5D game, etc) or only one axis of rotation, etc. Or if you want to attach some extra data like rigidbody velocity.

    But in general, most of the data you send back and forth is done using events (not RPCs, they exist also, but are of little real use other then for one off things like "Login", "enter world", etc.).
    Interesting... so what's a unity code sample look like of say, a client executing an attack or something? both the client side request and the server side event?


  4. Location
    Sweden
    Posts
    1,413
    We can take an example from the demo (simplified it a bit to make it easier to understand), first you need to define an event, here's a simple CastSpell event:

    Code:  
    1. public sealed class CastSpellEvent : Event<Actor>
    2. {
    3.     public override byte EventId { get { return HeaderBytes.UserStart + 3; } }
    4.     public override ProximityLevel ProximityLevel { get { return SlimNet.ProximityLevel.Horizon; } }
    5.     public override int DataSize { get { return 2; } }
    6.     public override bool Reliable { get { return true; } }
    7.  
    8.     public Actor SpellTarget { get; set; }
    9.  
    10.     public CastSpellEvent()
    11.         : base(EventTargets.Owner | EventTargets.Remotes, EventSources.Owner)
    12.     {
    13.  
    14.     }
    15.  
    16.     public override void Pack(SlimNet.Network.ByteOutStream stream)
    17.     {
    18.         stream.WriteActor(SpellTarget);
    19.     }
    20.  
    21.     public override void Unpack(SlimNet.Network.ByteInStream stream)
    22.     {
    23.         SpellTarget = stream.ReadActor();
    24.     }
    25. }

    Explanation of the standard properties of the event:

    • EventId is a byte that is unique to this event, basically it's id.
    • ProximityLevel is an interest based flag that decides what players should get an event based on how close they are to the origin of the event
    • DataSize is the size of the data in the event, in this case 2 as we're sending an actor reference over the wire (the target of the spell)
    • Reliable decides if the event should be reliable or not


    The property SpellTarget is specific to this event, and it's the target of the spell (duh ;p).

    The call to the base constructor is a bit specific, the constructor in SlimNet.Event<T> looks like this:

    Code:  
    1. Event(EventTargets targets, EventSources sources)

    EventTargets controls what peers the event should be raised on.
    EventSources controls what peers are allowed to raise the event.

    In this case of the CastSpellEvent the event will be sent to the owner of the actor (game object) and to all remote players. It's only allowed to be raised from the owner of the object (it would not make a lot of sense to raise "cast spell" for an actor you don't control)

    Pack and Unpack is basically the Serialize/Unserialize methods which packs or unpacks the data of the event.

    Now, assume you have a target selected and want to throw a fireball at it, it would look like this:

    Code:  
    1. actor.RaiseEvent<MMODemo.CastSpellEvent>((ev) =>
    2. {
    3.     ev.SpellTarget = target.Value;
    4. });

    This event will be raised on your local client (as you're the owner) and then sent to the server which distributes it to all other clients, they listen to the event by doing this:

    Code:  
    1.    void Start()
    2.     {
    3.         actor = this.GetSlimNetActor();
    4.         actor.RegisterEventReceiver<MMODemo.CastSpellEvent>(onCast);
    5.     }
    6.  
    7.     void onCast(MMODemo.CastSpellEvent ev)
    8.     {
    9.          // Cast spell
    10.     }
    My Open Source Projects: UdpKit, IronJS, Free Unity Assets
    Need unity consulting? Contact me over PM or Here


  5. Location
    Sweden
    Posts
    1,413
    Also note that all events that are sent are automatically synchronized to the movement of the players on the remote clients and server, so there is no need to manually align movement and actions, it's done automatically for you.
    My Open Source Projects: UdpKit, IronJS, Free Unity Assets
    Need unity consulting? Contact me over PM or Here


  6. Location
    Sweden
    Posts
    1,413
    After some really good feedback from a user on IRC I implemented an "embedded development server" inside Unity which compiles and runs the server for you when you hit play, easiest way to explain it is to just watch the video and see it in action:

    My Open Source Projects: UdpKit, IronJS, Free Unity Assets
    Need unity consulting? Contact me over PM or Here


  7. Posts
    155
    I'm impressed how easy it is to set up quick networking with this framework. There's some things I'm not a hundred percent sure how you'd set up. Like I'm trying to get a server to only send nearby entities. Additionally, I want my server to unload sections of the game world not currently in use (my game requires sending map data as the player moves around). It's probably not terribly hard, I guess I'm just not used to this kind of coding standard. It looks really good so far though! I'll mess around with it some more to see if it's what I need.


  8. Posts
    116
    I Might be blind or something, but don't understand how the system knows to instantiate "Player" prefab in the resources folder of the demo. Been searching for 2 hours. Might be missing an open door here?


  9. Posts
    2,601
    ActorExtension.cs


  10. Posts
    116
    Call me stupid but this is the code of actorExtension:

    Code:  
    1. /*
    2.  * SlimNet - Networking Middleware For Games
    3.  * Copyright (C) 2011-2012 Fredrik Holmström
    4.  *
    5.  * This software is provided 'as-is', without any express or implied
    6.  * warranty. In no event will the authors be held liable for any damages
    7.  * arising from the use of this software.
    8.  *
    9.  * Attribution
    10.  * The origin of this software must not be misrepresented; you must not
    11.  * claim that you wrote the original software. For any works using this
    12.  * software, reasonable acknowledgment is required.
    13.  *
    14.  * Noncommercial
    15.  * You may not use this software for commercial purposes.
    16.  *
    17.  * Distribution
    18.  * You are free to share, copy and distribute the software in it's original,
    19.  * unmodified form. You are not allowed to distribute or make publicly
    20.  * available the software itself or it's sources in any modified manner.
    21.  * This notice may not be removed or altered from any source distribution.
    22.  */
    23.  
    24.  
    25. using UnityEngine;
    26.  
    27. namespace SlimNet.Unity
    28. {
    29.     public static class ActorExtensions
    30.     {
    31.         public static GameObject GetGameObject(this Actor actor)
    32.         {
    33.             return GameObjectMap.Retrieve(actor);
    34.         }
    35.  
    36.         public static UnityEngine.Transform GetUnityTransform(this Actor actor)
    37.         {
    38.             return GameObjectMap.Retrieve(actor).transform;
    39.         }
    40.     }
    41. }

    But where does it define that the "Player" prefab should be used as the instantiate object "Actor"?


  11. Location
    Sweden
    Posts
    1,413
    it is not in ActorExtentions.cs but in peerutils.cs
    My Open Source Projects: UdpKit, IronJS, Free Unity Assets
    Need unity consulting? Contact me over PM or Here


  12. Posts
    2,601
    Sorry, he changed it in the latest version, it's located in the PeerUtils.cs


  13. Posts
    116
    Ok I am finding it very hard to understand the structure etc. How does this work? There are 3 prefabs, and for some reason it chooses "Player.prefab" to be the prefab for input etc. I am sorry if I am lacking skills to see this through just like that, but none of the videos talk about this, and for some reason, I just don't get it.

    Why is player.prefab loaded as the actor for input/camera and other players?

    Next to that, what happened to the idea of exporting the scene for the server? Is it still authorative?

    It looks like a promising framework and I'd love to give it a spin but for some reason I get confused like crazy..


  14. Posts
    116
    So yeah I might have been sleeping like a baby or something. The following code loads the actor based on what the derrived name is of ActorDefinition:
    Code:  
    1.        public ActorDefinition(Context context)
    2.         {
    3.             Context = context;
    4.             Name =
    5.                 GetType()
    6.                     .Name
    7.                     .Replace("Definition", "")
    8.                     .Replace("Actor", "");
    9.         }

    The contextPlugin of MMODemo.Server spawns the actor with prefab "Player" since the name is PlayerActorDefinition (above code removes actor definition to define the prefab name):
    Code:  
    1.        public override void PlayerJoined(SlimNet.Player player)
    2.         {
    3.             Context.PlayerEventHandler.Raise<SlimNet.Events.Authenticated>(
    4.                 player,
    5.                 (ev) =>
    6.                 {
    7.                     ev.IsAuthenticated = true;
    8.                     ev.Error = "";
    9.                 }
    10.             );
    11.  
    12.             base.PlayerJoined(player);
    13.  
    14.             Context.Server.SpawnActor<PlayerActorDefinition>(player, new SlimMath.Vector3(45, 10, 45));
    15.         }
    16.     }

    I am just filling this in for future reference for others, so they don't have to go through this.

    The only thing I do not understand yet is what config-prefabs.xml has to do with this, and if it does anything, how I'd go and generate it.

    If I would want to spawn say, a car, and this object would be important because the player drives in it and thus its location should be synced at all players based on the input, would I make something like a "CarActorDefinition" and spawn it at some point with a velocityEvent attached?

    Kind regards


  15. Location
    Sweden
    Posts
    1,413
    Jan: I will try to give you a longer response later, config-prefabs.xml is part of some old, now unused code and is not needed anywhere. 0.2.1 will be a nice cleanup of all the "old code" being removed + embedded editor + linux/osx support + a proper video tutorial of about 10 parts.

    though, as I said in another post on this forum, I took a big piece out of my index finger with a steak knife yday and can't program for about it a week. It (0.2.1) was supposed to be out mid-end next week, but I have to rest my left hand sadly ;p
    My Open Source Projects: UdpKit, IronJS, Free Unity Assets
    Need unity consulting? Contact me over PM or Here


  16. Posts
    116
    Quote Originally Posted by fholm View Post
    Jan: I will try to give you a longer response later, config-prefabs.xml is part of some old, now unused code and is not needed anywhere. 0.2.1 will be a nice cleanup of all the "old code" being removed + embedded editor + linux/osx support + a proper video tutorial of about 10 parts.

    though, as I said in another post on this forum, I took a big piece out of my index finger with a steak knife yday and can't program for about it a week. It (0.2.1) was supposed to be out mid-end next week, but I have to rest my left hand sadly ;p
    Hey man didn't know that no worries. Make sure your finger heals right. It just takes a lot of time to go through it all. Have you considered one or more github repos? As I am spitting through for example I'd be happy to make notes here and there..


  17. Location
    Sweden
    Posts
    1,413
    Quote Originally Posted by JanHelleman View Post
    Hey man didn't know that no worries. Make sure your finger heals right. It just takes a lot of time to go through it all. Have you considered one or more github repos? As I am spitting through for example I'd be happy to make notes here and there..
    I have three github repos, but they are all private currently.
    My Open Source Projects: UdpKit, IronJS, Free Unity Assets
    Need unity consulting? Contact me over PM or Here


  18. Posts
    116
    Ok, let me know if you want me to help out on something.

    for now my scenario is:

    I want a network synced car that can be controlled by a player. Obviously when the player enters the car it does not need to sync the transform anymore and would become dependant on the car. The car should then start syncing. The player would probably become a child of the car transform (sitting right etc). I'd figure this would be an "enter car event" where the player actor would stop syncing transform and the car starts syncing? Further I guess the car that the player sits in should start beeing considered "IsMine" as well.

    Right now I created a CarActorDefinition and CarBehaviour. It instantiates some dummy Car prefabs correctly when the client connects (obviously). How would you suggest the above scenario and further more, am I following your pattern when I'd be doing it this way?


  19. Location
    Sweden
    Posts
    1,413
    JanHelleman: Currently, the engine doesn't support changing ownership of an actor, this will be supported in 0.2.1 however. Other then that what you described is probably what I would do also.

    Also, I'll throw in a quick update on 0.2.1. It's done, but I'm holding it back while finishing up a much better version of the example game and the tutorial videos. Expect everything to land early next week. Here's a screenshot of the demo, complete with working chat + player portrait + three spells.



    (large version: http://dl.dropbox.com/u/19877504/021_demo_3.png)
    My Open Source Projects: UdpKit, IronJS, Free Unity Assets
    Need unity consulting? Contact me over PM or Here


  20. Posts
    300
    Cool! Ok, now subscribed to the 0.2 Beta thread. I'm going to take a look at this over the weekend. Excellent stuff from what I can tell so far!

Page 2 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •