Value Observer

Documentation for Value Observer v1.1

Introduction

Thanks for using Value Observer! Don't forget to leave a review on the store page if you liked it, this helps us a lot! https://assetstore.unity.com/packages/tools/utilities/value-observer-266922

You found the asset useful and want to support the development: https://www.buymeacoffee.com/infinitycode

Description

Value Observer is an editor-friendly implementation of the Observer pattern.

Contains: ValueObserver<T> - observes the value change and notifies listeners. Allows to validate the value change. LinkedObserver<T> - connects observer located in another component and allows to use it as a field of this class. LinkedValue<T> - connects any Serialized Property, Field or Property of any other component or Scriptable Object and allows it to be used as a field of this class. LinkedMethod<TResult> - connects any method that returns a value. Editor-friendly equivalent of Func<TResult>. Supports up to 10 parameters.

Advantages:

ValueObserver<T>

Observes the value change and notifies listeners. Allows to validate the value change.

Usage

  1. (Optional) If you are using Assembly Definitions, in Assembly Definition References add a reference to ValueObserver Assembly Definition.

  2. Add a namespace: using InfinityCode.Observers;

  3. Create the field:

    public ValueObserver<int> Health; Value Observer - Field

    Note: This is a generic class and you can use any type you want. But, keep in mind that this does not keep track of the internal state of the object and if any field of the object changes, it will not cause the listeners to be notified. Tip: You can easily see if the field has listeners by the color of the icon. If it is gray, then the field has no listeners. Otherwise it is yellow.

  4. Create a method that will listen for a change in value:

    public void OnHealthChanged(int newValue) { // Do Something }

    Note: The method must accept a new value of the generic type as a parameter.

  5. (Optional) Create a method that will validate the value:

    public void ValidateHealth(Validatable<int> health) { health.Value = Mathf.Clamp(health.Value, 0, 200); }

    Note: The method must accept as a parameter a validatable value of type Validatable<T>. You must assign a validated value to the Value field. The observer will check whether the value has changed and whether the listeners should be notified.

  6. Add listeners in the inspector: Value Observer - Listeners

    Note: You can have any number of listeners and validators. Listeners and validators can be in any component. Tip: If you want a listener or validator to work in edit mode, select Editor And Runtime mode.

API

Creating an Observer

// As a field public ValueObserver<int> observer;

// As a variable ValueObserver<int> observer = new ValueObserver<int>(20); ValueObserver<int> observer = new ValueObserver<int>(20, ChangedCallback);

Disposing

observer.Dispose();

Listeners

// Add observer += ChangedCallback; observer.AddListener(ChangedCallback);

// Remove observer -= ChangedCallback; observer.RemoveListener(ChangedCallback);

// Remove All observer.RemoveAllListeners();

// Notify observer.InvokeChanged();

Validations

// Add observer.AddValidation(ValidateInt);

// Remove observer.RemoveValidation(ValidateInt);

// Remove All observer.RemoveAllValidation();

Values

// Get int value = observer; int value = observer.Value;

// Set observer.Value = 30; observer.Set(30, false); // The second parameter specifies whether changing the value should notify the listeners.

// Compare if (observer == 30) {} if (observer.Value == 30) {}

LinkedObserver<T>

Connects observer located in another component and allows to use it as a field of this class.

Usage

  1. (Optional) If you are using Assembly Definitions, in Assembly Definition References add a reference to ValueObserver Assembly Definition.

  2. Add a namespace: using InfinityCode.Observers;

  3. Create the field:

    public LinkedObserver<int> LinkedHealth;

    Note: This is a generic class and you can use any type you want.

  4. In the inspector, specify the observer component and select the field:

    Linked Observer

  5. You can watch and change the value and listeners of the observer in the inspector.

  6. Work with the linked observer as a field of this class.

API

Creating an Observer

// As a field public LinkedObserver<int> observer;

// As a variable LinkedObserver<int> observer = new LinkedObserver<int>(this, "PropertyPath");

Where: Target is an Object containing the ValueObserver field. PropertyPath is the name of the serialized property. Note: This only supports properties at the top level. Properties at the second and subsequent levels (separated by a dot) are not supported.

Disposing

observer.Dispose();

Listeners

// Add observer += ChangedCallback; observer.AddListener(ChangedCallback);

// Remove observer -= ChangedCallback; observer.RemoveListener(ChangedCallback);

// Remove All observer.RemoveAllListeners();

// Notify observer.InvokeChanged();

Validations

// Add observer.AddValidation(ValidateInt);

// Remove observer.RemoveValidation(ValidateInt);

// Remove All observer.RemoveAllValidation();

Values

// Get int value = observer; int value = observer.Value;

// Set observer.Value = 30; observer.Set(30, false); // The second parameter specifies whether changing the value should notify the listeners.

// Compare if (observer == 30) {} if (observer.Value == 30) {}

LinkedValue<T>

Connects any Serialized Property of any other component or Scriptable Object and allows it to be used as a field of this class.

Usage

  1. (Optional) If you are using Assembly Definitions, in Assembly Definition References add a reference to ValueObserver Assembly Definition.

  2. Add a namespace: using InfinityCode.Observers;

  3. Create the field:

    public LinkedValue<int> MaxHealth;

    Note: This is a generic class and you can use any type you want.

  4. In the inspector, specify the value component and select the Serialized Property:

    Linked Value

  5. You can watch and change the value in the inspector.

  6. Work with the linked value as a field of this class.

Observation of Changes in Value

Observing LinkedValue

You can watch the Linked Values change. To do this you need to call the StartObserving field method in play mode, and pass it a reference to a MonoBehaviour that will start the coroutine to observe the change. Coroutine will check for a change in value once per frame and notify listeners when the value has changed.

 

API

Creating Linked Value

// As a field public LinkedValue<int> linkedValue;

// As a variable LinkedValue<int> linkedValue = new LinkedValue<int>(this, "PropertyPath");

Where: Target is an Object containing the serialized property. PropertyPath is the name of the serialized property. Note: This only supports properties at the top level. Properties at the second and subsequent levels (separated by a dot) are not supported.

Disposing

linkedValue.Dispose();

Listeners

// Start Observing linkedValue.StartObserving(this); // where "this" is the current MonoBehaviour

// Stop Observing linkedValue.StopObserving(this); // where "this" is MonoBehaviour that was used to start observing.

// Add linkedValue += ChangedCallback; linkedValue.AddListener(ChangedCallback);

// Remove linkedValue -= ChangedCallback; linkedValue.RemoveListener(ChangedCallback);

// Remove All linkedValue.RemoveAllListeners();

// Notify linkedValue.InvokeChanged();

Values

// Get int value = linkedValue; int value = linkedValue.Value;

// Set linkedValue.Value = 30;

// Compare if (linkedValue == 30) {} if (linkedValue.Value == 30) {}

// Check for changes if (linkedValue.IsChanged) {}

Tips

Performance

Linked Value uses reflection to get the value, and when you need to use the value multiple times in a method, store it in a local variable.

Exceptions

By default, when you try to get a Linked Value that is not configured or not found, you will only get a message in the console. If you want it to throw an exception, set the static flag LinkedValue.ThrowExceptions = true;

LinkedMethod<TResult>

Connects any method that returns a value. Editor-friendly equivalent of Func<TResult>. Supports up to 10 parameters. Should be used instead of UnityEvent<T> when you need to get the result of a method execution.

Usage

  1. (Optional) If you are using Assembly Definitions, in Assembly Definition References add a reference to ValueObserver Assembly Definition.

  2. Add a namespace: using InfinityCode.Observers;

  3. Create the field: public LinkedMethod<int, string> GetPlayerName; // Takes a value of int type as a parameter, and returns a value of string type.

    Note: This is a generic class and you can use any types you want. Important: the return value type is always the last generic argument.

  4. In the inspector, specify the component and select the method name: LinkedMethod

  5. Call LinkedMethod using Invoke: string playerName = GetPlayerName.Invoke(3);

API

Creating LinkedMethod

// As a field public LinkedMethod<int, string> linkedMethod;

// As a variable LinkedMethod<int, string> linkedMethod = new LinkedMethod<int, string>(this, "MethodName");

Where: Target is an Object containing the method. MethodName is the name of the serialized property.

Disposing

linkedMethod.Dispose();

Invoking

string result = linkedMethod.Invoke(5);

Tips

Return multiple values

When a method must return two or more values, use tuples: public LinkedMethod<float, (int, int)> SomeMethod;

public (int, int) SomeMethodImpl(float a) { // Implementation }

Exceptions

By default, when you try to invoke a LinkedMethod that is not configured or not found, you will only get a message in the console. If you want it to throw an exception, set the static flag LinkedMethod.ThrowExceptions = true;

Troubleshooting

Known Issues

Your script does not see InfinityCode.Observers namespace. If you are using Assembly Definitions, in Assembly Definition References add a reference to ValueObserver Assembly Definition.

Changing a class or structure field does not notify listeners. By Design. Value Observer monitors changes to a value, not its internal fields.

Listeners or validators do not work in edit mode. To make it work in edit mode, select Editor And Runtime mode.

Your problem is not listed

Try to update to the latest version of the asset. Perhaps we have already fixed this problem.

If the problem persists, please contact us about this problem using email (support@infinity-code.com), discord (https://discord.gg/2XRWwPgZK4) or forum (http://forum.infinity-code.com). We will try to fix all bugs and release the update as soon as possible.

Support

We provide support using email (support@infinity-code.com) in English and Russian, or using discord (https://discord.gg/2XRWwPgZK4) and forum (https://forum.infinity-code.com) in English.

If something does not work for you, you have found a bug, or you have a suggestion, please contact to us. When contacting, please specify your OS, the version of Unity Editor and the version of Value Observer. We try to respond to all request to the support within 24 hours.

Other Infinity Code assets

Huge Texture

Huge Texture

https://assetstore.unity.com/packages/tools/input-management/huge-texture-163576

Huge Texture allows you to import and use textures larger than 8192x8192px.

How it works: When importing a texture, Huge Texture splits the texture into pages and saves it as a Texture Array. Texture Array is combined on the shader side, which does not create extra draw calls and has almost no effect on performance.

Features:

Requirements:

Mesh to Terrain

Mesh to Terrain

https://assetstore.unity.com/packages/tools/terrain/mesh-to-terrain-7271

Mesh to Terrain is a tool for easily and quickly converting a 3D terrain model created in 3ds Max, Terragen or any other editor to Unity Terrains. Mesh to Terrain can convert textures to SplatPrototypes (Terrain Layers), generate terrain from several models and split the model into several terrains.

Features:

Online Maps

Online Maps

https://assetstore.unity.com/packages/tools/integration/online-maps-v3-138509

Online Maps is a universal multi-platform mapping solution for your 2D, 3D, AR / VR and mobile applications and games.

Fully customizable, incredibly easy to learn and use, and at the same time is one of the most powerful and flexible solutions in the industry.

Supports a huge number of services for any mapping needs, and has integration with the best Asset Store assets.

The package contains the complete source code without dependencies, and if you want to add or change some feature, you can easily do it.

Don't have programming experience or don't know C# - Online Maps supports visual scripting using Bolt and Playmaker.

All the features to create any map in Unity in one asset.

Features:

Project Context Actions

Project Context Actions

https://assetstore.unity.com/packages/tools/utilities/project-context-actions-267429

Project Context Actions is a standalone free toolkit from Ultimate Editor Enhancer asset that speeds up work with the Project window by adding contextual actions based on item type.

Supports one-column and two-column layouts.

Context actions are displayed when you hover over a row or cell in the project that matches certain criteria.

List of actions:

Real World Terrain

Real World Terrain

https://assetstore.unity.com/packages/tools/terrain/real-world-terrain-8752

Real World Terrain is a tool for automatically creating high-quality terrains, meshes, Gaia stamps and RAW files based on real-world data with global coverage. Incredibly fast and easy to use, and allows you to create high-quality terrains in a couple of clicks. In addition, Real World Terrain can create buildings, roads, trees, grass, and rivers based on Open Street Map data. Real World Terrain is incredibly powerful and flexible. It has a powerful Editor API to automate the generation of terrains, and Runtime API positioning objects by coordinates, etc. Real World Terrain has integration with the best assets of the Asset Store, which gives almost unlimited possibilities in the generation of terrains.

Features:

Run Desired Scene

Run Desired Scene

https://assetstore.unity.com/packages/tools/utilities/run-desired-scene-262762

Run Desired Scene is a very powerful and easy to use tool that allows you to start playing from any scene without opening it. After exiting play mode, you will return to the scenes open for editing.

Features:

Terrain Quality Manager

Terrain Quality Manager

https://assetstore.unity.com/packages/tools/terrain/terrain-quality-manager-28949

Terrain Quality Manager allows you to change the resolution of Heightmap, Detailmap, Alphamap and Basemap, without losing data. If you need to increase the quality of terrain, or optimize terrain for better performance, with this tool you can do it.

Features:

Tiny Terrain

Tiny Terrain

https://assetstore.unity.com/packages/tools/terrain/tiny-terrain-236464

Tiny Terrain is a lossy Terrain Data compression technology for Unity Terrain Engine, which allows you to reduce the size of the data that Terrain takes in the project many times and significantly reduce the size of your application. You pay a little CPU time and additional memory usage, but save tens and hundreds of megabytes for each Terrain in the project. Even though the compression is lossy, in most cases you won't see any visual difference at all. A very high compression ratio is achieved due to the author's data preparation algorithms and then compression using Brotli. Even if your build or AssetBundle is already compressed using LZ4, LZ4HC or LZMA, Tiny Terrain will be able to reduce its size. Of course the difference in size won't be as huge as with the uncompressed data, but it's still pretty big.

The asset has highly optimized code using direct memory access, which allows for fast compression and decompression, and minimizes additional memory usage. On average, one Terrain is loaded in about 1 second. Tiny Terrain is not a 3rd party Terrain Engine, and you can use Unity Terrain API and any terrain tools you like, such as Real World Terrain, Gaia, Vegetation Studio, etc.

Using Tiny Terrain is very easy, and anyone can do it, even if it is their first day using Unity. Just add Tiny Terrain Loader component to Terrain and click Compress. If you are an advanced user or programmer, Tiny Terrain has events and API that will help you take full control of the loading process.

Features:

Platforms: The asset was tested on PC, Mac, Android, iOS, WebGL. The rest of the platforms have not been tested, but the asset should also work well on them.

Tree Tool

Tree Tool

https://assetstore.unity.com/packages/tools/terrain/tree-tool-221137

Tree Tool allows you to manage each tree individually.

Using this tool, you can perform the following actions on trees:

 

In addition, the tool can perform the following mass actions:

 

Tree Tool is compatible with all assets that create trees for Terrain.

Ultimate Editor Enhancer

Ultimate Editor Enhancer

https://assetstore.unity.com/packages/tools/utilities/ultimate-editor-enhancer-141831

Ultimate Editor Enhancer (ex uContext Pro) is productivity PowerPack that take your workflow in Unity Editor to a next level, simplifies working with content, adds new features to the editor, corrects and improves the editor’s built-in behaviors.

Dramatically improves Hierarchy, Inspector, Scene View and the editor itself.

Adds tools for quick navigation, creation and manipulation of objects.

 

Key Features:

List of tools:

 

uPano

uPano

https://assetstore.unity.com/packages/tools/integration/upano-126396

uPano (Unity Panoramic Framework) is a universal solution for displaying dynamic and static panoramas, and creating virtual tours. uPano is very easy to learn and use, and is great for people who do not have programming experience. Visual Tour Maker lets you create virtual tours in minutes. In most usage scenarios, you can make interactive panoramas without creating your own scripts. If you have some very specific purpose, uPano has a powerful and easy-to-use API that will allow you to implement any behavior. Most of the existing types of panoramas are supported: spherical, cylindrical, cubic panoramas on single or six images, cubemap.

Supported platforms: Standalone, iOS, Android (including Google VR), Universal Windows Platform, WebGL. Other platforms have not been tested, but most likely uPano will work well.

Additional features:

Final words

We sincerely hope that you enjoy using Value Observer. If you have any questions or problems, please contact us. We will try to help you as quickly as possible.

Please don't forget to leave a review on the store page if you liked Value Observer, this helps us a lot! It is very important for us to have feedback to make our assets better.

Links

Product page: https://infinity-code.com/assets/value-observer Asset Store: https://assetstore.unity.com/packages/tools/utilities/value-observer-266922 Support: support@infinity-code.com Discord: https://discord.gg/2XRWwPgZK4 Forum: https://forum.infinity-code.com YouTube: https://www.youtube.com/playlist?list=PL2QU1uhBMew8FmZlbXr-SqILgAKXjzUpU Twitter: https://twitter.com/InfinityCodeCom