Fixed SHUIComponent serialization

This commit is contained in:
Kah Wei 2023-02-04 00:04:25 +08:00
parent 7ded7a0706
commit 3cd1778d08
5 changed files with 49 additions and 13 deletions

View File

@ -36,6 +36,9 @@
Mesh: 141771688
Material: 123313564
IsActive: true
UI Component:
Canvas ID: 1
IsActive: true
Scripts: ~
- EID: 5
Name: Main Menu Button
@ -56,6 +59,9 @@
Hovered Texture: 55999018
Clicked Texture: 66382894
IsActive: true
UI Component:
Canvas ID: 1
IsActive: true
Scripts:
- Type: ChangeSceneButton
Enabled: true
@ -79,6 +85,9 @@
Hovered Texture: 65045286
Clicked Texture: 58607560
IsActive: true
UI Component:
Canvas ID: 1
IsActive: true
Scripts:
- Type: QuitButton
Enabled: true

View File

@ -22,6 +22,9 @@
Mesh: 141771688
Material: 121834459
IsActive: true
UI Component:
Canvas ID: 0
IsActive: true
Scripts: ~
- EID: 5
Name: Start Game Button
@ -42,6 +45,9 @@
Hovered Texture: 62235279
Clicked Texture: 64722619
IsActive: true
UI Component:
Canvas ID: 0
IsActive: true
Scripts:
- Type: ChangeSceneButton
Enabled: true
@ -65,6 +71,9 @@
Hovered Texture: 65045286
Clicked Texture: 58607560
IsActive: true
UI Component:
Canvas ID: 0
IsActive: true
Scripts:
- Type: QuitButton
Enabled: true

View File

@ -9,17 +9,22 @@ public class ChangeSceneButton : Script
protected override void start()
{
UIElement ui = GetComponent<UIElement>();
ui.OnClick.RegisterAction(() =>
if (ui != null)
{
if(sceneID != 0)
ui.OnClick.RegisterAction(() =>
{
Audio.PlaySFXOnce2D("event:/UI/success");
SceneManager.ChangeScene(sceneID);
Audio.StopAllSounds();
}
});
if (sceneID != 0)
{
Audio.PlaySFXOnce2D("event:/UI/success");
SceneManager.ChangeScene(sceneID);
Audio.StopAllSounds();
}
});
}
else
{
Debug.LogError("Failed to register button action for ChangeSceneButton.");
}
}
protected override void update()
{

View File

@ -6,12 +6,22 @@ public class QuitButton : Script
protected override void start()
{
UIElement ui = GetComponent<UIElement>();
ui.OnClick.RegisterAction(() =>
if (ui != null)
{
Audio.StopAllSounds();
Application.Quit();
});
ui.OnClick.RegisterAction(() =>
{
ui.OnClick.RegisterAction(() =>
{
Audio.StopAllSounds();
Application.Quit();
});
});
}
else
{
Debug.LogError("Failed to register button action for QuitButton.");
}
}
protected override void update()

View File

@ -205,6 +205,7 @@ namespace SHADE
AddComponentToComponentNode<SHTextRenderableComponent>(components, eid);
AddComponentToComponentNode<SHAnimatorComponent>(components, eid);
AddComponentToComponentNode<SHUIComponent>(components, eid);
node[ComponentsNode] = components;
@ -263,6 +264,7 @@ namespace SHADE
AddComponentID<SHToggleButtonComponent>(componentIDList, componentsNode);
AddComponentID<SHTextRenderableComponent>(componentIDList, componentsNode);
AddComponentID<SHAnimatorComponent>(componentIDList, componentsNode);
AddComponentID<SHUIComponent>(componentIDList, componentsNode);
return componentIDList;
}
@ -347,5 +349,6 @@ namespace SHADE
SHSerializationHelper::InitializeComponentFromNode<SHTextRenderableComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHLightComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHAnimatorComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHUIComponent>(componentsNode, eid);
}
}