diff --git a/Runtime/Plugins/netstandard2.0/Ragon.Client.deps.json b/Runtime/Plugins/netstandard2.0/Ragon.Client.deps.json index 492d342..2d252cf 100644 --- a/Runtime/Plugins/netstandard2.0/Ragon.Client.deps.json +++ b/Runtime/Plugins/netstandard2.0/Ragon.Client.deps.json @@ -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": {} @@ -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": {} } @@ -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": "" diff --git a/Runtime/Plugins/netstandard2.0/Ragon.Client.dll b/Runtime/Plugins/netstandard2.0/Ragon.Client.dll index 93cf822..f818866 100644 Binary files a/Runtime/Plugins/netstandard2.0/Ragon.Client.dll and b/Runtime/Plugins/netstandard2.0/Ragon.Client.dll differ diff --git a/Runtime/Plugins/netstandard2.0/Ragon.Protocol.dll b/Runtime/Plugins/netstandard2.0/Ragon.Protocol.dll index acec0a3..0120526 100644 Binary files a/Runtime/Plugins/netstandard2.0/Ragon.Protocol.dll and b/Runtime/Plugins/netstandard2.0/Ragon.Protocol.dll differ diff --git a/Runtime/Sources/Component/RagonAnimatorComponent.cs b/Runtime/Sources/Component/RagonAnimatorComponent.cs deleted file mode 100644 index 7d82cc8..0000000 --- a/Runtime/Sources/Component/RagonAnimatorComponent.cs +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2023 Eduard Kargin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using UnityEngine; - -namespace Ragon.Client.Unity -{ - [RequireComponent(typeof(RagonLink))] - public class RagonAnimatorComponent: RagonBehaviour - { - - } -} \ No newline at end of file diff --git a/Runtime/Sources/Component/RagonAnimatorComponent.cs.meta b/Runtime/Sources/Component/RagonAnimatorComponent.cs.meta deleted file mode 100644 index f580509..0000000 --- a/Runtime/Sources/Component/RagonAnimatorComponent.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: a2fc3dfa8047488cb2f29e7b45b76b47 -timeCreated: 1671608268 \ No newline at end of file diff --git a/Runtime/Sources/Component/RagonTransformComponent.cs b/Runtime/Sources/Component/RagonTransformComponent.cs index 2e1b0fd..ddd6c8b 100644 --- a/Runtime/Sources/Component/RagonTransformComponent.cs +++ b/Runtime/Sources/Component/RagonTransformComponent.cs @@ -14,6 +14,7 @@ * limitations under the License. */ +using System; using System.Collections.Generic; using Fusumity.Attributes.Specific; using Ragon.Client.Compressor; @@ -22,7 +23,6 @@ namespace Ragon.Client.Unity { - [RequireComponent(typeof(RagonLink))] public class RagonTransformComponent : RagonBehaviour { [SerializeField] private Transform target; diff --git a/Runtime/Sources/RagonLinkFinder.cs b/Runtime/Sources/RagonLinkFinder.cs new file mode 100644 index 0000000..3e36073 --- /dev/null +++ b/Runtime/Sources/RagonLinkFinder.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; + +namespace Ragon.Client.Unity +{ + public class RagonLinkFinder + { + private Dictionary _links = new Dictionary(); + + 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); + } + } +} \ No newline at end of file diff --git a/Runtime/Sources/RagonLinkFinder.cs.meta b/Runtime/Sources/RagonLinkFinder.cs.meta new file mode 100644 index 0000000..efebd07 --- /dev/null +++ b/Runtime/Sources/RagonLinkFinder.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a39e6ecd4467403b937258e1f6869504 +timeCreated: 1697486752 \ No newline at end of file diff --git a/Runtime/Sources/RagonNetwork.cs b/Runtime/Sources/RagonNetwork.cs index 1dcb6e4..49c0e20 100644 --- a/Runtime/Sources/RagonNetwork.cs +++ b/Runtime/Sources/RagonNetwork.cs @@ -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 { @@ -28,8 +26,7 @@ public class RagonNetwork : MonoBehaviour, IRagonSceneRequestListener { private static RagonNetwork _instance; - - private Dictionary _links; + private RagonLinkFinder _finder; private IRagonPrefabSpawner _spawner; private RagonClient _networkClient; private bool _sceneLoading = true; @@ -66,7 +63,7 @@ private void Awake() var defaultLogger = new RagonUnityLogger(); RagonLog.Set(defaultLogger); - _links = new Dictionary(); + _finder = new RagonLinkFinder(); _registry.Cache(); switch (_configuration.Type) @@ -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(); @@ -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; @@ -173,12 +171,20 @@ 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(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(); @@ -186,10 +192,10 @@ public static GameObject Create(GameObject prefab, IRagonPayload spawnPayload = 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(); var properties = link.Discovery(); @@ -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; } @@ -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) @@ -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); @@ -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); @@ -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); } } \ No newline at end of file diff --git a/Runtime/Sources/RagonPrefabRegistry.cs b/Runtime/Sources/RagonPrefabRegistry.cs index 65c57e9..a0cdcfa 100644 --- a/Runtime/Sources/RagonPrefabRegistry.cs +++ b/Runtime/Sources/RagonPrefabRegistry.cs @@ -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; } diff --git a/Runtime/Sources/RagonSceneCollector.cs b/Runtime/Sources/RagonSceneCollector.cs index 02b4884..fbd8242 100644 --- a/Runtime/Sources/RagonSceneCollector.cs +++ b/Runtime/Sources/RagonSceneCollector.cs @@ -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(); foreach (var go in gameObjects) { + if (!go.activeInHierarchy) continue; + var links = go.GetComponentsInChildren(); 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(); } }