From eae7b615d6a9c9f0098ddb381f5b85138283596b Mon Sep 17 00:00:00 2001 From: Pasha Bibko <156938226+PashaBibko@users.noreply.github.com> Date: Tue, 13 Jan 2026 10:54:09 +0000 Subject: [PATCH] Added a way to kill children --- Assets/Scenes/SampleScene.unity | 72 ++++++++++++++++++++++- Assets/Scripts/BasicWindow.cs | 5 +- Assets/Scripts/WindowBase.cs | 3 + Assets/Scripts/WindowInteractions.cs | 12 ++++ Assets/Scripts/WindowInteractions.cs.meta | 3 + Assets/Scripts/WindowSpawner.cs | 3 + 6 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 Assets/Scripts/WindowInteractions.cs create mode 100644 Assets/Scripts/WindowInteractions.cs.meta diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 1f619c4..e346597 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -622,13 +622,15 @@ GameObject: - component: {fileID: 1867692262} - component: {fileID: 1867692261} - component: {fileID: 1867692260} + - component: {fileID: 1867692264} + - component: {fileID: 1867692263} m_Layer: 5 m_Name: SampleChild m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!224 &1867692259 RectTransform: m_ObjectHideFlags: 0 @@ -699,6 +701,74 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: k__BackingField: {fileID: 1867692260} +--- !u!114 &1867692263 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1867692258} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 60d964b1b6914933801eaa6783d62cd8, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &1867692264 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1867692258} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 1867692260} + m_OnClick: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1867692263} + m_TargetAssemblyTypeName: InterfaceOff.WindowInteractions, Assembly-CSharp + m_MethodName: WindowClicked + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 --- !u!1 &2038986851 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/BasicWindow.cs b/Assets/Scripts/BasicWindow.cs index 14ce40d..fe5820e 100644 --- a/Assets/Scripts/BasicWindow.cs +++ b/Assets/Scripts/BasicWindow.cs @@ -2,6 +2,9 @@ { public class BasicWindow : WindowBase { - + public override void OnWindowClicked() + { + Destroy(gameObject); + } } } \ No newline at end of file diff --git a/Assets/Scripts/WindowBase.cs b/Assets/Scripts/WindowBase.cs index 635d6b0..51b60e5 100644 --- a/Assets/Scripts/WindowBase.cs +++ b/Assets/Scripts/WindowBase.cs @@ -4,11 +4,14 @@ namespace InterfaceOff { public abstract class WindowBase : MonoBehaviour { + public WindowInteractions Interactions { get; set; } public WindowComponents Components { get; set; } public void InstantiateWindowBase() { transform.position = CanvasManager.GetRandomPositionOnCanvas(); } + + public virtual void OnWindowClicked() { } } } diff --git a/Assets/Scripts/WindowInteractions.cs b/Assets/Scripts/WindowInteractions.cs new file mode 100644 index 0000000..7568ff2 --- /dev/null +++ b/Assets/Scripts/WindowInteractions.cs @@ -0,0 +1,12 @@ +using UnityEngine; + +namespace InterfaceOff +{ + public class WindowInteractions : MonoBehaviour + { + private WindowBase AttachedWindow { get; set; } + + public void SetAttachedTo(WindowBase window) => AttachedWindow = window; + public void WindowClicked() => AttachedWindow.OnWindowClicked(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/WindowInteractions.cs.meta b/Assets/Scripts/WindowInteractions.cs.meta new file mode 100644 index 0000000..2e03dd0 --- /dev/null +++ b/Assets/Scripts/WindowInteractions.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 60d964b1b6914933801eaa6783d62cd8 +timeCreated: 1768301109 \ No newline at end of file diff --git a/Assets/Scripts/WindowSpawner.cs b/Assets/Scripts/WindowSpawner.cs index 725d01d..41b83c6 100644 --- a/Assets/Scripts/WindowSpawner.cs +++ b/Assets/Scripts/WindowSpawner.cs @@ -49,6 +49,9 @@ namespace InterfaceOff return; } + windowBase.Interactions = go.GetComponent(); + windowBase.Interactions.SetAttachedTo(windowBase); + windowBase.Components = go.GetComponent(); windowBase.InstantiateWindowBase(); }