So I created my first Editor script. The script opens up a window with an object field and allows me to make several changes to the object through toggle switches and EnumPopups. I click a button and it applies all the attributes I set to the object I placed in the object field. It works like a charm, however the editor script performs some calculations based on the attributes I set that I would like to have access to in the script that is applied to the object.
Essentially, what I would like to be able to do is have another class that has variables to hold the values that my Editor script calculated so that the script that is applied to the object can have access to these values without having to do the calculations itself.
For example, my editor script will have something like this:
Then in my ObjProperties.cs
Then some other MonoBehaviour script that is actually applied to the object can have access to this value by saying something like:
Problem is, this doesn't work. mCalc always has it's default value of 0.0f.
What am I doing wrong?
Any help is greatly appreciated. This is driving me crazy.
asked Aug 10 '11 at 05:19 AM
You can't store properties just as class variables (I'm assuming you mistranscribed a
Simplest would be to store the calculated value in the actual scene object that ultimately needs it, not try to poke it elsewhere.
answered Aug 10 '11 at 01:24 PM
Certainly Kilometers. First you will need to create a class that extends ScriptableObject (make sure you have using UnityEngine at the top) for your stored variables. It should look something like this:
Then, in your editor script have some method you call such as this one.
What this will do is create an asset file that you can reference through other scripts and thus have access to your stored values. So somewhere in your MonoBehaviour have:
and simply drag the storeddata.asset file into the object field in the inspector.
That pretty much sums it up. If you have any further questions on how this works just let me know.