136 lines
3.0 KiB
C++
136 lines
3.0 KiB
C++
#include "ui_actor.h"
|
|
|
|
|
|
|
|
UIActor::UIActor() :
|
|
_bControl{ false }
|
|
{
|
|
UI::Panel* panel = CreatePanel("root");
|
|
panel->SetPosScale({ 0.0f, 0.0f });
|
|
panel->SetPosPixel(POS_CONTENT_LB);
|
|
panel->SetLocator(createLocatorY(180.0f));
|
|
|
|
//
|
|
File::GetPathFileAll(g_factory->GetPathModel(), _allModel);
|
|
for (auto& iter : _allModel)
|
|
{
|
|
iter = File::GetRelative(iter, g_factory->GetPathModel());
|
|
}
|
|
|
|
{
|
|
UI::ListBox* lst = g_ui->CreateListBoxDefault(false);
|
|
lst->SetItemCallback([](UI::Panel* item, Value v) {
|
|
if (v)
|
|
item->ExSetString(v.ToString());
|
|
else
|
|
item->ExSetString({});
|
|
});
|
|
lst->SetItemData(_allModel);
|
|
panel->Add(lst);
|
|
_lst = lst;
|
|
}
|
|
{
|
|
UI::ListBox* lst = g_ui->CreateListBoxDefault(false);
|
|
lst->SetItemCallback([](UI::Panel* item, Value v) {
|
|
if (v)
|
|
item->ExSetString(v.ToString());
|
|
else
|
|
item->ExSetString({});
|
|
});
|
|
panel->Add(lst);
|
|
_lstAnimation = lst;
|
|
}
|
|
{
|
|
UI::Text* txt = g_ui->CreateTextDefault();
|
|
txt->GetText()->SetOutline(1);
|
|
panel->Add(txt);
|
|
_txtDebug = txt;
|
|
}
|
|
_vecAct.resize(1);
|
|
|
|
_actBox = g_factory->CreateActorDefault();
|
|
_actBox->GetTransform()->SetPosition({ 0,0,-2.0f });
|
|
_actBox->GetTransform()->SetScale({ 10.0f, 10.0f, 0.2f });
|
|
_actBox->CreateRigidBody(RigidBodyType::STATIC, false);
|
|
|
|
|
|
|
|
g_factory->LoadSkybox("skybox/1k/");
|
|
g_factory->LoadSkybox("skybox/2k/");
|
|
g_factory->LoadSkybox("skybox/4k/");
|
|
}
|
|
|
|
void UIActor::Update()
|
|
{
|
|
//
|
|
if (g_input->KeyUp(KeyCode::TAB))
|
|
_bControl = !_bControl;
|
|
|
|
if (_bControl)
|
|
g_factory->GetCamera()->RunControllerFPS();
|
|
else
|
|
g_system->SetCursorMode(System::CursorMode::NORMAL);
|
|
|
|
g_factory->UpdateDebugView();
|
|
|
|
Value v = _lst->GetSelectClickDouble();
|
|
if (v)
|
|
{
|
|
g_factory->LoadModel(v.ToString(), v.ToString());
|
|
_vecAct[0] = g_factory->CreateActor(v.ToString());
|
|
_vecAct[0]->CreateRigidBody(RigidBodyType::DYNAMIC, true);
|
|
|
|
_allAnmation.clear();
|
|
for (size_t i = 0; i < _vecAct[0]->GetAniSize(); ++i)
|
|
{
|
|
_allAnmation.push_back(_vecAct[0]->GetAniName(i));
|
|
}
|
|
_lstAnimation->SetItemData(_allAnmation);
|
|
}
|
|
|
|
if (_vecAct[0])
|
|
{
|
|
Value v = _lstAnimation->GetSelectClickDouble();
|
|
if (v)
|
|
{
|
|
_vecAct[0]->SetAni(v.ToString());
|
|
}
|
|
if (_vecAct[0]->HasAni() && !g_input->KeyState(KeyCode::SPACE))
|
|
_vecAct[0]->Update();
|
|
}
|
|
_txtDebug->SetString(fmt::format("当前调试:{}", magic_enum::enum_name(g_factory->GetDebugView3D())));
|
|
|
|
_light.SetDirection({ -1.0f, 1.0f, -1.0f });
|
|
//_light.SetStrength({ 8.0f, 8.0f, 8.0f });
|
|
|
|
if(g_input->KeyUp(KeyCode::KEY1))
|
|
g_factory->SetSkybox(1);
|
|
if (g_input->KeyUp(KeyCode::KEY2))
|
|
g_factory->SetSkybox(2);
|
|
if (g_input->KeyUp(KeyCode::KEY3))
|
|
g_factory->SetSkybox(3);
|
|
if (g_input->KeyUp(KeyCode::KEY0))
|
|
g_factory->SetSkybox(0);
|
|
}
|
|
|
|
void UIActor::Render()
|
|
{
|
|
if (_vecAct[0])
|
|
{
|
|
_vecAct[0]->Render();
|
|
}
|
|
g_gfx->SetColor(ColorDef::AXIS_X);
|
|
g_gfx->Line({}, { 100, 0, 0 });
|
|
g_gfx->SetColor(ColorDef::AXIS_Y);
|
|
g_gfx->Line({}, { 0, 100, 0 });
|
|
g_gfx->SetColor(ColorDef::AXIS_Z);
|
|
g_gfx->Line({}, { 0, 0, 100 });
|
|
|
|
_light.Render();
|
|
_light.RenderDebug({ 0.0f, 0.0f, 3.0f });
|
|
|
|
_actBox->Render();
|
|
|
|
g_physics->RenderDebug();
|
|
}
|