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
|
|
|
|
{
|
2023-04-10 13:44:37 +01:00
|
|
|
[Test]
|
|
|
|
public void GetComponentsInChildrenOnly_ShouldIgnoreParent()
|
2022-05-08 12:09:30 +01:00
|
|
|
{
|
|
|
|
var parent = new GameObject();
|
|
|
|
var rigidbody = parent.AddComponent<Rigidbody>();
|
|
|
|
|
|
|
|
var child = new GameObject();
|
2023-04-10 13:45:39 +01:00
|
|
|
child.transform.SetParent(parent.transform);
|
2022-05-08 12:09:30 +01:00
|
|
|
child.AddComponent<Rigidbody>();
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|