X10D/X10D.Unity.Tests/Assets/Tests/ComponentTests.cs

32 lines
872 B
C#
Raw Normal View History

2022-05-08 11:09:30 +00:00
#nullable enable
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using Object = UnityEngine.Object;
2022-05-08 11:09:30 +00:00
namespace X10D.Unity.Tests
2022-05-08 11:09:30 +00:00
{
public class ComponentTests
{
[Test]
public void GetComponentsInChildrenOnly_ShouldIgnoreParent()
2022-05-08 11:09:30 +00:00
{
var parent = new GameObject();
var rigidbody = parent.AddComponent<Rigidbody>();
var child = new GameObject();
child.transform.SetParent(parent.transform);
2022-05-08 11:09:30 +00:00
child.AddComponent<Rigidbody>();
Rigidbody[] components = rigidbody.GetComponentsInChildrenOnly<Rigidbody>();
Assert.That(components, Has.Length.EqualTo(1));
Assert.That(child, Is.EqualTo(components[0].gameObject));
2022-05-08 11:09:30 +00:00
Object.Destroy(parent);
Object.Destroy(child);
}
2022-05-08 11:09:30 +00:00
}
}