Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
edmand46 committed Jul 30, 2023
1 parent 029a08c commit 6cce285
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
11 changes: 11 additions & 0 deletions Editor/RagonPrefabRegistryEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Plugins/netstandard2.0/Ragon.Client.dll
Binary file not shown.
6 changes: 3 additions & 3 deletions Sources/RagonBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ public class RagonBehaviour : MonoBehaviour

public RagonPlayer Owner => _entity.Owner;
public RagonEntity Entity => _entity;
public bool HasAuthority => _mine;
public bool HasAuthority => _authority;

private bool _mine;
private bool _authority;
private RagonEntity _entity;
private Dictionary<int, OnEventDelegate> _events = new Dictionary<int, OnEventDelegate>();
private Dictionary<int, Action<RagonPlayer, IRagonEvent>> _localEvents = new Dictionary<int, Action<RagonPlayer, IRagonEvent>>();

internal void Attach(RagonEntity entity)
{
_entity = entity;
_mine = entity.HasAuthority;
_authority = entity.HasAuthority;

OnAttachedEntity();
}
Expand Down
16 changes: 14 additions & 2 deletions Sources/RagonNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

using System.Collections.Generic;
using Ragon.Protocol;
using TMPro;
using UnityEngine;

Expand Down Expand Up @@ -138,14 +139,25 @@ public static void Disconnect()
_instance._networkClient.Disconnect();
}

public static GameObject Create(GameObject prefab, IRagonPayload payload = null)
public static GameObject Create(GameObject prefab, IRagonPayload spawnPayload = null)
{
if (prefab.TryGetComponent<RagonLink>(out var prefabLink))
{
var spawner = _instance._spawner;
var entity = new RagonEntity(prefabLink.Type, prefabLink.StaticID);
entity.AttachPayload(payload);

RagonPayload payload = null;
if (spawnPayload != null)
{
var buffer = new RagonBuffer();
spawnPayload.Serialize(buffer);

payload = new RagonPayload(buffer.WriteOffset);
payload.Read(buffer);

entity.AttachPayload(payload);
}

var go = spawner.InstantiateEntityGameObject(entity, prefab);
var link = go.GetComponent<RagonLink>();
var properties = link.Discovery();
Expand Down

0 comments on commit 6cce285

Please sign in to comment.