Giter Club home page Giter Club logo

Comments (3)

Brandon-Gui123 avatar Brandon-Gui123 commented on June 20, 2024

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.

baratgabor avatar baratgabor commented on June 20, 2024

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:

https://github.com/baratgabor/Unity3D-ReactiveScriptables/blob/master/ScriptableObjects/Properties/FloatProperty_Writeable.cs

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.

Brandon-Gui123 avatar Brandon-Gui123 commented on June 20, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.