Publisher | ByteCobra |
---|---|
File size | 207.89kB |
Number of files | 59 |
Latest version | 2 |
Latest release date | 2023-09-11 10:57:55 |
First release date | 2023-01-02 02:24:11 |
Supported Unity versions | 2018.4.2 or higher |
Introducing the Observed - a collection of scripts that allows you to easily create observable variables, observable collections, and observable dictionaries in your Unity projects.
This version is without the source code, if you need access to the full source code check out the source version here.
Well Tested
As the developer of the Observed asset, I have put in a great deal of effort to ensure its reliability and robustness. I have created over 100 unit tests to cover a variety of scenarios and conditions, so you can trust that the observable variables and collections in the Observed asset will perform consistently and smoothly in your Unity projects.
Use Cases
Here are a few practical applications for some of the classes that are included in this asset:
Tracking Player Scores and Level Progress
Message Queue System For Multiplayer Networking
Observed<T>
Observed variables are variables that can notify subscribers when their value changes. This can be useful in game development for tracking and responding to changes in various game states or variables.
For example, an observed variable could be used to track the player's health, the progress of a loading screen, or the score of a game. Subscribers can be set up to listen for changes to the observed variable and take some action in response, such as updating a UI element or triggering some other event.
ObservedCollection<T>
ObservedCollection is a collection that can notify subscribers when its contents change, allowing you to track changes to the collection and respond to them in your code. Examples of how you might use ObservedCollection in game development include using it to track the state of a list of items in a UI or inventory system, subscribing to changes in an observed collection to update a UI or other system when the collection changes, using the ObservedCollection class's built-in methods such as Add, Remove, and Clear to manipulate the collection and automatically notify subscribers of changes, and iterating over the collection and accessing its items using the foreach loop or LINQ methods, just like you would with a regular collection.
ObservedDictionary<T>
ObservedDictionary is a class that allows users to subscribe to changes made to the dictionary. This can be useful in scenarios where the user wants to be notified when an item is added, removed, or updated in the dictionary.
ObservedQueue<T>
ObservedQueue is a queue that can notify subscribers when its contents change, allowing you to track changes to the queue and respond to them in your code.
A queue is a linear data structure that follows the "first-in, first-out" (FIFO) principle. It is a collection of elements in which the addition of new elements happens at the back of the queue, and the removal of existing elements occurs at the front of the queue. This makes a queue a useful data structure for tasks that need to be processed in the order that they are received.
In game development, queues can be useful for tasks such as managing the order in which units move in a turn-based game, processing events in the order that they are received, or managing a list of actions that need to be performed in a specific order. Queues can also be used to store data temporarily before it is processed, such as incoming network packets in an online game.
ObservedSet<T>
ObservedSet is a set that can notify subscribers when its contents change, allowing you to track changes to the set and respond to them in your code.
A set is a collection of unique items, meaning that it does not allow for duplicates. Sets can be useful for game development in a variety of situations where uniqueness is important, such as tracking unique items in an inventory or unique player IDs in a multiplayer game. Sets can also be useful for quickly checking if an item is already present in the collection, as they typically have fast lookup times due to their use of hashing.
ObservedHashSet<T>
ObservedHashSet is a class that extends the .NET System.Collections.Generic.HashSet<T> class and adds the ability to notify subscribers when the set is modified. This can be useful if you want to track changes to the set and have other parts of your code respond to these changes.
Like a regular hashset, ObservedHashSet is a collection of unique items that does not allow for duplicates. It uses hashing to provide fast lookup times for checking if an item is present in the set. In addition to the standard methods provided by the HashSet class, such as Add, Remove, and Clear, ObservedHashSet also includes methods for subscribing and unsubscribing to notifications of set changes, as well as methods for clearing subscriptions and notifying subscribers of added and removed items.
ObservedHashSet can be useful for game development in a variety of situations where uniqueness is important, such as tracking unique items in an inventory or unique player IDs in a multiplayer game. It can also be useful for quickly checking if an item is already present in the set and for responding to changes in the set in other parts of your code.
ObservedBitArray
An observed bitarray is a class that wraps a regular .NET System.Collections.BitArray and adds the ability to notify subscribers when the bitarray is modified. This can be useful if you want to track changes to the bitarray and have other parts of your code respond to these changes. Overall, the main benefit of using an observed bitarray is that it provides a convenient way to track and respond to changes in a bitarray, which can be useful for various purposes in game development.
One possible use case for an observed bitarray is to track the state of various game options or settings. For example, you could use an observed bitarray to track which options in a menu are selected, which achievements have been unlocked, or which leaderboard scores have been achieved.
It could also be used for optimizing online games to reduce the amount of data that is sent over the network. If you are using a BitArray to represent a state that needs to be synchronized between clients and the server in an online game, using ObservedBitArray would allow you to easily track and send changes to the bit array over the network.
ObservedSortedList<TKey, TValue>
ObservedSortedList is a class that allows users to subscribe to changes made to a SortedList, a collection that stores key-value pairs in a sorted order according to the keys. This can be useful in scenarios where the user wants to be notified when an item is added, removed, or updated in the SortedList. The ObservedSortedList class provides a convenient way to track and respond to changes in a SortedList, which can be useful for various purposes in game development.
One possible use case for ObservedSortedList is to track the state of various game objects or UI elements in a sorted manner. For example, if you have a sorted list of enemies in a game, you could use ObservedSortedList to track the health, position, or other properties of each enemy and have other parts of your code respond to these changes. This could be useful for implementing game mechanics such as spawning new enemies, updating the AI of enemies, or displaying the status of enemies in a UI.
ObservedSortedSet<T>
A sorted set is a collection of items that are stored in a specific order, based on their value. Sorted sets are useful for scenarios where you need to store items in a specific order and quickly retrieve items based on their value.
It has all the same functionality as a regular sorted set, but it also has the ability to notify subscribers of changes made to the set through the Subscribe and Unsubscribe methods.
ObservedSortedDictionary<TKey, TValue>
ObservedSortedDictionary is a class that extends the .NET SortedDictionary class to add the ability to notify subscribers when the dictionary is modified. This can be useful if you want to track changes to the dictionary and have other parts of your code respond to these changes. ObservedSortedDictionary is particularly useful when you need a dictionary that is always sorted based on its keys, as it provides a convenient way to track and respond to changes in a sorted dictionary, which can be useful for various purposes in game development.
ObservedSortedDictionary can be used to store data that needs to be accessed in a specific order, such as high scores or other ordered lists of data.
ObservedStack<T>
ObservedStack is a stack implementation that allows you to subscribe to changes made to the stack. When an item is added or removed from the stack, all subscribed callbacks are notified with the item and a ChangeType indicating whether the item was added or removed.
They can be useful for implementing features such as leaderboards or ranking systems, where the order of the items is important.
ObservedBinaryFile
The ObservedBinaryFile class allows you to subscribe to file change events for a specific file. It monitors the file for changes, and notifies subscribers when the file is changed, created, deleted, moved, or renamed.
ObservedTextFile
The ObservedTextFile class allows you to subscribe to file change events for a specific text file. It monitors the file for changes, and notifies subscribers when the file is changed, created, deleted, moved, or renamed.
Upgrade your Unity projects with the power of observables - try the Observed asset today!