Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any other example of Options? #25

Open
alijaya opened this issue Oct 16, 2023 · 2 comments
Open

Is there any other example of Options? #25

alijaya opened this issue Oct 16, 2023 · 2 comments

Comments

@alijaya
Copy link

alijaya commented Oct 16, 2023

Hello, to be honest, the documentation is a little bit confusing. What is the difference between Option and Feature?
And what is the use case of it? Do you have more example (in code)?

@sttz
Copy link
Owner

sttz commented Oct 17, 2023

The Options and Features section in the documentation tries to explain it and gives some examples.

But it ultimately comes down to how an Option is implement and what exactly it's configuring, so it can be difficult to pin it down exactly. There are different types of Options and they each might define what exactly their Feature is in a different way.

On a technical level:

  • Options are the Trimmer classes used for configuring aspects of your project. Depending on the Build Profile used, they can be completely compiled out of the build when excluded.
  • A Feature is an additional flag associated with each root Option in a Build Profile. When the Feature is included, an additional conditional compilation define is set – but otherwise it's up to the Option to decide how to handle the Feature flag.

The basic idea is that there can be two separate things that can be in-/excluded in builds: The Option that allows changing the configuration but also the thing itself that the Option is configuring.

Maybe explaining the different possible combination helps:

  • Option and Feature included: The functionality is in the build and can be configured at runtime using the Option
  • Option excluded and Feature included: The functionality is in the build but the configuration of the Option is applied when building and cannot be changed at runtime
  • Feature excluded: The functionality is removed from the build (including the Option doesn't make sense here)

Some Options might inject a Feature (there are methods on OptionHelper to help implement this), actively remove it when building (e.g. using PostprocessScene, changing the scenes list, not setting conditional compilation defines, etc) or not have a Feature at all (by not setting HasAssociatedFeature in its capabilities attribute). It really depends on what you want to configure with Trimmer and how you prefer to implement it.

For examples, check out the Options included in Trimmer: https://github.com/sttz/trimmer/tree/master/Options

@alijaya
Copy link
Author

alijaya commented Oct 17, 2023

Uhhh... I'm still confused by this...

What should I do if I have this case:
I want some ScriptableObject change it's value depending on which build that I want to do.
For example, the ScriptableObject has a string field, let's call it "text", and for the "Development" build, I want it to be changed to "dev", and for the "Demo" build, I want it to be changed to "demo".

What should I do in this case?
I guess this one should not have Option, because it's supposed to be not changed during runtime. So for the capabilities, I should not include CanIncludeOption, is that right?
Actually side note: I've read that the documentation says that we can change the Option during runtime, but I'm still not sure how.

Then I want it to takes effect when I go to play mode, so I could inspect what is the behaviour when I build it. So I guess, I should include CanPlayInEditor, and do the function with overriding Apply.

Because I want it change the ScriptableObject before building, I guess I should hook the PrepareBuild, and I need ConfiguresBuild, so it will call when it builds.

But how can I configure to execute PrepareBuild or not? Because it seems, it's always called.
And the same thing with the PlayMode, Apply is always called, and it seems I can't disable it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants