using System; using System.Collections.Generic; using System.Linq; using NUnit.Framework; using UnityEditor; using UnityEngine; using UnityEngine.Perception.Content; namespace CharacterToolingTests { public class CharacterToolingTests { public List selectionLists = new List(); public List assets = new List(); private CharacterTooling contentTests = new CharacterTooling(); [SetUp] public void Setup() { selectionLists = new List(); AssetListCreation(); } [TearDown] public void TearDown() { selectionLists.Clear(); } [Test, TestCaseSource(typeof(AssetCollection), "GameObject")] public void CreateEarsNoseJoints(GameObject gameObject) { var exampleTemplate = AssetDatabase.GetAllAssetPaths().Where(o => o.EndsWith("CocoKeypointTemplate.asset", StringComparison.OrdinalIgnoreCase)).ToList(); var template = new UnityEngine.Object(); foreach (string o in exampleTemplate) { if (o.Contains("com.unity.perception")) { template = AssetDatabase.LoadAssetAtPath(o); } } var newModel = new GameObject(); var model = contentTests.CharacterCreateNose(gameObject, out newModel, template, true); var validate = false; if (model) validate = contentTests.ValidateNoseAndEars(newModel); else if (!model) Assert.Fail("Failed to create the Ear and Nose Joints"); Assert.True(validate, "Failed to create ear and nose joints"); } [Test, TestCaseSource(typeof(AssetCollection), "GameObject")] public void CharacterBones(GameObject gameObject) { var failedBones = new Dictionary(); var test = contentTests.CharacterRequiredBones(gameObject, out failedBones); Assert.True(test, "Character is missing required bones"); } [Test, TestCaseSource(typeof(AssetCollection), "GameObject")] public void CharacterPoseData(GameObject gameObject) { var failedPose = new List(); var test = contentTests.CharacterPoseData(gameObject, out failedPose); Assert.True(test, "Character is missing Pose Data"); } public void AssetListCreation() { assets = AssetDatabase.GetAllAssetPaths().Where(o => o.EndsWith(".fbx", StringComparison.OrdinalIgnoreCase)).ToList(); foreach (string o in assets) { if (o.Contains("TestAssets/Characters")) { var asset = AssetDatabase.LoadAssetAtPath(o); if (asset != null && !selectionLists.Contains(asset)) selectionLists.Add(asset); } } } } public class AssetCollection { public static IEnumerable GameObject { get { CharacterToolingTests tool = new CharacterToolingTests(); tool.AssetListCreation(); foreach (var asset in tool.selectionLists) { yield return new TestCaseData(asset); } } } } }