2022-05-08 12:09:30 +01:00
|
|
|
#nullable enable
|
|
|
|
|
|
|
|
using System.Collections;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.TestTools;
|
2023-04-07 01:21:56 +01:00
|
|
|
using Object = UnityEngine.Object;
|
2022-05-08 12:09:30 +01:00
|
|
|
|
2022-05-08 12:17:57 +01:00
|
|
|
namespace X10D.Unity.Tests
|
2022-05-08 12:09:30 +01:00
|
|
|
{
|
|
|
|
public class ComponentTests
|
|
|
|
{
|
|
|
|
[UnityTest]
|
|
|
|
public IEnumerator GetComponentsInChildrenOnly_ShouldIgnoreParent()
|
|
|
|
{
|
|
|
|
var parent = new GameObject();
|
|
|
|
var rigidbody = parent.AddComponent<Rigidbody>();
|
|
|
|
|
|
|
|
var child = new GameObject();
|
|
|
|
child.AddComponent<Rigidbody>();
|
|
|
|
|
2023-04-07 01:21:56 +01:00
|
|
|
yield return null;
|
|
|
|
|
2022-05-08 12:09:30 +01:00
|
|
|
Rigidbody[] components = rigidbody.GetComponentsInChildrenOnly<Rigidbody>();
|
2023-04-07 01:34:34 +01:00
|
|
|
Assert.That(components, Has.Length.EqualTo(1));
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(child, Is.EqualTo(components[0].gameObject));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
2023-04-07 01:21:56 +01:00
|
|
|
Object.Destroy(parent);
|
|
|
|
Object.Destroy(child);
|
|
|
|
}
|
2022-05-08 12:09:30 +01:00
|
|
|
}
|
|
|
|
}
|