Fixed Button texture swapping. Fixed Button scripts on scene change. Added buttons to scenes. Added SHEDITOR define for Managed #341

Merged
maverickdgg merged 17 commits from SP3-20-UI-System into main 2023-02-04 00:32:29 +08:00
11 changed files with 112 additions and 28 deletions
Showing only changes of commit 382a2d0f6a - Show all commits

View File

@ -1,16 +1,16 @@
[Window][MainStatusBar] [Window][MainStatusBar]
Pos=0,981 Pos=0,989
Size=1920,20 Size=2560,20
Collapsed=0 Collapsed=0
[Window][SHEditorMenuBar] [Window][SHEditorMenuBar]
Pos=0,48 Pos=0,48
Size=1920,933 Size=2560,941
Collapsed=0 Collapsed=0
[Window][Hierarchy Panel] [Window][Hierarchy Panel]
Pos=0,186 Pos=0,187
Size=300,795 Size=300,802
Collapsed=0 Collapsed=0
DockId=0x00000004,0 DockId=0x00000004,0
@ -20,14 +20,14 @@ Size=400,400
Collapsed=0 Collapsed=0
[Window][Inspector] [Window][Inspector]
Pos=1434,48 Pos=2074,48
Size=486,933 Size=486,941
Collapsed=0 Collapsed=0
DockId=0x00000006,0 DockId=0x00000006,0
[Window][Profiler] [Window][Profiler]
Pos=0,48 Pos=0,48
Size=300,136 Size=300,137
Collapsed=0 Collapsed=0
DockId=0x00000003,0 DockId=0x00000003,0
@ -76,7 +76,7 @@ DockId=0x0000000B,0
[Window][ Viewport] [Window][ Viewport]
Pos=302,48 Pos=302,48
Size=1130,697 Size=1770,705
Collapsed=0 Collapsed=0
DockId=0x0000000B,0 DockId=0x0000000B,0
@ -93,14 +93,14 @@ Collapsed=0
DockId=0x0000000A,0 DockId=0x0000000A,0
[Window][ Asset Browser] [Window][ Asset Browser]
Pos=302,747 Pos=302,755
Size=1130,234 Size=1770,234
Collapsed=0 Collapsed=0
DockId=0x0000000C,0 DockId=0x0000000C,0
[Window][Material Inspector] [Window][Material Inspector]
Pos=1434,48 Pos=2074,48
Size=486,933 Size=486,941
Collapsed=0 Collapsed=0
DockId=0x00000006,1 DockId=0x00000006,1
@ -116,13 +116,13 @@ Collapsed=0
[Window][Collider Tag Panel] [Window][Collider Tag Panel]
Pos=302,48 Pos=302,48
Size=1130,697 Size=1770,705
Collapsed=0 Collapsed=0
DockId=0x0000000B,1 DockId=0x0000000B,1
[Window][Input Bindings Panel] [Window][Input Bindings Panel]
Pos=1434,48 Pos=2074,48
Size=486,933 Size=486,941
Collapsed=0 Collapsed=0
DockId=0x00000006,2 DockId=0x00000006,2
@ -151,7 +151,7 @@ Column 15 Weight=1.2009
Column 16 Weight=1.0132 Column 16 Weight=1.0132
[Docking][Data] [Docking][Data]
DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=0,77 Size=1920,933 Split=X DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=0,71 Size=2560,941 Split=X
DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1432,1036 Split=X DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1432,1036 Split=X
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=300,1036 Split=Y Selected=0x1E6EB881 DockNode ID=0x00000001 Parent=0x00000005 SizeRef=300,1036 Split=Y Selected=0x1E6EB881
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,147 Selected=0x1E6EB881 DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,147 Selected=0x1E6EB881

View File

@ -1,7 +1,7 @@
- EID: 0 - EID: 0
Name: Canvas Name: Canvas
IsActive: true IsActive: true
NumberOfChildren: 1 NumberOfChildren: 2
Components: Components:
Canvas Component: Canvas Component:
Canvas Width: 1920 Canvas Width: 1920
@ -9,7 +9,7 @@
IsActive: true IsActive: true
Scripts: ~ Scripts: ~
- EID: 1 - EID: 1
Name: Default Name: Background
IsActive: true IsActive: true
NumberOfChildren: 0 NumberOfChildren: 0
Components: Components:
@ -23,6 +23,29 @@
Material: 121834459 Material: 121834459
IsActive: true IsActive: true
Scripts: ~ Scripts: ~
- EID: 5
Name: Start Game Button
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 75, z: 0}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 400, y: 200, z: 1}
IsActive: true
Renderable Component:
Mesh: 141771688
Material: 129340704
IsActive: true
Button Component:
Default Texture: 52901020
Hovered Texture: 62235279
Clicked Texture: 64722619
IsActive: true
Scripts:
- Type: ChangeSceneButton
Enabled: true
sceneID: 86098106
- EID: 2 - EID: 2
Name: Light Name: Light
IsActive: true IsActive: true

View File

@ -0,0 +1,28 @@
using System;
using SHADE;
public class ChangeSceneButton : Script
{
public uint sceneID = 0;
protected override void awake()
{
UIElement ui = GetComponent<UIElement>();
ui.OnClick.RegisterAction(() =>
{
if(sceneID != 0)
{
Audio.PlaySFXOnce2D("event:/UI/success");
SceneManager.ChangeScene(86098106);
Audio.StopAllSounds();
}
});
}
protected override void update()
{
}
}

View File

@ -0,0 +1,3 @@
Name: SC_ChangeSceneButton
ID: 155329160
Type: 9

View File

@ -39,5 +39,10 @@ layout(location = 1) out uint outEntityID;
void main() void main()
{ {
fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv); fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv);
if (fragColor.a < 0.01f)
{
discard;
}
outEntityID = In2.eid; outEntityID = In2.eid;
} }

Binary file not shown.

View File

@ -7,7 +7,7 @@ namespace SHADE
{ {
SHButtonComponent::SHButtonComponent() SHButtonComponent::SHButtonComponent()
:size(1.0f), isHovered(false), isClicked(false), :size(1.0f), isHovered(false), isClicked(false),
defaultTexture(0), hoveredTexture(0), clickedTexture(0) defaultTexture(0), hoveredTexture(0), clickedTexture(0), currentTexture(0)
{ {
} }

View File

@ -41,6 +41,8 @@ namespace SHADE
AssetID hoveredTexture; AssetID hoveredTexture;
AssetID clickedTexture; AssetID clickedTexture;
AssetID currentTexture;
RTTR_ENABLE() RTTR_ENABLE()
}; };

View File

@ -6,7 +6,7 @@ namespace SHADE
{ {
SHToggleButtonComponent::SHToggleButtonComponent() SHToggleButtonComponent::SHToggleButtonComponent()
:size(1.0f), isHovered(false), isClicked(false), value(false), :size(1.0f), isHovered(false), isClicked(false), value(false),
defaultTexture(0), toggledTexture(0) defaultTexture(0), toggledTexture(0), currentTexture(0)
{ {
} }

View File

@ -42,6 +42,8 @@ namespace SHADE
AssetID defaultTexture; AssetID defaultTexture;
AssetID toggledTexture; AssetID toggledTexture;
AssetID currentTexture;
RTTR_ENABLE() RTTR_ENABLE()

View File

@ -236,12 +236,14 @@ namespace SHADE
auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID()); auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
//auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture()); //auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
auto material = renderable->GetModifiableMaterial();
AssetID textureID = 0;
if (!comp.isHovered && !comp.isClicked) if (!comp.isHovered && !comp.isClicked)
{ {
if (comp.GetDefaultTexture() != 0 && SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE) if (comp.GetDefaultTexture() != 0 && SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE)
{ {
material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(comp.GetDefaultTexture())); textureID = comp.GetDefaultTexture();
//material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(comp.GetDefaultTexture()));
//SHLOG_INFO("SETTING DEFAULT TEXTURE") //SHLOG_INFO("SETTING DEFAULT TEXTURE")
} }
} }
@ -249,7 +251,8 @@ namespace SHADE
{ {
if (comp.GetClickedTexture() != 0 && SHAssetManager::GetType(comp.GetClickedTexture()) == AssetType::TEXTURE) if (comp.GetClickedTexture() != 0 && SHAssetManager::GetType(comp.GetClickedTexture()) == AssetType::TEXTURE)
{ {
material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(comp.GetClickedTexture())); textureID = comp.GetClickedTexture();
//material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(comp.GetClickedTexture()));
//SHLOG_INFO("SETTING CLICKED TEXTURE") //SHLOG_INFO("SETTING CLICKED TEXTURE")
} }
} }
@ -257,10 +260,17 @@ namespace SHADE
{ {
if (comp.GetHoveredTexture() != 0 && SHAssetManager::GetType(comp.GetHoveredTexture()) == AssetType::TEXTURE) if (comp.GetHoveredTexture() != 0 && SHAssetManager::GetType(comp.GetHoveredTexture()) == AssetType::TEXTURE)
{ {
material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>( comp.GetHoveredTexture())); textureID = comp.GetHoveredTexture();
//material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>( comp.GetHoveredTexture()));
//SHLOG_INFO("SETTING HOVERED TEXTURE") //SHLOG_INFO("SETTING HOVERED TEXTURE")
} }
} }
if (textureID != 0 && textureID != comp.currentTexture)
{
auto material = renderable->GetModifiableMaterial();
comp.currentTexture = textureID;
material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(textureID));
}
@ -358,12 +368,14 @@ namespace SHADE
auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID()); auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
//auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture()); //auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
auto material = renderable->GetModifiableMaterial(); //auto material = renderable->GetModifiableMaterial();
AssetID textureID = 0;
if (comp.GetValue() == false) if (comp.GetValue() == false)
{ {
if (comp.GetDefaultTexture()!= 0 && SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE) if (comp.GetDefaultTexture()!= 0 && SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE)
{ {
material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(comp.GetDefaultTexture())); textureID = comp.GetDefaultTexture();
//material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(comp.GetDefaultTexture()));
//SHLOG_INFO("SETTING DEFAULT TEXTURE") //SHLOG_INFO("SETTING DEFAULT TEXTURE")
} }
} }
@ -371,11 +383,20 @@ namespace SHADE
{ {
if (comp.GetToggledTexture() != 0 && SHAssetManager::GetType(comp.GetToggledTexture()) == AssetType::TEXTURE) if (comp.GetToggledTexture() != 0 && SHAssetManager::GetType(comp.GetToggledTexture()) == AssetType::TEXTURE)
{ {
material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(comp.GetToggledTexture())); textureID = comp.GetToggledTexture();
//material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(comp.GetToggledTexture()));
//SHLOG_INFO("SETTING DEFAULT TEXTURE") //SHLOG_INFO("SETTING DEFAULT TEXTURE")
} }
} }
if (textureID != 0 && textureID != comp.currentTexture)
{
auto material = renderable->GetModifiableMaterial();
comp.currentTexture = textureID;
material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(textureID));
}
} }
} }