Skip to content

Commit 0832f82

Browse files
committed
Fix Samples~/uGUI Demo
1 parent f83576a commit 0832f82

File tree

13 files changed

+1651
-1529
lines changed

13 files changed

+1651
-1529
lines changed

Samples~/uGUI Demo/Scenes/uGUIDemo.unity

Lines changed: 1565 additions & 1386 deletions
Large diffs are not rendered by default.

Samples~/uGUI Demo/Scripts/Runtime/MonkeyTestsButton.cs renamed to Samples~/uGUI Demo/Scripts/Runtime/MonkeyTestButton.cs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,40 @@
55
using Cysharp.Threading.Tasks;
66
using TestHelper.UI.Operators;
77
using TestHelper.UI.ScreenshotFilenameStrategies;
8+
using TestHelper.UI.Visualizers;
89
using UnityEngine;
910
using UnityEngine.UI;
1011

1112
namespace TestHelper.UI.Samples.UguiDemo
1213
{
1314
[RequireComponent(typeof(Button))]
14-
public class MonkeyTestsButton : MonoBehaviour
15+
public class MonkeyTestButton : MonoBehaviour
1516
{
1617
[field: SerializeField]
1718
private int LifetimeSeconds { get; set; } = 10;
1819

1920
[field: SerializeField]
2021
private int DelayMillis { get; set; } = 200;
2122

23+
[field: SerializeField]
24+
private int BufferLengthForDetectLooping { get; set; } = 10;
25+
26+
[field: SerializeField]
27+
private bool VerboseLogger { get; set; }
28+
29+
[field: SerializeField]
30+
private bool DebugVisualizer { get; set; }
31+
2232
private Button _button;
2333
private Text _buttonText;
34+
private string _originalButtonText;
2435

2536
private void Awake()
2637
{
2738
_button = GetComponent<Button>();
2839
_button.onClick.AddListener(() => RunMonkeyTests().Forget());
2940
_buttonText = _button.GetComponentInChildren<Text>();
41+
_originalButtonText = _buttonText.text;
3042
}
3143

3244
private async UniTask RunMonkeyTests()
@@ -35,50 +47,35 @@ private async UniTask RunMonkeyTests()
3547
{
3648
Lifetime = TimeSpan.FromSeconds(LifetimeSeconds),
3749
DelayMillis = DelayMillis,
38-
BufferLengthForDetectLooping = 10,
50+
BufferLengthForDetectLooping = BufferLengthForDetectLooping,
51+
Verbose = VerboseLogger,
52+
Visualizer = DebugVisualizer ? new DefaultDebugVisualizer() : null,
3953
Screenshots = new ScreenshotOptions()
4054
{
4155
FilenameStrategy = new CounterBasedStrategy("UguiDemo"),
4256
},
4357
Operators = new IOperator[]
4458
{
59+
new UguiClickAndHoldOperator(),
4560
new UguiClickOperator(),
4661
new UguiDoubleClickOperator(),
47-
new UguiClickAndHoldOperator(),
4862
new UguiDragAndDropOperator(),
49-
new UguiSwipeOperator(),
5063
new UguiScrollWheelOperator(),
64+
new UguiSwipeOperator(),
5165
new UguiTextInputOperator(),
5266
}
5367
};
5468

5569
try
5670
{
57-
SetControlsInteractable(false);
71+
_button.interactable = false;
72+
_buttonText.text = "Running...";
5873
await Monkey.Run(config);
5974
}
6075
finally
6176
{
62-
SetControlsInteractable(true);
63-
}
64-
}
65-
66-
private void SetControlsInteractable(bool interactable)
67-
{
68-
// myself
69-
_button.interactable = interactable;
70-
_buttonText.text = _button.interactable ? "Run Monkey Tests" : "Running...";
71-
72-
// settings
73-
foreach (var toggle in GameObject.Find("SettingsPane").GetComponentsInChildren<Toggle>())
74-
{
75-
toggle.interactable = interactable;
76-
}
77-
78-
// controls in content pane
79-
foreach (var content in FindObjectsOfType<TabContent>())
80-
{
81-
content.SetControlsInteractable(interactable);
77+
_buttonText.text = _originalButtonText;
78+
_button.interactable = true;
8279
}
8380
}
8481
}

Samples~/uGUI Demo/Scripts/Runtime/MonkeyTestsButton.cs.meta renamed to Samples~/uGUI Demo/Scripts/Runtime/MonkeyTestButton.cs.meta

File renamed without changes.

Samples~/uGUI Demo/Scripts/Runtime/TabContent.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using UnityEngine;
7-
using UnityEngine.UI;
87

98
namespace TestHelper.UI.Samples.UguiDemo
109
{
1110
public class TabContent : MonoBehaviour
1211
{
13-
[field: SerializeField]
14-
public GameObject ControlPanel { get; set; }
15-
1612
private List<TabContent> _tabContents = new List<TabContent>();
1713

1814
private void Start()
@@ -29,27 +25,6 @@ public void Select()
2925
{
3026
tabContent.gameObject.SetActive(tabContent == this);
3127
}
32-
33-
var monkeyTestsButton = FindObjectOfType<MonkeyTestsButton>();
34-
var interactable = monkeyTestsButton.GetComponent<Button>().interactable;
35-
SetControlsInteractable(interactable);
36-
}
37-
38-
/// <summary>
39-
/// Set interactable state for all Selectable components in ControlPanel.
40-
/// </summary>
41-
/// <param name="interactable"></param>
42-
public void SetControlsInteractable(bool interactable)
43-
{
44-
if (ControlPanel == null)
45-
{
46-
return;
47-
}
48-
49-
foreach (var selectable in ControlPanel.GetComponentsInChildren<Selectable>())
50-
{
51-
selectable.interactable = interactable;
52-
}
5328
}
5429
}
5530
}

Samples~/uGUI Demo/Scripts/Runtime/TabSwitchButton.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

Samples~/uGUI Demo/Scripts/Runtime/TabSwitchButton.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2019-2025 Koji Hasegawa.
2+
// This software is released under the MIT License.
3+
4+
using System.Collections.Generic;
5+
using UnityEngine;
6+
using UnityEngine.UI;
7+
8+
namespace TestHelper.UI.Samples.UguiDemo
9+
{
10+
/// <summary>
11+
/// Show target tab and hide other tabs when value changed.
12+
/// </summary>
13+
[RequireComponent(typeof(Dropdown))]
14+
public class TabSwitchDropdown : MonoBehaviour
15+
{
16+
[field: SerializeField]
17+
public List<TabContent> TargetContents { get; set; }
18+
19+
private void Awake()
20+
{
21+
var dropdown = GetComponent<Dropdown>();
22+
dropdown.options.Clear();
23+
foreach (var content in TargetContents)
24+
{
25+
dropdown.options.Add(new Dropdown.OptionData(content.gameObject.name)); // TODO: 仮
26+
}
27+
28+
dropdown.onValueChanged.AddListener(_ =>
29+
{
30+
TargetContents[dropdown.value].Select();
31+
});
32+
}
33+
}
34+
}

Samples~/uGUI Demo/Scripts/Runtime/TabSwitchDropdown.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Samples~/uGUI Demo/Tests/Runtime/ClickOperatorsTest.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,22 @@
66
using TestHelper.Attributes;
77
using TestHelper.UI.GameObjectMatchers;
88
using TestHelper.UI.Operators;
9+
using UnityEngine.UI;
910

1011
namespace TestHelper.UI.Samples.UguiDemo
1112
{
1213
[TestFixture]
1314
public class ClickOperatorsTest
1415
{
1516
private const string ScenePath = "../../Scenes/uGUIDemo.unity";
16-
1717
private readonly GameObjectFinder _finder = new GameObjectFinder();
1818

1919
[SetUp]
2020
public async Task SetUp()
2121
{
22-
var button = await _finder.FindByMatcherAsync(new ButtonMatcher(text: "Click Operators"));
23-
var clickOperator = new UguiClickOperator();
24-
Assume.That(clickOperator.CanOperate(button.GameObject), Is.True);
25-
26-
await clickOperator.OperateAsync(button.GameObject);
22+
var matcher = new ComponentMatcher(componentType: typeof(Dropdown), name: "TabSwitcher");
23+
var dropdown = await _finder.FindByMatcherAsync(matcher);
24+
dropdown.GameObject.GetComponent<Dropdown>().value = 1; // ClickDemo
2725
}
2826

2927
[Test]

Samples~/uGUI Demo/Tests/Runtime/DragOperatorsTest.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,22 @@
66
using TestHelper.Attributes;
77
using TestHelper.UI.GameObjectMatchers;
88
using TestHelper.UI.Operators;
9+
using UnityEngine.UI;
910

1011
namespace TestHelper.UI.Samples.UguiDemo
1112
{
1213
[TestFixture]
1314
public class DragOperatorsTest
1415
{
1516
private const string ScenePath = "../../Scenes/uGUIDemo.unity";
16-
1717
private readonly GameObjectFinder _finder = new GameObjectFinder();
1818

1919
[SetUp]
2020
public async Task SetUp()
2121
{
22-
var button = await _finder.FindByMatcherAsync(new ButtonMatcher(text: "Drag Operators"));
23-
var clickOperator = new UguiClickOperator();
24-
Assume.That(clickOperator.CanOperate(button.GameObject), Is.True);
25-
26-
await clickOperator.OperateAsync(button.GameObject);
22+
var matcher = new ComponentMatcher(componentType: typeof(Dropdown), name: "TabSwitcher");
23+
var dropdown = await _finder.FindByMatcherAsync(matcher);
24+
dropdown.GameObject.GetComponent<Dropdown>().value = 2; // DragDemo
2725
}
2826

2927
[Test]

0 commit comments

Comments
 (0)