Skip to content

Commit

Permalink
Add popup spammer
Browse files Browse the repository at this point in the history
  • Loading branch information
toberge committed Oct 22, 2023
1 parent b1cf05b commit 66e6ad8
Show file tree
Hide file tree
Showing 10 changed files with 391 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Assets/Prefabs/Input/Player.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,57 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1 &345906872987025452
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3484089900029681523}
- component: {fileID: 4146737323431763604}
m_Layer: 5
m_Name: Spam
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &3484089900029681523
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 345906872987025452}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 3570743071879246586}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &4146737323431763604
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 345906872987025452}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 054f8241b622aff439e7b31758f43d23, type: 3}
m_Name:
m_EditorClassIdentifier:
popups:
- {fileID: 2749458525383876187, guid: 6e375834f9190b44b85120879f9bbee1, type: 3}
--- !u!1 &650044701630506088
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -936,6 +987,7 @@ RectTransform:
m_LocalScale: {x: 0, y: 0, z: 0}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 3484089900029681523}
- {fileID: 5051670465698078307}
- {fileID: 1664387495115092571}
- {fileID: 1417967732049705392}
Expand Down
109 changes: 109 additions & 0 deletions Assets/Prefabs/UI/SpamWindow.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3985983561988511089
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1225662013474792832}
- component: {fileID: 4203500173424713874}
- component: {fileID: 196829886972534681}
- component: {fileID: 2749458525383876187}
- component: {fileID: 3979177335964750275}
m_Layer: 5
m_Name: SpamWindow
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1225662013474792832
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3985983561988511089}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 27.8552, y: 3.3161}
m_SizeDelta: {x: 360, y: 264}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &4203500173424713874
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3985983561988511089}
m_CullTransparentMesh: 1
--- !u!114 &196829886972534681
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3985983561988511089}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 1208c49ff8294ce498efcc7be814bca7, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!114 &2749458525383876187
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3985983561988511089}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bf36c31efc151dc4b96cecf0ef7f1f29, type: 3}
m_Name:
m_EditorClassIdentifier:
minTimeout: 2
maxTimeout: 4
--- !u!114 &3979177335964750275
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3985983561988511089}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bf39a137c20631044b50258ded7b8ed2, type: 3}
m_Name:
m_EditorClassIdentifier:
baseWaitTime: 0
additionalWaitTime: 0
repeat: 0
7 changes: 7 additions & 0 deletions Assets/Prefabs/UI/SpamWindow.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions Assets/Scripts/UI/Popup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using UnityEngine;

public class Popup : MonoBehaviour
{
[SerializeField]
private float minTimeout = 2;

[SerializeField]
private float maxTimeout = 4;

private Timer timer;

private void Start()
{
timer = GetComponent<Timer>();
timer.StartTimer(Random.Range(minTimeout, maxTimeout));
timer.OnTimerRunCompleted += () => Destroy(gameObject);
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/UI/Popup.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions Assets/Scripts/UI/PopupSpammer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Collections;
using CollectionExtensions;
using UnityEngine;

public class PopupSpammer : MonoBehaviour
{
[SerializeField] private Popup[] popups;

private RectTransform rectTransform;

private void Start()
{
rectTransform = GetComponent<RectTransform>();
StartCoroutine(SpamALot());
}

private void Spam()
{
// TODO get the popups on top!
var popup = popups.RandomElement();
var halfWidth = rectTransform.rect.width / 2;
var halfHeight = rectTransform.rect.height / 2;
var position = new Vector2(
Random.Range(-halfWidth, halfWidth),
Random.Range(-halfHeight, halfHeight));
var instance = Instantiate(popup, transform.position, transform.rotation, rectTransform);
instance.GetComponent<RectTransform>().anchoredPosition = position;
}

private IEnumerator SpamALot()
{
while (true)
{
Spam();
yield return new WaitForSeconds(.5f);
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/UI/PopupSpammer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Textures/Spam.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Textures/Spam/ErrorWindow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 66e6ad8

Please sign in to comment.