Skip to content

Commit

Permalink
update sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
edmand46 committed Nov 5, 2023
1 parent dd67f1c commit b4072fe
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 57 deletions.
6 changes: 3 additions & 3 deletions Runtime/Plugins/netstandard2.0/Ragon.Client.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Ragon.Client/1.0.0": {
"dependencies": {
"NETStandard.Library": "2.0.3",
"Ragon.Protocol": "1.2.4-rc"
"Ragon.Protocol": "1.0.0"
},
"runtime": {
"Ragon.Client.dll": {}
Expand All @@ -22,7 +22,7 @@
"Microsoft.NETCore.Platforms": "1.1.0"
}
},
"Ragon.Protocol/1.2.4-rc": {
"Ragon.Protocol/1.0.0": {
"runtime": {
"Ragon.Protocol.dll": {}
}
Expand All @@ -49,7 +49,7 @@
"path": "netstandard.library/2.0.3",
"hashPath": "netstandard.library.2.0.3.nupkg.sha512"
},
"Ragon.Protocol/1.2.4-rc": {
"Ragon.Protocol/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
Expand Down
Binary file modified Runtime/Plugins/netstandard2.0/Ragon.Client.dll
Binary file not shown.
Binary file modified Runtime/Plugins/netstandard2.0/Ragon.Protocol.dll
Binary file not shown.
26 changes: 0 additions & 26 deletions Runtime/Sources/Component/RagonAnimatorComponent.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Runtime/Sources/Component/RagonAnimatorComponent.cs.meta

This file was deleted.

2 changes: 1 addition & 1 deletion Runtime/Sources/Component/RagonTransformComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using Fusumity.Attributes.Specific;
using Ragon.Client.Compressor;
Expand All @@ -22,7 +23,6 @@

namespace Ragon.Client.Unity
{
[RequireComponent(typeof(RagonLink))]
public class RagonTransformComponent : RagonBehaviour
{
[SerializeField] private Transform target;
Expand Down
24 changes: 24 additions & 0 deletions Runtime/Sources/RagonLinkFinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;

namespace Ragon.Client.Unity
{
public class RagonLinkFinder
{
private Dictionary<RagonEntity, RagonLink> _links = new Dictionary<RagonEntity, RagonLink>();

internal bool Find(RagonEntity entity, out RagonLink link)
{
return _links.TryGetValue(entity, out link);
}

internal void Track(RagonEntity entity, RagonLink link)
{
_links.Add(entity, link);
}

internal void Untrack(RagonEntity entity)
{
_links.Remove(entity);
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Sources/RagonLinkFinder.cs.meta

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

44 changes: 25 additions & 19 deletions Runtime/Sources/RagonNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
* limitations under the License.
*/

using System.Collections.Generic;
using Ragon.Client.Utility;
using Ragon.Protocol;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Ragon.Client.Unity
{
Expand All @@ -28,8 +26,7 @@ public class RagonNetwork : MonoBehaviour,
IRagonSceneRequestListener
{
private static RagonNetwork _instance;

private Dictionary<RagonEntity, RagonLink> _links;
private RagonLinkFinder _finder;
private IRagonPrefabSpawner _spawner;
private RagonClient _networkClient;
private bool _sceneLoading = true;
Expand Down Expand Up @@ -66,7 +63,7 @@ private void Awake()
var defaultLogger = new RagonUnityLogger();
RagonLog.Set(defaultLogger);

_links = new Dictionary<RagonEntity, RagonLink>();
_finder = new RagonLinkFinder();
_registry.Cache();

switch (_configuration.Type)
Expand All @@ -91,9 +88,13 @@ private void Awake()
}
}

Configure(new RagonSceneCollector(), new RagonPrefabSpawner());
var collector = new RagonSceneCollector(_finder);
var spawner = new RagonPrefabSpawner();

Configure(collector, spawner);
}


public void OnRequestScene(RagonClient client, string sceneName)
{
_sceneRequest?.Dispose();
Expand Down Expand Up @@ -147,11 +148,8 @@ public void OnEntityCreated(RagonEntity entity)
entity.Attached += link.OnAttached;
entity.Detached += link.OnDetached;
entity.OwnershipChanged += link.OnOwnershipChanged;

_instance._links.Add(entity, link);
}


public static void Connect()
{
var configuration = _instance._configuration;
Expand All @@ -173,23 +171,31 @@ public static void Disconnect()

public static GameObject Create(GameObject prefab, IRagonPayload spawnPayload = null)
{
if (_instance._networkClient.Status != RagonStatus.ROOM)
{
RagonLog.Warn("You are not in room!");
return null;
}

if (prefab.TryGetComponent<RagonLink>(out var prefabLink))
{
var client = _instance._networkClient;
var local = client.Room.Local;
var spawner = _instance._spawner;
var entity = new RagonEntity(prefabLink.Type, prefabLink.StaticID);

RagonPayload payload = null;
var payload = RagonPayload.Empty;

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

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

entity.AttachPayload(payload);
}


entity.Prepare(client, 0, prefabLink.Type, true, local, payload);

var go = spawner.InstantiateEntityGameObject(entity, prefab);
var link = go.GetComponent<RagonLink>();
var properties = link.Discovery();
Expand All @@ -202,7 +208,7 @@ public static GameObject Create(GameObject prefab, IRagonPayload spawnPayload =
entity.OwnershipChanged += link.OnOwnershipChanged;

_instance._networkClient.Room.CreateEntity(entity, payload);
_instance._links.Add(entity, link);
_instance._finder.Track(entity, link);

return go;
}
Expand All @@ -218,7 +224,7 @@ public static bool TryGetLink(ushort entityId, out RagonLink link)
return false;
}

return _instance._links.TryGetValue(entity, out link);
return _instance._finder.Find(entity, out link);
}

public static void Transfer(GameObject go, RagonPlayer player)
Expand Down Expand Up @@ -250,7 +256,7 @@ public static void Destroy(GameObject go, RagonPayload? payload = null)
var entity = link.Entity;

_instance._networkClient.Room.DestroyEntity(entity);
_instance._links.Remove(entity);
_instance._finder.Untrack(entity);
}

public static void AddListener(IRagonListener listener) => _instance._networkClient.AddListener(listener);
Expand All @@ -274,7 +280,7 @@ public static void Destroy(GameObject go, RagonPayload? payload = null)
public static void AddListener(IRagonPlayerJoinListener listener) => _instance._networkClient.AddListener(listener);

public static void AddListener(IRagonPlayerLeftListener listener) => _instance._networkClient.AddListener(listener);

public static void AddListener(IRagonDataListener listener) => _instance._networkClient.AddListener(listener);

public static void RemoveListener(IRagonListener listener) => _instance._networkClient.RemoveListener(listener);
Expand All @@ -298,7 +304,7 @@ public static void Destroy(GameObject go, RagonPayload? payload = null)
public static void RemoveListener(IRagonPlayerJoinListener listener) => _instance._networkClient.RemoveListener(listener);

public static void RemoveListener(IRagonPlayerLeftListener listener) => _instance._networkClient.RemoveListener(listener);

public static void RemoveListener(IRagonDataListener listener) => _instance._networkClient.RemoveListener(listener);
}
}
1 change: 0 additions & 1 deletion Runtime/Sources/RagonPrefabRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public void Rescan()
if (!string.IsNullOrEmpty(link.PrefabId))
{
_prefabs.Add(new EntityPrefab() { Prefab = link.gameObject, EntityType = link.Type });
_prefabTypes.Add(link.PrefabId, link.Type);
continue;
}

Expand Down
20 changes: 16 additions & 4 deletions Runtime/Sources/RagonSceneCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,43 @@

namespace Ragon.Client.Unity
{
public class RagonSceneCollector: IRagonSceneCollector
public class RagonSceneCollector : IRagonSceneCollector
{
private RagonLinkFinder _finder;

public RagonSceneCollector(RagonLinkFinder finder)
{
_finder = finder;
}

public RagonEntity[] Collect()
{
var gameObjects = SceneManager.GetActiveScene().GetRootGameObjects();
var entities = new List<RagonEntity>();
foreach (var go in gameObjects)
{
if (!go.activeInHierarchy) continue;

var links = go.GetComponentsInChildren<RagonLink>();
foreach (var link in links)
{
if (link.StaticID == 0) continue;

var properties = link.Discovery();
var entity = new RagonEntity(link.Type, link.StaticID);
foreach (var property in properties)
entity.State.AddProperty(property);

entity.Attached += link.OnAttached;
entity.Detached += link.OnDetached;
entity.OwnershipChanged += link.OnOwnershipChanged;

entities.Add(entity);

_finder.Track(entity, link);
}
}

return entities.ToArray();
}
}
Expand Down

0 comments on commit b4072fe

Please sign in to comment.