Comments (3)
On second thought, maybe instead we don't allow Variable.Value
to get modified via the Value
property, forcing users to modify the value via a FloatVariable
.
This will allow other scripts that use the FloatVariable
to see the changes.
The property can be changed to this:
public float Value
{
get { return UseConstant ? ConstantValue : Variable.Value; }
set
{
if (!UseConstant)
// maybe Debug.LogError here to warn devs?
else
ConstantValue = value;
}
}
from unite2017.
Sorry, I'm not the maintainer; but I got a notification, and it occurred to me to mention that I also extended the solution in this repo with differentiated read-only and writeable classes, and a lot of other features. :) If you want, you can look into it as a possible implementation.
For example this is a writeable float property, which extends the basic concrete read-only class, which is further derived from a generic abstract base class GameProperty<T>
that exposes a protected setter method which takes care of propagating the changed value to subscribers:
I also ended up differentiating 'properties' and 'events', because in my use I realized that a lot of times all I want is to push a notification to a component with a certain payload, without having an initial value set. But possibly there were other reasons too; I can't quite remember because it was ages ago. :)
from unite2017.
@baratgabor I see. I do think that creating separate read-only and writeable classes is a good solution because you have a choice on whether modifications are allowed. Thanks for showing me!
from unite2017.
Related Issues (11)
- Add a license HOT 2
- #ifdef UNITY_EDITOR on serialized property HOT 1
- FloatReferenceDrawer no longer works HOT 4
- Inventory Demo HOT 3
- Handling multiple instances of objects (ie PlayerHealth, but multiple player's) HOT 3
- Persistence (saving data) HOT 1
- Wouldn't source control be spammed with unnecessary changes caused by persistant scriptable assets being modified at run time? HOT 1
- ScriptableObjectsEvents on build, Android not working. HOT 4
- Type mismatch in Demo05_Sets HOT 4
- Event send an arg HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unite2017.