How EditorScript works

Hello everyone. I am with you, stalker320, and today I would like to tell you about writing service scripts that run in the editor. Everyone who wants to read - welcome under the cut






EditorScript is a script that can be launched by pressing the Ctrl + Shift + X combination directly from the engine. It can perform various service functions. For example, create the necessary directory structure in the project.





tool
extends EditorScript

var folders: PoolStringArray = [#    
	"res://assets/textures/",#   
	"res://assets/fonts/",#      ,   
	"res://resources/",
	"res://addons/",
	"res://scenes/",
	"res://scripts/singletons/",
	"res://scripts/resources/",
	"res://scripts/editor_scripts/"
]

var placeholder: Resource = load("res://placeholder.tres")
# -    .  

func _run() -> void: #    
	var dir = Directory.new()
	for folder in folders: #    
		if !dir.dir_exists(folder):
			var err = OK
			err = dir.make_dir_recursive(folder)
			if err != OK:
				prints("Error", err)
				return
			else:
				if !dir.file_exists(folder.plus_file("placeholder.tres")):
					#        
					err = ResourceSaver.save(folder.plus_file("placeholder.tres"), placeholder)
					if err != OK:
						prints("Error", err) 
						return
					else:
						#    ( )
						prints("Making", folder)
						prints("Making", folder.plus_file("placeholder.tres"))
	print("Successful. Structure created or already exists.")
	return

      
      



, - API . ( , , - ). , , get_scene() ( , , ).





, , , .





. , , , .








All Articles