Sunday, 15 February 2015

Unity Editor Scripts

     Based on the one of the recent lectures I have decided to implement a Unity Editor Script to reset the variables for the scripts in the Inspector. I wanted to start with making all my variables private and using Serialized Fields to make them show up in Inspector but at the first try I have noticed there was a major problem with it.. Whenever those were changed it reset the variables to its initial state. So before I changed all of the fields I decided to write an Editor Script to enable resetting values to the defaults I want. When doing that I also used finding object in hierarchy function that I think was mention in one of the very first lectures. I had problems with setting variables to privates again as it needed getters and setters that would not be static(otherwise serialization doesn't work in Unity-issue which I have encountered). I resolved all these problems and now I have reset button for main character movement script that rests all values to what I want to be default. Then I moved on to making those fields finally Serialized Fields so that they can be displayed in Inspector despite being private.

     Before I attempted creating Editor Script for this functionality I have done some research and I have discovered there is an easier way of resetting values in Unity 4.5 or higher by using property drawers, which I will try to do for another script.

     At this point I have also use GameObjec.Find() method and therefore implemented some of the material covered in the second lecture in this series.

No comments:

Post a Comment