Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/javier-games/upm-propertyrefs
PropertyRef allows you to create shortcuts to the values of a prefab and modify them.
https://github.com/javier-games/upm-propertyrefs
Last synced: about 1 month ago
JSON representation
PropertyRef allows you to create shortcuts to the values of a prefab and modify them.
- Host: GitHub
- URL: https://github.com/javier-games/upm-propertyrefs
- Owner: javier-games
- License: mit
- Created: 2023-05-28T07:08:35.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-01T07:45:18.000Z (about 2 months ago)
- Last Synced: 2024-11-01T08:19:09.871Z (about 2 months ago)
- Language: C#
- Size: 20.7 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![GitHub](https://img.shields.io/badge/GitHub-181717?logo=github&logoColor=fff)](https://github.com/javier-games/upm-propertyrefs)
[![Itch.io](https://img.shields.io/badge/itch.io-FA5C5C?logo=Itch.io&logoColor=fff)](https://javier-games.itch.io/propertyrefs)
[![npm](https://img.shields.io/badge/npm-CB3837?logo=npm&logoColor=fff)](https://www.npmjs.com/package/games.javier.upm.propertyrefs)
[![OpenUPM](https://img.shields.io/badge/OpenUPM-3A6CE2.svg?logo=data:image/svg%2bxml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+Cjxzdmcgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDI1NiAyNTYiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6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w5MkwxMCwxMjRMNTgsMTA3TC00Myw3OEwtODksOTJaTTEwNSw5NkwxMTgsOTJMMTA1LDg4TDEwNSw5NlpNMy42MjUsNTAuNjI1QzEuODAxLDUyLjk0OCAxLjgwMSw1Mi45NDggMS40MzgsNTZDMS43NjUsNTkuMTQ2IDEuNzY1LDU5LjE0NiA0LjEyNSw2MS40MzhDNi45MTIsNjMuMjQ5IDYuOTEyLDYzLjI0OSAxMC4xMjUsNjNDMTMuMDIyLDYyLjE5MyAxMy4wMjIsNjIuMTkzIDE0LjkzOCw2MC4zMTNDMTYuNDAxLDU3LjEyNyAxNS45ODksNTUuMzIxIDE1LDUyQzEzLjkzNyw1MC4wMiAxMy45MzcsNTAuMDIgMTIsNDlDOC4zNyw0OC40NTkgNi42NzgsNDguNTM2IDMuNjI1LDUwLjYyNVoiIHN0eWxlPSJmaWxsOndoaXRlOyIvPgogICAgPC9nPgo8L3N2Zz4=)](https://openupm.com/packages/games.javier.upm.propertyrefs)# PropertyRefs
PropertyRefs is an open source tool for Unity, crafted to streamline your game development tasks. By creating references to the properties of the components, you can efficiently access and manipulate them from other scripts, centralizing meaningful properties of a game object, prefab, or a scene in one location. This is a significant advantage for game and level designers, offering an enhanced and seamless workflow.
## Features
### Access from Editor
With a custom property drawer, PropertyRefs provides an intuitive interface for gathering all significant properties in one place. This not only eliminates the tedious search through countless properties but also promotes a cleaner, more organized codebase.
### Access from Code
Developers have the flexibility to modify the values of the PropertyRefs programmatically. For more information on how to access and modify properties programmatically, please refer to the [Property Access Methods](#property-access-methods) section.
### AOT Systems Support
PropertyRefs is equipped with a dual-mode functionality. Initially, it uses System Reflection to access the values of component properties. However, for AOT systems, where System Reflection is not applicable, PropertyRefs seamlessly switches to a Roslyn Source Generator. For more details on how AOT systems are supported, please see the [AOT Systems Support and Code Generation](#aot-systems-support-and-code-generation) section.
## Requirements
The PropertyRefs package is currently supported on `Unity 2021.3.17f1`. Usage in other versions of Unity may result in unexpected behavior. Please ensure your Unity environment meets this requirement before installation to guarantee the package's optimal functionality.
## Installation
There are several methods available to install PropertyRefs into your Unity project. Choose the one that best suits your needs. It's recommended to install via npm if you wish to keep the package up-to-date easily, as future releases and updates will be readily available.
- **Package Name:**
```
games.javier.upm.propertyrefs
```
- **Display Package Name:**
```
Javier Games
```
- **NPM Registry URL:**
```
https://registry.npmjs.org
```
- **Scope(s):**
```
games.javier
```
- **OpenUPM CI command**
```
openupm add games.javier.upm.propertyrefs
```
This package is being distributed on [npm](https://www.npmjs.com/package/games.javier.upm.propertyrefs), [OpenUPM](https://openupm.com/packages/games.javier.upm.propertyrefs) or a downloadable Tarball from the [Releases section](https://github.com/javier-games/propertyrefs/releases) of this repository or from the dedicated [itch.io page](https://javier-games.itch.io/propertyrefs). For detailed installation instructions, please refer to the guide on our [installation documentation page](https://installation.upm.javier.games).## Usage
PropertyRefs is designed with an intuitive interface to ensure a seamless and user-friendly experience. To use PropertyRefs in your projects, follow the general usage instructions below:
### General Usage
To establish a reference to the properties of your components, declare a private `SerializedProperty` or a public field of `PropertyRef` type in a custom class. Once declared, the Inspector will allow you to select the component and the property for the reference.
```csharp
using System.Collections.Generic;
using UnityEngine;
using JG.UPM.PropertyRefs;public class PrefabProperties : MonoBehaviour
{
[SerializeField]
private PropertyRef myPropertyRef;
[SerializeField]
private List myListOfProperties;
}
```You can also declare a list of `PropertyRef` instances. In this mode, PropertyRefs conveniently labels the properties in the list with the name of the game object and the property. This labeling facilitates easier identification of properties.
### Property Access Methods
To ensure that a newly created component's properties are identifiable by PropertyRefs, the properties must be declared with read and write access. If a property lacks read and write access, PropertyRefs won't be able to identify it.
```csharp
using UnityEngine;public class CustomComponent : MonoBehaviour
{
public float MyFindableProperty { get; set; }
}
```Moreover, PropertyRefs enables you to modify and obtain the value of the `PropertyRef` programmatically. However, caution is advised as this option doesn't recommend the assignment of values that are of a different type to the `PropertyRef`. If such an assignment occurs, the value of the `PropertyRef` will remain unchanged.
```csharp
using UnityEngine;
using JG.UPM.PropertyRefs;public class EditableProperty : MonoBehaviour
{
[SerializeField]
private PropertyRef myEditablePropertyRef;private void Start()
{
var value = (float) myEditablePropertyRef.GetValue();
Debug.Log($"My value is {value}");value += 5;
myEditablePropertyRef.SetValue(value);
Debug.Log($"My new value is {value}");
}
}
```### AOT Systems Support and Code Generation
PropertyRefs includes a built-in Roslyn source generator for supporting Ahead-Of-Time (AOT) systems, like iOS. To activate this feature, locate a `Registry.PropertyRefsSourceGenerator.additionalfile` file somewhere in your project. This file serves as a registry for the properties you can use.
When a component or a property that isn't registered is assigned to a `PropertyRef`, it will display an option for you to register them. This ensures that your AOT system is fully supported and that your property references are generated correctly. The JSON file below is a sample of how the registry is conformed.
```json
{
"components": [
{
"type": "UnityEngine.Transform",
"properties": [
{
"name": "position",
"type": "UnityEngine.Vector3"
}
]
}
]
}
```With these features and flexible options, PropertyRefs aims to enhance your Unity development experience, offering an enhanced and seamless workflow.
## License
PropertyRefs is available under the MIT license. See the [LICENSE](LICENSE) file for more info.
## Contribution
Please read our [Contributing Guide](CONTRIBUTING.md) before submitting a Pull Request to the project.
## Support
For any questions or issues, please open a [new issue](https://github.com/javier-games/upm-propertyrefs/issues/new) on this repository.
## Acknowledgements
We would like to express our gratitude to [Kenney](https://www.kenney.nl) for providing the assets used to create the samples and images in this repository. These models are under the Creative Commons Zero (CC0) license.