From 7ff666f66a32b7b2bf1a582709b60c3de172a29e Mon Sep 17 00:00:00 2001 From: Hertzole Date: Fri, 12 Jan 2024 17:10:57 +0100 Subject: [PATCH] remove: networking support I can't keep up with all the breaking changes, so I've decided to just drop support for it. --- .../Runtime/Networking.meta | 3 - .../Runtime/Networking/FishNet.meta | 3 - .../SyncedScriptableDictionary.FishNet.cs | 192 --------- ...SyncedScriptableDictionary.FishNet.cs.meta | 3 - .../FishNet/SyncedScriptableList.FishNet.cs | 205 ---------- .../SyncedScriptableList.FishNet.cs.meta | 3 - .../FishNet/SyncedScriptableValue.FishNet.cs | 96 ----- .../SyncedScriptableValue.FishNet.cs.meta | 3 - .../Runtime/Networking/NGO.meta | 8 - .../NGO/SyncedScriptableList.NGO.cs | 363 ------------------ .../NGO/SyncedScriptableList.NGO.cs.meta | 11 - .../NGO/SyncedScriptableValue.NGO.cs | 166 -------- .../NGO/SyncedScriptableValue.NGO.cs.meta | 11 - .../Networking/SyncedScriptableDictionary.cs | 49 --- .../SyncedScriptableDictionary.cs.meta | 3 - .../Networking/SyncedScriptableList.cs | 74 ---- .../Networking/SyncedScriptableList.cs.meta | 3 - .../Networking/SyncedScriptableValue.cs | 46 --- .../Networking/SyncedScriptableValue.cs.meta | 3 - README.md | 96 +---- 20 files changed, 1 insertion(+), 1340 deletions(-) delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking.meta delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet.meta delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableDictionary.FishNet.cs delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableDictionary.FishNet.cs.meta delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableList.FishNet.cs delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableList.FishNet.cs.meta delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableValue.FishNet.cs delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableValue.FishNet.cs.meta delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO.meta delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableList.NGO.cs delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableList.NGO.cs.meta delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableValue.NGO.cs delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableValue.NGO.cs.meta delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableDictionary.cs delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableDictionary.cs.meta delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableList.cs delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableList.cs.meta delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableValue.cs delete mode 100644 Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableValue.cs.meta diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking.meta b/Packages/se.hertzole.scriptable-values/Runtime/Networking.meta deleted file mode 100644 index 6fbe189..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 640cb51ae9a54e2f8dc1c6fd8c81a01f -timeCreated: 1686686433 \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet.meta b/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet.meta deleted file mode 100644 index a6849f4..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 9dfd5a299c7e4cadb3bec8fabdde8361 -timeCreated: 1686686512 \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableDictionary.FishNet.cs b/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableDictionary.FishNet.cs deleted file mode 100644 index 89e4136..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableDictionary.FishNet.cs +++ /dev/null @@ -1,192 +0,0 @@ -#if (FISHNET || SCRIPTABLE_VALUES_NGO) -#define SCRIPTABLE_VALUES_NETWORKING -#endif - -#if SCRIPTABLE_VALUES_NETWORKING && FISHNET -using System; -using FishNet.Object.Synchronizing; -using FishNet.Object.Synchronizing.Internal; - -namespace Hertzole.ScriptableValues -{ - partial class SyncedScriptableDictionary : SyncBase, ICustomSync - { - private DidOperationFlags didOperation; - - private readonly SyncDictionary syncDictionary = new SyncDictionary(); - - [Flags] - private enum DidOperationFlags - { - None = 0, - Add = 1, - Set = 2, - Remove = 4, - Clear = 8 - } - - protected override void Registered() - { - syncDictionary.InitializeInstance(NetworkBehaviour, byte.MaxValue - SyncIndex, Settings.WritePermission, Settings.ReadPermission, Settings.SendRate, - Settings.Channel, IsSyncObject); - - base.Registered(); - syncDictionary.SetRegistered(); - } - - partial void OnInitialized() - { - syncDictionary.OnChange += OnSyncDictionaryChanged; - } - - private void OnSyncDictionaryChanged(SyncDictionaryOperation op, TKey key, TValue value, bool asServer) - { - if (asServer) - { - return; - } - - switch (op) - { - case SyncDictionaryOperation.Add: - if ((didOperation & DidOperationFlags.Add) != 0) - { - didOperation &= ~DidOperationFlags.Add; - return; - } - - didOperation |= DidOperationFlags.Add; - targetDictionary.Add(key, value); - break; - case SyncDictionaryOperation.Clear: - if ((didOperation & DidOperationFlags.Clear) != 0) - { - didOperation &= ~DidOperationFlags.Clear; - return; - } - - didOperation |= DidOperationFlags.Clear; - targetDictionary.Clear(); - break; - case SyncDictionaryOperation.Remove: - if ((didOperation & DidOperationFlags.Remove) != 0) - { - didOperation &= ~DidOperationFlags.Remove; - return; - } - - didOperation |= DidOperationFlags.Remove; - targetDictionary.Remove(key); - break; - case SyncDictionaryOperation.Set: - if ((didOperation & DidOperationFlags.Set) != 0) - { - didOperation &= ~DidOperationFlags.Set; - return; - } - - didOperation |= DidOperationFlags.Set; - targetDictionary[key] = value; - break; - case SyncDictionaryOperation.Complete: - break; - default: - throw new ArgumentOutOfRangeException(nameof(op), op, null); - } - } - - partial void OnAdded(TKey key, TValue value) - { - if ((didOperation & DidOperationFlags.Add) != 0) - { - didOperation &= ~DidOperationFlags.Add; - return; - } - - bool asServerInvoke = !IsNetworkInitialized || NetworkBehaviour.IsServer; - - if (!asServerInvoke) - { - return; - } - - didOperation |= DidOperationFlags.Add; - syncDictionary.Add(key, value); - } - - partial void OnRemoved(TKey key, TValue value) - { - if ((didOperation & DidOperationFlags.Remove) != 0) - { - didOperation &= ~DidOperationFlags.Remove; - return; - } - - bool asServerInvoke = !IsNetworkInitialized || NetworkBehaviour.IsServer; - - if (!asServerInvoke) - { - return; - } - - didOperation |= DidOperationFlags.Remove; - syncDictionary.Remove(key); - } - - partial void OnSet(TKey key, TValue oldValue, TValue newValue) - { - if ((didOperation & DidOperationFlags.Set) != 0) - { - didOperation &= ~DidOperationFlags.Set; - return; - } - - bool asServerInvoke = !IsNetworkInitialized || NetworkBehaviour.IsServer; - - if (!asServerInvoke) - { - return; - } - - didOperation |= DidOperationFlags.Set; - syncDictionary[key] = newValue; - } - - partial void OnCleared() - { - if ((didOperation & DidOperationFlags.Clear) != 0) - { - didOperation &= ~DidOperationFlags.Clear; - return; - } - - bool asServerInvoke = !IsNetworkInitialized || NetworkBehaviour.IsServer; - - if (!asServerInvoke) - { - return; - } - - didOperation |= DidOperationFlags.Clear; - syncDictionary.Clear(); - } - - partial void OnDisposed() - { - syncDictionary.OnChange -= OnSyncDictionaryChanged; - } - - public override void Reset() - { - base.Reset(); - - syncDictionary.Clear(); - } - - public object GetSerializedType() - { - return null; - } - } -} -#endif \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableDictionary.FishNet.cs.meta b/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableDictionary.FishNet.cs.meta deleted file mode 100644 index 08554c9..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableDictionary.FishNet.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 6dfc43aa02cb46bb8cac8a16bbcb3731 -timeCreated: 1686751461 \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableList.FishNet.cs b/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableList.FishNet.cs deleted file mode 100644 index 0aa4654..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableList.FishNet.cs +++ /dev/null @@ -1,205 +0,0 @@ -#if (FISHNET || SCRIPTABLE_VALUES_NGO) -#define SCRIPTABLE_VALUES_NETWORKING -#endif - -#if SCRIPTABLE_VALUES_NETWORKING && FISHNET -using System; -using FishNet.Object.Synchronizing; -using FishNet.Object.Synchronizing.Internal; - -namespace Hertzole.ScriptableValues -{ - partial class SyncedScriptableList : SyncBase, ICustomSync - { - private DidOperationFlags didOperation; - - private readonly SyncList syncList = new SyncList(); - - protected override void Registered() - { - syncList.InitializeInstance(NetworkBehaviour, byte.MaxValue - SyncIndex, Settings.WritePermission, Settings.ReadPermission, Settings.SendRate, - Settings.Channel, IsSyncObject); - - base.Registered(); - syncList.SetRegistered(); - } - - partial void OnInitialized() - { - syncList.OnChange += OnSyncListChanged; - } - - private void OnSyncListChanged(SyncListOperation op, int index, T oldItem, T newItem, bool asServer) - { - if (!isInitialized || asServer) - { - return; - } - - switch (op) - { - case SyncListOperation.Add: - if ((didOperation & DidOperationFlags.Add) != 0) - { - didOperation &= ~DidOperationFlags.Add; - return; - } - - didOperation |= DidOperationFlags.Add; - targetList.Add(newItem); - break; - case SyncListOperation.Insert: - if ((didOperation & DidOperationFlags.Insert) != 0) - { - didOperation &= ~DidOperationFlags.Insert; - return; - } - - didOperation |= DidOperationFlags.Insert; - targetList.Insert(index, newItem); - break; - case SyncListOperation.Set: - if ((didOperation & DidOperationFlags.Set) != 0) - { - didOperation &= ~DidOperationFlags.Set; - return; - } - - didOperation |= DidOperationFlags.Set; - targetList[index] = newItem; - break; - case SyncListOperation.RemoveAt: - if ((didOperation & DidOperationFlags.Remove) != 0) - { - didOperation &= ~DidOperationFlags.Remove; - return; - } - - didOperation |= DidOperationFlags.Remove; - targetList.RemoveAt(index); - break; - case SyncListOperation.Clear: - if ((didOperation & DidOperationFlags.Clear) != 0) - { - didOperation &= ~DidOperationFlags.Clear; - return; - } - - didOperation |= DidOperationFlags.Clear; - targetList.Clear(); - break; - case SyncListOperation.Complete: - break; - default: - throw new ArgumentOutOfRangeException(nameof(op), op, null); - } - } - - partial void OnAdded(T item) - { - if ((didOperation & DidOperationFlags.Add) != 0) - { - didOperation &= ~DidOperationFlags.Add; - return; - } - - bool asServerInvoke = !IsNetworkInitialized || NetworkBehaviour.IsServer; - - if (!asServerInvoke) - { - return; - } - - didOperation |= DidOperationFlags.Add; - syncList.Add(item); - } - - partial void OnRemoved(int index, T item) - { - if ((didOperation & DidOperationFlags.Remove) != 0) - { - didOperation &= ~DidOperationFlags.Remove; - return; - } - - bool asServerInvoke = !IsNetworkInitialized || NetworkBehaviour.IsServer; - - if (!asServerInvoke) - { - return; - } - - didOperation |= DidOperationFlags.Remove; - syncList.RemoveAt(index); - } - - partial void OnInserted(int index, T item) - { - if ((didOperation & DidOperationFlags.Insert) != 0) - { - didOperation &= ~DidOperationFlags.Insert; - return; - } - - bool asServerInvoke = !IsNetworkInitialized || NetworkBehaviour.IsServer; - - if (!asServerInvoke) - { - return; - } - - didOperation |= DidOperationFlags.Insert; - syncList.Insert(index, item); - } - - partial void OnSet(int index, T oldItem, T newItem) - { - if ((didOperation & DidOperationFlags.Set) != 0) - { - didOperation &= ~DidOperationFlags.Set; - return; - } - - bool asServerInvoke = !IsNetworkInitialized || NetworkBehaviour.IsServer; - - if (!asServerInvoke) - { - return; - } - - didOperation |= DidOperationFlags.Set; - syncList[index] = newItem; - } - - partial void OnCleared() - { - if ((didOperation & DidOperationFlags.Clear) != 0) - { - didOperation &= ~DidOperationFlags.Clear; - return; - } - - bool asServerInvoke = !IsNetworkInitialized || NetworkBehaviour.IsServer; - - if (!asServerInvoke) - { - return; - } - - didOperation |= DidOperationFlags.Clear; - syncList.Clear(); - } - - public void Dispose() - { - DisposeTargetList(); - syncList.OnChange -= OnSyncListChanged; - } - - public object GetSerializedType() - { - return null; - } - } -} -#endif \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableList.FishNet.cs.meta b/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableList.FishNet.cs.meta deleted file mode 100644 index 26839b2..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableList.FishNet.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b217f53fb475411f8b5bc71d65ba8e1e -timeCreated: 1686689528 \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableValue.FishNet.cs b/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableValue.FishNet.cs deleted file mode 100644 index e1a9977..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableValue.FishNet.cs +++ /dev/null @@ -1,96 +0,0 @@ -#if (FISHNET || SCRIPTABLE_VALUES_NGO) -#define SCRIPTABLE_VALUES_NETWORKING -#endif - -#if SCRIPTABLE_VALUES_NETWORKING && FISHNET -using System.Runtime.CompilerServices; -using FishNet.Object.Synchronizing; -using FishNet.Object.Synchronizing.Internal; -using FishNet.Serializing; - -namespace Hertzole.ScriptableValues -{ - partial class SyncedScriptableValue : SyncBase, ICustomSync - { - private bool valueChanged; - - private T currentValue; - - partial void OnValueChanging(T previousValue, T newValue) - { - if (!IsRegistered) - { - return; - } - - if (!NetworkBehaviour.IsServer) - { - return; - } - - valueChanged = true; - currentValue = newValue; - - Dirty(); - } - - public override void WriteFull(PooledWriter writer) - { - if (!isInitialized || !valueChanged) - { - return; - } - - WriteHeader(writer, false); - - writer.Write(currentValue); - } - - public override void WriteDelta(PooledWriter writer, bool resetSyncTick = true) - { - if (!isInitialized) - { - return; - } - - base.WriteDelta(writer, resetSyncTick); - - writer.Write(currentValue); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override void Read(PooledReader reader, bool asServer) - { - if (!isInitialized) - { - return; - } - - bool asClientAndHost = !asServer && NetworkManager.IsServer; - - T newValue = reader.Read(); - - if (!asClientAndHost) - { - targetValue.Value = newValue; - } - } - - public override void Reset() - { - base.Reset(); - valueChanged = false; - } - - public object GetSerializedType() - { - return null; - } - - public void Dispose() - { - DisposeScriptableValue(); - } - } -} -#endif \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableValue.FishNet.cs.meta b/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableValue.FishNet.cs.meta deleted file mode 100644 index 3497152..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/FishNet/SyncedScriptableValue.FishNet.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 202b605a7c4d4723a0ecd1b0a641e45a -timeCreated: 1686686527 \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO.meta b/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO.meta deleted file mode 100644 index 059de1a..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: c23018285c63e4040bb191effdc163f4 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableList.NGO.cs b/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableList.NGO.cs deleted file mode 100644 index 379ccf3..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableList.NGO.cs +++ /dev/null @@ -1,363 +0,0 @@ -#if (FISHNET || SCRIPTABLE_VALUES_NGO) -#define SCRIPTABLE_VALUES_NETWORKING -#endif - -#if SCRIPTABLE_VALUES_NETWORKING && SCRIPTABLE_VALUES_NGO -using System; -using Unity.Netcode; - -namespace Hertzole.ScriptableValues -{ - partial class SyncedScriptableList : NetworkVariableBase where T : unmanaged, IEquatable - { - private bool hasInitializedNetworkList; - private bool forceIsSpawned; - - private DidOperationFlags didOperation; - - private NetworkList networkList; - - private bool IsSpawned - { - get { return GetBehaviour() != null && (forceIsSpawned || GetBehaviour().IsSpawned); } - } - - private bool CanWrite - { - get { return CanClientWrite(GetBehaviour().NetworkManager.LocalClientId); } - } - - public SyncedScriptableList(NetworkVariableReadPermission readPerm = DefaultReadPerm, NetworkVariableWritePermission writePerm = DefaultWritePerm) : - base(readPerm, writePerm) - { - hasInitializedNetworkList = false; - } - - partial void OnInitialized() - { - networkList = new NetworkList(targetList.list, ReadPerm, WritePerm); - networkList.OnListChanged += OnNetworkListChanged; - - if (IsSpawned && GetBehaviour().IsServer) - { - SetDirty(true); - } - - InitializeIfNeeded(); - } - - partial void OnAdded(T item) - { - if (!isInitialized || !IsSpawned) - { - return; - } - - InitializeIfNeeded(); - - if ((didOperation & DidOperationFlags.Add) != 0) - { - didOperation &= ~DidOperationFlags.Add; - return; - } - - if (!CanWrite) - { - throw new InvalidOperationException("Cannot add to the list. Client does not have write permission."); - } - - didOperation |= DidOperationFlags.Add; - networkList.Add(item); - SetDirty(true); - } - - partial void OnRemoved(int index, T item) - { - if (!isInitialized || !IsSpawned) - { - return; - } - - InitializeIfNeeded(); - - if ((didOperation & DidOperationFlags.Remove) != 0) - { - didOperation &= ~DidOperationFlags.Remove; - return; - } - - if (!CanWrite) - { - throw new InvalidOperationException("Cannot remove from the list. Client does not have write permission."); - } - - didOperation |= DidOperationFlags.Remove; - networkList.RemoveAt(index); - SetDirty(true); - } - - partial void OnInserted(int index, T item) - { - if (!isInitialized || !IsSpawned) - { - return; - } - - InitializeIfNeeded(); - - if ((didOperation & DidOperationFlags.Insert) != 0) - { - didOperation &= ~DidOperationFlags.Insert; - return; - } - - if (!CanWrite) - { - throw new InvalidOperationException("Cannot insert into the list. Client does not have write permission."); - } - - didOperation |= DidOperationFlags.Insert; - networkList.Insert(index, item); - SetDirty(true); - } - - partial void OnSet(int index, T oldItem, T newItem) - { - if (!isInitialized || !IsSpawned) - { - return; - } - - InitializeIfNeeded(); - - if ((didOperation & DidOperationFlags.Set) != 0) - { - didOperation &= ~DidOperationFlags.Set; - return; - } - - if (!CanWrite) - { - throw new InvalidOperationException("Cannot set the list item. Client does not have write permission."); - } - - didOperation |= DidOperationFlags.Set; - networkList[index] = newItem; - SetDirty(true); - } - - partial void OnCleared() - { - if (!isInitialized || !IsSpawned) - { - return; - } - - InitializeIfNeeded(); - - if ((didOperation & DidOperationFlags.Clear) != 0) - { - didOperation &= ~DidOperationFlags.Clear; - return; - } - - if (!CanWrite) - { - throw new InvalidOperationException("Cannot clear the list. Client does not have write permission."); - } - - didOperation |= DidOperationFlags.Clear; - networkList.Clear(); - SetDirty(true); - } - - private void OnNetworkListChanged(NetworkListEvent changeEvent) - { - switch (changeEvent.Type) - { - case NetworkListEvent.EventType.Add: - if ((didOperation & DidOperationFlags.Add) != 0) - { - didOperation &= ~DidOperationFlags.Add; - return; - } - - didOperation |= DidOperationFlags.Add; - targetList.Add(changeEvent.Value); - break; - case NetworkListEvent.EventType.Insert: - if ((didOperation & DidOperationFlags.Insert) != 0) - { - didOperation &= ~DidOperationFlags.Insert; - return; - } - - didOperation |= DidOperationFlags.Insert; - targetList.Insert(changeEvent.Index, changeEvent.Value); - break; - case NetworkListEvent.EventType.Remove: - if ((didOperation & DidOperationFlags.Remove) != 0) - { - didOperation &= ~DidOperationFlags.Remove; - return; - } - - didOperation |= DidOperationFlags.Remove; - targetList.Remove(changeEvent.Value); - break; - case NetworkListEvent.EventType.RemoveAt: - if ((didOperation & DidOperationFlags.RemoveAt) != 0) - { - didOperation &= ~DidOperationFlags.RemoveAt; - return; - } - - didOperation |= DidOperationFlags.RemoveAt; - targetList.RemoveAt(changeEvent.Index); - break; - case NetworkListEvent.EventType.Value: - if ((didOperation & DidOperationFlags.Set) != 0) - { - didOperation &= ~DidOperationFlags.Set; - return; - } - - didOperation |= DidOperationFlags.Set; - targetList[changeEvent.Index] = changeEvent.Value; - break; - case NetworkListEvent.EventType.Clear: - if ((didOperation & DidOperationFlags.Clear) != 0) - { - didOperation &= ~DidOperationFlags.Clear; - return; - } - - didOperation |= DidOperationFlags.Clear; - targetList.Clear(); - break; - case NetworkListEvent.EventType.Full: - if ((didOperation & DidOperationFlags.Clear) != 0) - { - didOperation &= ~DidOperationFlags.Clear; - return; - } - - didOperation |= DidOperationFlags.Clear; - targetList.Clear(); - for (int i = 0; i < networkList.Count; i++) - { - didOperation |= DidOperationFlags.Add; - targetList.Add(networkList[i]); - } - - break; - default: - throw new ArgumentOutOfRangeException(); - } - } - - public override void SetDirty(bool isDirty) - { - InitializeIfNeeded(); - - base.SetDirty(isDirty); - } - - public override void ResetDirty() - { - base.ResetDirty(); - networkList.ResetDirty(); - } - - public override void WriteDelta(FastBufferWriter writer) - { - if (!isInitialized) - { - return; - } - - InitializeIfNeeded(); - - networkList.WriteDelta(writer); - } - - public override void WriteField(FastBufferWriter writer) - { - if (!isInitialized) - { - return; - } - - InitializeIfNeeded(); - - networkList.WriteField(writer); - } - - public override void ReadField(FastBufferReader reader) - { - if (!isInitialized) - { - return; - } - - InitializeIfNeeded(); - - networkList.ReadField(reader); - // We're forcing the spawned state here because it will say it isn't spawned, but if we can read, it is spawned. - forceIsSpawned = true; - OnNetworkListChanged(new NetworkListEvent - { - Type = NetworkListEvent.EventType.Full, - Index = 0, - PreviousValue = default, - Value = default - }); - - forceIsSpawned = false; - } - - public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta) - { - if (!isInitialized) - { - return; - } - - InitializeIfNeeded(); - - networkList.ReadDelta(reader, keepDirtyDelta); - } - - public override void Dispose() - { - base.Dispose(); - - if (networkList != null) - { - networkList.OnListChanged -= OnNetworkListChanged; - networkList.Dispose(); - } - - DisposeTargetList(); - } - - private void InitializeIfNeeded() - { - if (hasInitializedNetworkList) - { - return; - } - - NetworkBehaviour behaviour = GetBehaviour(); - - if (behaviour == null) - { - return; - } - - networkList.Initialize(behaviour); - hasInitializedNetworkList = true; - } - } -} -#endif \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableList.NGO.cs.meta b/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableList.NGO.cs.meta deleted file mode 100644 index b220b35..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableList.NGO.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 318fbad2b0d9a7d46837dfab00b11eea -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableValue.NGO.cs b/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableValue.NGO.cs deleted file mode 100644 index 971e20d..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableValue.NGO.cs +++ /dev/null @@ -1,166 +0,0 @@ -#if (FISHNET || SCRIPTABLE_VALUES_NGO) -#define SCRIPTABLE_VALUES_NETWORKING -#endif - -#if SCRIPTABLE_VALUES_NETWORKING && SCRIPTABLE_VALUES_NGO -using System; -using Unity.Netcode; - -namespace Hertzole.ScriptableValues -{ - partial class SyncedScriptableValue : NetworkVariableBase - { - private bool hasInitializedNetworkVariable; - private bool didSet; - private bool forceIsSpawned; - - private NetworkVariable networkVariable; - - private bool IsSpawned - { - get { return GetBehaviour() != null && (forceIsSpawned || GetBehaviour().IsSpawned); } - } - - private bool CanWrite - { - get { return CanClientWrite(GetBehaviour().NetworkManager.LocalClientId); } - } - - public SyncedScriptableValue(NetworkVariableReadPermission readPerm = DefaultReadPerm, NetworkVariableWritePermission writePerm = DefaultWritePerm) - : base(readPerm, writePerm) - { - hasInitializedNetworkVariable = false; - } - - partial void OnInitialized() - { - networkVariable = new NetworkVariable(targetValue.Value, ReadPerm, WritePerm); - - InitializeIfNeeded(); - - if (IsSpawned && GetBehaviour().IsServer) - { - SetDirty(true); - } - } - - partial void OnValueChanging(T previousValue, T newValue) - { - if (!isInitialized || !IsSpawned) - { - return; - } - - InitializeIfNeeded(); - - if (didSet) - { - didSet = false; - return; - } - - if (!CanWrite) - { - throw new InvalidOperationException("Cannot change the value. Client does not have write permission."); - } - - didSet = true; - networkVariable.Value = newValue; - SetDirty(true); - } - - public override void SetDirty(bool isDirty) - { - InitializeIfNeeded(); - - base.SetDirty(isDirty); - } - - public override void WriteDelta(FastBufferWriter writer) - { - if (!isInitialized) - { - return; - } - - InitializeIfNeeded(); - - networkVariable.WriteDelta(writer); - didSet = false; - } - - public override void WriteField(FastBufferWriter writer) - { - if (!isInitialized) - { - return; - } - - InitializeIfNeeded(); - - networkVariable.WriteField(writer); - didSet = false; - } - - public override void ReadField(FastBufferReader reader) - { - if (!isInitialized) - { - return; - } - - InitializeIfNeeded(); - - networkVariable.ReadField(reader); - - didSet = true; - // We're forcing the spawned state here because it will say it isn't spawned, but if we can read, it is spawned. - forceIsSpawned = true; - targetValue.Value = networkVariable.Value; - forceIsSpawned = false; - } - - public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta) - { - if (!isInitialized) - { - return; - } - - InitializeIfNeeded(); - - networkVariable.ReadDelta(reader, keepDirtyDelta); - - didSet = true; - targetValue.Value = networkVariable.Value; - } - - public override void Dispose() - { - base.Dispose(); - - DisposeScriptableValue(); - - networkVariable?.Dispose(); - } - - private void InitializeIfNeeded() - { - if (hasInitializedNetworkVariable) - { - return; - } - - NetworkBehaviour behaviour = GetBehaviour(); - - if (behaviour == null) - { - return; - } - - networkVariable.Initialize(behaviour); - hasInitializedNetworkVariable = true; - } - } -} -#endif \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableValue.NGO.cs.meta b/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableValue.NGO.cs.meta deleted file mode 100644 index fa7266b..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/NGO/SyncedScriptableValue.NGO.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d04c36e72fe9f104cb88f46bfc8349db -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableDictionary.cs b/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableDictionary.cs deleted file mode 100644 index 69a1a1a..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableDictionary.cs +++ /dev/null @@ -1,49 +0,0 @@ -#if (FISHNET) -#define SCRIPTABLE_VALUES_NETWORKING -#endif - -#if SCRIPTABLE_VALUES_NETWORKING -using System; - -namespace Hertzole.ScriptableValues -{ - public sealed partial class SyncedScriptableDictionary : IDisposable - { - private ScriptableDictionary targetDictionary; - - public void Initialize(ScriptableDictionary dictionary) - { - targetDictionary = dictionary; - - dictionary.OnAdded += OnAdded; - dictionary.OnRemoved += OnRemoved; - dictionary.OnSet += OnSet; - dictionary.OnCleared += OnCleared; - - OnInitialized(); - } - - partial void OnAdded(TKey key, TValue value); - - partial void OnRemoved(TKey key, TValue value); - - partial void OnSet(TKey key, TValue oldValue, TValue newValue); - - partial void OnCleared(); - - partial void OnInitialized(); - - public void Dispose() - { - targetDictionary.OnAdded -= OnAdded; - targetDictionary.OnRemoved -= OnRemoved; - targetDictionary.OnSet -= OnSet; - targetDictionary.OnCleared -= OnCleared; - - OnDisposed(); - } - - partial void OnDisposed(); - } -} -#endif \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableDictionary.cs.meta b/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableDictionary.cs.meta deleted file mode 100644 index 56c5825..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableDictionary.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d52f1a28cc1d4865957d12d6f15cffec -timeCreated: 1686751058 \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableList.cs b/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableList.cs deleted file mode 100644 index d2a065b..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableList.cs +++ /dev/null @@ -1,74 +0,0 @@ -#if (FISHNET || SCRIPTABLE_VALUES_NGO) -#define SCRIPTABLE_VALUES_NETWORKING -#endif - -#if SCRIPTABLE_VALUES_NETWORKING -using System; -using Hertzole.ScriptableValues.Helpers; - -namespace Hertzole.ScriptableValues -{ - public sealed partial class SyncedScriptableList : IDisposable - { - private bool isInitialized; - - private ScriptableList targetList; - - [Flags] - private enum DidOperationFlags - { - None = 0, - Add = 1, - Insert = 2, - Set = 4, - Remove = 8, - RemoveAt = 16, - Clear = 32 - } - - public void Initialize(ScriptableList list) - { - ThrowHelper.ThrowIfNull(list, nameof(list)); - - targetList = list; - - targetList.OnAdded += OnAdded; - targetList.OnRemoved += OnRemoved; - targetList.OnInserted += OnInserted; - targetList.OnSet += OnSet; - targetList.OnCleared += OnCleared; - - isInitialized = true; - - OnInitialized(); - } - - partial void OnAdded(T item); - - partial void OnRemoved(int index, T item); - - partial void OnInserted(int index, T item); - - partial void OnSet(int index, T oldItem, T newItem); - - partial void OnCleared(); - - partial void OnInitialized(); - - private void DisposeTargetList() - { - if (targetList != null) - { - targetList.OnAdded -= OnAdded; - targetList.OnRemoved -= OnRemoved; - targetList.OnInserted -= OnInserted; - targetList.OnSet -= OnSet; - targetList.OnCleared -= OnCleared; - targetList = null; - } - - isInitialized = false; - } - } -} -#endif \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableList.cs.meta b/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableList.cs.meta deleted file mode 100644 index 3467b14..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableList.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 9ff877cd9031407eaef68e59e02cf8e4 -timeCreated: 1686689457 \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableValue.cs b/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableValue.cs deleted file mode 100644 index ff6ef82..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableValue.cs +++ /dev/null @@ -1,46 +0,0 @@ -#if (FISHNET || SCRIPTABLE_VALUES_NGO) -#define SCRIPTABLE_VALUES_NETWORKING -#endif - -#if SCRIPTABLE_VALUES_NETWORKING -using System; -using Hertzole.ScriptableValues.Helpers; - -namespace Hertzole.ScriptableValues -{ - public sealed partial class SyncedScriptableValue : IDisposable - { - private bool isInitialized; - - private ScriptableValue targetValue; - - public void Initialize(ScriptableValue value) - { - ThrowHelper.ThrowIfNull(value, nameof(value)); - - targetValue = value; - - targetValue.OnValueChanging += OnValueChanging; - - isInitialized = true; - - OnInitialized(); - } - - partial void OnInitialized(); - - partial void OnValueChanging(T previousValue, T newValue); - - private void DisposeScriptableValue() - { - if (targetValue != null) - { - targetValue.OnValueChanging -= OnValueChanging; - targetValue = null; - } - - isInitialized = false; - } - } -} -#endif \ No newline at end of file diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableValue.cs.meta b/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableValue.cs.meta deleted file mode 100644 index d2b6da1..0000000 --- a/Packages/se.hertzole.scriptable-values/Runtime/Networking/SyncedScriptableValue.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 907ef813093b4a5bb25b20fd8a318a6c -timeCreated: 1686686452 \ No newline at end of file diff --git a/README.md b/README.md index 4fa226f..493a381 100644 --- a/README.md +++ b/README.md @@ -320,7 +320,7 @@ public class ScriptableIntValuePool : ScriptableObjectPool ![Value reference](https://github.com/Hertzole/scriptable-values/assets/5569364/7fcc6a1e-3108-4df3-87c7-5ed5383abdc9) -Value reference is a special type that allows you you to pick in the inspector if you want a constant value in the inspector or a scriptable value reference (and even a addressable reference if you have addressables installed!). Meanwhile, in your code, you only interact with a single `Value` property and you don't need to care what type it is. +Value reference is a special type that allows you to pick in the inspector if you want a constant value in the inspector or a scriptable value reference (and even a addressable reference if you have addressables installed!). Meanwhile, in your code, you only interact with a single `Value` property and you don't need to care what type it is. #### Value Reference Usage @@ -337,100 +337,6 @@ public class PauseManager : MonoBehaviour } } ``` - -## 🌐 Networking Support - -You can automatically sync scriptable values, lists, and dictionaries over the network. All of the networking solutions follow the same setup. - -### FishNet -```cs -public ScriptableInt intValue; -public ScriptableIntList list; -public ScriptableIntDictionary dictionary; - -[SyncObject] -private readonly SyncedScriptableValue syncedInt = new SyncedScriptableValue(); -[SyncObject] -private readonly SyncedScriptableList syncedList = new SyncedScriptableList(); -[SyncObject] -private readonly SyncedScriptableDictionary syncedDictionary = new SyncedScriptableDictionary(); - -void Awake() -{ - // Always initialize the synced objects as early as possible! - syncedInt.Initialize(intValue); - syncedList.Initialize(list); - syncedDictionary.Initialize(dictionary); -} - -void OnDestroy() -{ - // It's important to dispose the synced objects when you're done with them! - syncedInt.Dispose(); - syncedList.Dispose(); - syncedDictionary.Dispose(); -} - -void OnEnable() -{ - // To listen to events, you always go to the source scriptable object. - intValue.OnValueChanged += OnIntValueChanged; -} - -void OnDisable() -{ - intValue.OnValueChanged -= OnIntValueChanged; -} - -void SetValue(int value) -{ - // To set a value, you always go to the source object. - // Only the server can set values. - intValue.Value = value; -} -``` - -### Netcode for GameObjects -```cs -public ScriptableInt intValue; -public ScriptableIntList list; -// Dictionary is currently not supported. - -private readonly SyncedScriptableValue syncedInt = new SyncedScriptableValue(); -private readonly SyncedScriptableList syncedList = new SyncedScriptableList(); - -void Awake() -{ - // Always initialize the synced objects as early as possible! - syncedInt.Initialize(intValue); - syncedList.Initialize(list); -} - -void OnDestroy() -{ - // It's important to dispose the synced objects when you're done with them! - syncedInt.Dispose(); - syncedList.Dispose(); -} - -void OnEnable() -{ - // To listen to events, you always go to the source scriptable object. - intValue.OnValueChanged += OnIntValueChanged; -} - -void OnDisable() -{ - intValue.OnValueChanged -= OnIntValueChanged; -} - -void SetValue(int value) -{ - // To set a value, you always go to the source object. - // Only the server can set values. - intValue.Value = value; -} -``` ## ♥ Support