sttz / trimmer

An editor, build and player configuration framework for the Unity game engine.
MIT License
104 stars 8 forks source link

Is there any other example of Options? #25

Open alijaya opened 1 year ago

alijaya commented 1 year ago

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 commented 1 year ago

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:

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:

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 commented 1 year ago

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.