- Home /
how to apply same fields for objects with different script but inherit same class Unity C#
i have lots of classess who inherit BaseIsland (more then 20) each of classess have prefab and i wonna to fill a lot of fields with same value for each of them. but some of values type are like AnimationCurve some fields are with types of transform so how can i apply same Value to all of them?
probably i can create some object fill all fields and somehow using reflexion get these fields from that object and set these fields to each of them
Probably a custom Editor script or EditorWindow could help filling in the same values, but I'm not sure what functions to use exactly or how much effort it would be. I'm sorry that I cannot be more specific.
One idea I have for this is that you create a custom EditorWindow (for example BaseIslandEditorWindow) which has fields for the values that you want to assign to all of your prefabs. Then you have button on it, which when pressed checks all the selected game objects ( Selection.gameObjects
), and the ones that have BaseIsland
component on them will get the values specified in the fields copied to them.
A different possible solution (but more work upfront) would be to move towards a data driven approach: you could move all the configuration data of a BaseIsland
into a class derived from ScriptableObject
, e.g. BaseIslandData
, and use the values in it to set it up. Then you create data assets from BaseIslandData
instances and just assign them to the different prefabs that have a script deriving from BaseIsland
.
Answer by madks13 · Jul 19, 2018 at 02:27 PM
If you have same values, use static properties.
You cannot assign values to static properties from the Editor, which I think yaroslav_ wants to have.
True, there it is not said explicitly, but AnimationCurve is mentioned, which is usually defined from the Editor (it is possible from code, but it is cumbersome and beats the purpose). I guess @yaroslav_ can tell us.
Your answer
Follow this Question
Related Questions
Building a Collection of Subclasses and Modifying Their Public Members from the Inspector 0 Answers
Get all inherited classes of an abstract class - Editor Scripting 1 Answer
I need an Array of System.type[] from all of my ScriptableObjects scripts 0 Answers
An OS design issue: File types associated with their appropriate programs 1 Answer
Get name of inherited type? 1 Answer