Skip to content

Commit

Permalink
Obsolate CreateInteractableComponent(GameObject)
Browse files Browse the repository at this point in the history
  • Loading branch information
nowsprinting committed Mar 31, 2024
1 parent 603037e commit 7bfd08f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions Runtime/InteractiveComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public static InteractiveComponent CreateInteractableComponent(MonoBehaviour com
/// <param name="isComponentInteractable">The function returns the <c>Component</c> is interactable or not.
/// Default is <c>DefaultComponentInteractableStrategy.IsInteractable</c>.</param>
/// <returns>Returns new InteractableComponent instance from GameObject. If GameObject is not interactable so, return null.</returns>
[Obsolete("Obsolete due to non-deterministic behavior when GameObject has multiple interactable components.")]
public static InteractiveComponent CreateInteractableComponent(GameObject gameObject,
Func<GameObject, Vector2> getScreenPoint = null,
Func<GameObject, Func<GameObject, Vector2>, PointerEventData, List<RaycastResult>, bool> isReachable = null,
Expand Down
13 changes: 10 additions & 3 deletions Samples~/uGUI Demo/Tests/Runtime/ScenarioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using NUnit.Framework;
using TestHelper.Attributes;
using UnityEngine.UI;

namespace TestHelper.Monkey.Samples.UGUIDemo
{
Expand All @@ -25,17 +26,23 @@ public async Task OpenSubScreens(string target)

// When click Start button, then open Home screen.
var startButton = await _finder.FindByNameAsync("StartButton", interactable: true);
InteractiveComponent.CreateInteractableComponent(startButton).Click();
var startComponent = InteractiveComponent.CreateInteractableComponent(startButton.GetComponent<Button>());
Assume.That(startComponent.CanClick(), Is.True);
startComponent.Click();
await _finder.FindByNameAsync("Home");

// When click target button, then open target screen.
var targetButton = await _finder.FindByNameAsync($"{target}Button", interactable: true);
InteractiveComponent.CreateInteractableComponent(targetButton).Click();
var targetComponent = InteractiveComponent.CreateInteractableComponent(targetButton.GetComponent<Button>());
Assume.That(targetComponent.CanClick(), Is.True);
targetComponent.Click();
await _finder.FindByNameAsync(target);

// When click Back button, then return Home screen.
var backButton = await _finder.FindByPathAsync($"**/{target}/BackButton", interactable: true);
InteractiveComponent.CreateInteractableComponent(backButton).Click();
var backComponent = InteractiveComponent.CreateInteractableComponent(backButton.GetComponent<Button>());
Assume.That(backComponent.CanClick(), Is.True);
backComponent.Click();
await _finder.FindByNameAsync("Home");
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Runtime/InteractiveComponentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class InteractiveComponentTest
public void CreateInteractableComponent_CreateInstance()
{
var button = new GameObject("InteractableButton").AddComponent<Button>();
var actual = InteractiveComponent.CreateInteractableComponent(button.gameObject);
var actual = InteractiveComponent.CreateInteractableComponent(button);
Assert.That(actual, Is.Not.Null);
}

Expand All @@ -28,7 +28,7 @@ public void CreateInteractableComponent_NotInteractable_ReturnNull()
{
var button = new GameObject("NotInteractableButton").AddComponent<Button>();
button.interactable = false;
var actual = InteractiveComponent.CreateInteractableComponent(button.gameObject);
var actual = InteractiveComponent.CreateInteractableComponent(button);
Assert.That(actual, Is.Null);
}

Expand Down

0 comments on commit 7bfd08f

Please sign in to comment.