Description
The Scene
property of the EditorTool
class provides access to the current Scene
instance that the editor tool is operating within. This property is essential for interacting with the scene's elements, such as game objects, components, and other scene-related data.
Usage
Use the Scene
property to access and manipulate the scene within the context of an editor tool. This property is particularly useful when you need to perform operations that involve the scene's structure or its elements.
Note that this property is marked with the JsonIgnore
attribute, indicating that it will not be serialized when the object is converted to JSON. This is typically done to prevent circular references or to exclude non-serializable data from the serialization process.
Example
// Example of accessing the Scene property within an EditorTool
public class MyCustomEditorTool : EditorTool
{
public override void OnEnabled()
{
base.OnEnabled();
// Access the current scene
Scene currentScene = this.Scene;
// Perform operations on the scene
// For example, iterate over all game objects in the scene
foreach (var gameObject in currentScene.GameObjects)
{
// Perform some operation on each game object
}
}
}