当前位置: 首页 > 工具软件 > Godot > 使用案例 >

godot引擎学习3

隗翰海
2023-12-01

扫描
void ProjectManager::_scan_projects() {
    scan_dir->popup_file_dialog();
}
33335
新建项
void ProjectManager::_new_project() {
    npdialog->set_mode(ProjectDialog::MODE_NEW);
    npdialog->show_dialog();
}
导入
void ProjectManager::_import_project() {
    npdialog->set_mode(ProjectDialog::MODE_IMPORT);
    npdialog->show_dialog();
}

编辑
void ProjectManager::_open_selected_projects_ask()

void ProjectManager::_open_selected_projects()

创建另一个进程
args.push_back("--path");
        args.push_back(path);

        args.push_back("--editor");

        if (OS::get_singleton()->is_stdout_debug_enabled()) {
            args.push_back("--debug");
        }

        if (OS::get_singleton()->is_stdout_verbose()) {
            args.push_back("--verbose");
        }

        if (OS::get_singleton()->is_disable_crash_handler()) {
            args.push_back("--disable-crash-handler");
        }

        String exec = OS::get_singleton()->get_executable_path();
        Error err = OS::get_singleton()->create_process(exec, args);

Error OS_Windows::create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id) {
    String path = p_path.replace("/", "\\");
    String command = _quote_command_line_argument(path);
    for (const String &E : p_arguments) {
        command += " " + _quote_command_line_argument(E);
    }

    ProcessInfo pi;
    ZeroMemory(&pi.si, sizeof(pi.si));
    pi.si.cb = sizeof(pi.si);
    ZeroMemory(&pi.pi, sizeof(pi.pi));
    LPSTARTUPINFOW si_w = (LPSTARTUPINFOW)&pi.si;

    int ret = CreateProcessW(nullptr, (LPWSTR)(command.utf16().ptrw()), nullptr, nullptr, false, NORMAL_PRIORITY_CLASS & CREATE_NO_WINDOW, nullptr, nullptr, si_w, &pi.pi);
    ERR_FAIL_COND_V_MSG(ret == 0, ERR_CANT_FORK, "Could not create child process: " + command);

    ProcessID pid = pi.pi.dwProcessId;
    if (r_child_id) {
        *r_child_id = pid;
    }
    process_map->insert(pid, pi);

    return OK;
};

二,配置文件
GLOBAL_DEF宏
ProjectSettings : public Object
中Map<StringName, VariantContainer> props;数据存放的地方
文件存放 project.godot,每个工程不同
对于class ProjectSettingsEditor : public AcceptDialog中配置的一些数据都存放这里
如:
display/window/size/width

_EDITOR_DEF宏
class EditorSettings : public Resource 
中HashMap<String, VariantContainer> props;存放数据
C:\Users\Dell\AppData\Roaming/Godot/editor_settings-3.tres
可以看出,这些变量是全局存放的
如:
interface/editor/editor_language = "zh_CN"
interface/editor/main_font_size = 20
interface/editor/code_font_size = 22.0
这个文件还有所有打开的工程文件信息
projects/E:::3DProject::machine = "E:/3DProject/machine"
projects/E:::3DProject::mymaterial = "E:/3DProject/mymaterial"
projects/E:::3DProject::myThird_Person = "E:/3DProject/myThird_Person"
文件各的产生
void EditorSettings::create()
String config_file_name = "editor_settings-" + itos(VERSION_MAJOR) + ".tres";
根据版本号产生的,在godot中为一个资源类型文件

关于主题设置
文件 C:/Users/Dell/AppData/Roaming/Godot/editor_settings-4.tres
interface/theme/preset
hints["interface/theme/preset"] = PropertyInfo(Variant::STRING, "interface/theme/preset", PROPERTY_HINT_ENUM, "Default,Breeze Dark,Godot 2,Grey,Light,Solarized (Dark),Solarized (Light),Custom", PROPERTY_USAGE_DEFAULT);
设置
EditorInspector::_edit_set
UndoRedo::commit_action
UndoRedo::_process_operation_list
SectionedInspectorFilter
edited->set(name, p_value, &valid);
Object::set(const StringName &p_name

EditorSettingsDialog::_settings_property_edited(const String &p_name)
theme = create_custom_theme(theme_base->get_theme());
 else if (preset == "Light")
 {
        preset_accent_color = Color(0.18, 0.50, 1.00);
        preset_base_color = Color(0.9, 0.9, 0.9);
        // A negative contrast rate looks better for light themes, since it better follows the natural order of UI "elevation".
        preset_contrast = -0.08;
}
所有相同版本都改了
EditorSettings::_load_defaults 初始化

一些文件路径
data_path = OS::get_singleton()->get_data_path();
C:\Users\Dell\AppData\Roaming
data_dir = data_path.plus_file(OS::get_singleton()->get_godot_dir_name());
C:\Users\Dell\AppData\Roaming/Godot
config_path = OS::get_singleton()->get_config_path();
C:\Users\Dell\AppData\Roaming
config_dir = config_path.plus_file(OS::get_singleton()->get_godot_dir_name());
C:\Users\Dell\AppData\Roaming/Godot
cache_path = OS::get_singleton()->get_cache_path();
C:\Users\Dell\AppData\Local\Temp

每个工程,文件不同
project_config_dir = project_config_dir.get_file() + "-" + project_config_dir.md5_text();
值:SimpleDebug-85a831dee25a300759bcf3f36ef8f623

与工程有关的几个文件
void EditorSettings::load_favorites()
C:\Users\Dell\AppData\Roaming/Godot/projects/SimpleDebug-85a831dee25a300759bcf3f36ef8f623/favorites 貌似编辑的UI布局
[recent_files]有场景最近打开的文件,脚本最近打开的文件
C:\Users\Dell\AppData\Roaming/Godot/projects/SimpleDebug-85a831dee25a300759bcf3f36ef8f623/recent_dirs
EditorSettings::get_project_metadata(const String &p_section, const String &p_key, Variant p_default)
C:\Users\Dell\AppData\Roaming/Godot/projects/SimpleDebug-85a831dee25a300759bcf3f36ef8f623/project_metadata.cfg


下载资源后的文件位置
C:\Users\Dell\AppData\Local\Temp/Godot/tmp_asset_3.zip
测试文件位置
C:\Users\Dell\AppData\Local\Temp\Uwdp\tmp_asset_196.zip
_Utils::get_singleton()->unpacket_scene(L"C:\\Users\\Dell\\AppData\\Local\\Temp\\Uwdp\\tmp_asset_196.zip");

字体
int default_font_size = int(EDITOR_GET("interface/editor/main_font_size")) * EDSCALE;
_initial_set("interface/editor/main_font_size", 15);

// load settings
if (!EditorSettings::get_singleton())
EditorSettings::create();
void EditorSettings::create()
C:\Users/Dell/AppData/Roaming/Leyifu/editor_settings-3.tres
singleton = ResourceLoader::load(config_file_path, "EditorSettings");

主题样式
void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) 
// Theme
//_initial_set("interface/theme/preset", "Default");
_initial_set("interface/theme/preset", "Light");

_initial_set("interface/editor/editor_language", "zh_CN");


下载的导出模板的位置
C:\Users\Dell\AppData\Roaming\Godot\templates
Godot_v3.3.3-stable_export_templates.tpz 也可以从文件中导入


类的辅助说明在
doc\classes
记得要在@GlobalScope.xml类中加说明

三,软件icon,及spash
1,原文件均在main目录下

2,编辑器中使用的一些图标
editor_icons.gen.h的产生
editor\icons目录下,.svg文件会产生

3,软件中使用的默认icon文件中scene\resources\default_theme,一些png文件
由make_header.py文件产生

四,翻译
在editor\translations中,然后编译后

进入编辑器参数
E:\godot\bin\godot.windows.tools.32.exe --path F:/project/Demo3 --editor

代码测试
godot_windows.cpp

编辑器参数试: E:\godot\bin\godot.windows.tools.32.exe --path F:\project\Simple2D --editor  ok,进入 编辑界面

开发UWDP使用
D:\mywork_doc\editor\bin\godot.windows.tools.32.exe --path E:\G3.5WorkProject\Simple --editor
D:\mywork_doc\godoteditorwork\bin\godot.windows.tools.32.exe  --path E:\UWDPProject\test0 --editor

E:\godot3.5\godot\bin\godot.windows.tools.32.exe --path E:\G3.5WorkProject\Simple --editor

godot定制开发 QQ 35484348

 类似资料: