Book Image

Extending Unity with Editor Scripting

Book Image

Extending Unity with Editor Scripting

Overview of this book

Table of Contents (18 chapters)
Extending Unity with Editor Scripting
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Integrating the Scriptable Object with the level


In this section, we will integrate the LevelSetting class with our levels and then test how Scriptable Objects allow us to modify values in the play mode.

Updating the Level and the LevelInspector class

The first change to be made is to update the Level class. So, instead of using the current variables for the gravity, bgm, and background, start using a LevelSetting class as a reference.

Let's make a small update in Level.cs file. Add the following lines to it:

[SerializeField]
  private LevelSettings _settings;

  public LevelSettings Settings {
    get { return _settings; }
    set { _settings = value; }
  }

We need to take care of the render of this new property.

We will update the DrawLevelDataGUI method in the LevelInspector class:

private void DrawLevelDataGUI () {
      EditorGUILayout.LabelField ("Data", _titleStyle);
      EditorGUILayout.BeginVertical ("box");
      EditorGUILayout.PropertyField (_serializedTotalTime);
      _myTarget.Settings...