Skip to content

Samples

ODD Games edited this page Oct 14, 2026 · 3 revisions

Samples

The package ships a generator for a sample scene that exercises every kind of input, plus the small runtime components that scene uses. It does not ship sample tests — the examples below are written against the generated scene and can be copied into your own test assembly.

Sample Scene

Generate it from:

Window > UI Automation > Generate Sample Scene

This creates a new, unsaved scene with a Canvas, an EventSystem and the panels below, then logs a reminder to save it. Save it (for example as Assets/Scenes/ComprehensiveSampleScene.unity) and add it to File > Build Profiles (scene list) so a PlayMode test can load it by name.

Only MainMenu is active at start. Each menu button shows one panel, and every panel's Back button returns to the menu.

Panels and Element Names

MainMenu

Name Text
SettingsButton Settings
ButtonsButton Buttons
FormsButton Forms
DragButton Drag & Drop
KeyboardButton Keyboard
AdvancedButton Advanced Input

SettingsPanel

SoundToggle ("Sound Effects"), MusicToggle ("Music"), SettingsVolumeSlider, GraphicsOption ("Graphics: High"), BackButton.

SampleButtonPanel

ResultLabel (shows "Button clicked!" after SimpleButton is clicked), SampleToggle, three ItemButtons ("Item 1"–"Item 3", for index tests), CounterLabel ("Counter: N") with IncrementButton, DisabledButton (not interactable), HoldButton ("Hold Me"), BackButton.

SampleFormPanel

Label Field
"Username:" UsernameInput (TMP_InputField)
"Email:" EmailInput (legacy InputField)
"Password:" PasswordInput (TMP_InputField, password)
"Category:" CategoryDropdown (Option 1–3)
"Volume:" VolumeSlider

Plus AgreeToggle ("I agree to terms"), SubmitButton ("Submit"), SuccessMessage ("Form submitted successfully!", hidden until Submit is clicked) and BackButton.

SampleDragPanel

ScrollView (vertical), Carousel (horizontal scroll view), DraggableItem ("Drag"), DropZone ("Drop Here"), BackButton.

SampleKeyboardPanel

KeyPressTarget ("Press Space"), KeyboardInput ("Type here:") and SecondInput ("Tab to:") — both legacy InputFields — and KeyHoldContainer, a WASD + Shift indicator with a moving PositionIndicator and KeyHoldStatus text. BackButton.

SampleAdvancedPanel

DoubleClickButton ("Double-Click Me") with DoubleClickFeedback, ScrollArea, SwipeArea, GestureStatus, BackButton. A 3D cube named GestureTarget is shown on the left while this panel is open; it responds to pinch, rotate and two-finger pan.

Example Tests

using System.Threading.Tasks;
using NUnit.Framework;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using ODDGames.BugpunchSdk;
using static ODDGames.BugpunchSdk.ActionExecutor;

[TestFixture]
public class SampleSceneTests
{
    [SetUp]
    public async Task LoadScene()
    {
        await SceneManager.LoadSceneAsync("ComprehensiveSampleScene");
        await WaitFor(Name("MainMenu"));
    }

    [Test]
    public async Task Settings_OpenAndReturn()
    {
        await Click(Text("Settings"));
        await WaitFor(Name("SettingsPanel"));
        await Click(Name("SoundToggle"));
        await ClickSlider(Name("SettingsVolumeSlider"), 0.25f);
        await Click(Text("Back"));
        await WaitFor(Name("MainMenu"));
    }

    [Test]
    public async Task Buttons_ClickHoldAndCount()
    {
        await Click(Text("Buttons"));

        await Click(Text("Simple Button"));
        await WaitFor(Name("ResultLabel"), "Button clicked!");

        await Click(Name("IncrementButton"));
        await Click(Name("IncrementButton"));
        await WaitFor(Name("CounterLabel"), "Counter: 2");

        await Click(Text("Item 2"));
        await Hold(Text("Hold Me"), 1f);

        var disabled = await Find<Button>(Name("DisabledButton"));
        Assert.IsFalse(disabled.interactable);
    }

    [Test]
    public async Task Form_FillAndSubmit()
    {
        await Click(Text("Forms"));

        await TextInput(Adjacent("Username:"), "testuser");
        await TextInput(Adjacent("Email:"), "test@example.com");
        await TextInput(Adjacent("Password:"), "secret123");
        await ClickDropdown(Name("CategoryDropdown"), "Option 2");
        await ClickSlider(Name("VolumeSlider"), 0.75f);
        await Click(Name("AgreeToggle"));

        Assert.AreEqual("testuser", await GetValue<string>(Name("UsernameInput")));
        Assert.AreEqual(1, await GetValue<int>(Name("CategoryDropdown")));
        Assert.IsTrue(await GetValue<bool>(Name("AgreeToggle")));

        await Click(Text("Submit"));
        await WaitFor(Name("SuccessMessage"));
    }

    [Test]
    public async Task Drag_ItemOntoDropZone()
    {
        await Click(Text("Drag & Drop"));
        await DragTo(Name("DraggableItem"), Name("DropZone"));
        await Scroll(Name("ScrollView"), "down", 0.5f);
        await Swipe(Name("Carousel"), SwipeDirection.Left);
    }

    [Test]
    public async Task Keyboard_TypeAndHold()
    {
        await Click(Text("Keyboard"));
        await TextInput(Adjacent("Type here:"), "hello");
        await HoldKey(Key.W, 0.5f);
        await HoldKeys(0.5f, Key.D, Key.LeftShift);
    }

    [Test]
    public async Task Advanced_Gestures()
    {
        await Click(Text("Advanced Input"));
        await DoubleClick(Name("DoubleClickButton"));
        await Swipe(Name("SwipeArea"), SwipeDirection.Right);
        await Pinch(Name("GestureTarget"), 1.5f);
        await Rotate(Name("GestureTarget"), 45f);
        await TwoFingerSwipe(Name("GestureTarget"), "up");
    }
}

Put this in a test assembly that references ODDGames.Bugpunch, Unity.InputSystem, Unity.TextMeshPro and the test runner (see Installation).

Sample Components

These ship as source in the package's Samples/ folder (ODDGames.Bugpunch.Samples assembly):

Component Purpose
PanelSwitcher On the Canvas: wires the menu and Back buttons, shows one panel at a time, toggles the gesture cube, and drives the button-panel result/counter and the form's success message
ClickFeedback Turns an element green briefly when clicked and counts clicks — handy for confirming injected input landed
DraggableUI / DropZoneUI Drag-and-drop source and target
GestureCube 3D target that scales on pinch, rotates on twist and pans on two-finger drag
GestureTargetUI UI gesture target
KeyHoldIndicator Lights up W/A/S/D/Shift while held and moves a position marker

Related Pages

Clone this wiki locally