using System.Collections.Generic; using NUnit.Framework; using Sirenix.Utilities; using Test.Util; using UnityEditor; using UnityEngine; using VOID.Generic.Objects.Weapon; namespace Test.EditMode.Prefabs.Generic { public class WeaponObjectTest { private List _gameObjects = new(); [OneTimeSetUp] public void Setup() { AssetDatabase.FindAssets($"t:{nameof(GameObject)}").ForEach(gameObjectGuid => { var gameObjectPath = AssetDatabase.GUIDToAssetPath(gameObjectGuid); var gameObject = AssetDatabase.LoadAssetAtPath(gameObjectPath); var weaponObjects = gameObject.GetComponentsInChildren(); // If prefab have any ArmorObject - take it, we will test it if (weaponObjects.Length > 0) _gameObjects.Add(gameObject); }); } [OneTimeTearDown] public void Cleanup() { _gameObjects?.Clear(); _gameObjects = null; } [Test] public void WeaponData_Damage() { _gameObjects.ForEach(gameObject => { var weaponObject = gameObject.GetComponent(); var prefabPath = AssetDatabase.GetAssetPath(gameObject.GetInstanceID()); var prefabPathHyperlink = DebugLogUtil.Hyperlink(prefabPath); var damageMin = weaponObject.weaponData.damageMin; var damageMax = weaponObject.weaponData.damageMax; if (damageMin < 0f) Debug.LogError($"{nameof(WeaponObject)}'s damage min is lesser than 0: {prefabPathHyperlink}", weaponObject); if (damageMax < 0f) Debug.LogError($"{nameof(WeaponObject)}'s damage max is lesser than 0: {prefabPathHyperlink}", weaponObject); if (damageMin > damageMax) Debug.LogError($"{nameof(WeaponObject)}'s damage min is greater than damage max: {prefabPathHyperlink}", weaponObject); }); } [Test] public void WeaponData_AttackAbility() { _gameObjects.ForEach(gameObject => { var weaponObject = gameObject.GetComponent(); var prefabPath = AssetDatabase.GetAssetPath(gameObject.GetInstanceID()); var prefabPathHyperlink = DebugLogUtil.Hyperlink(prefabPath); if (!weaponObject.weaponData.attackAbility) Debug.LogError($"{nameof(WeaponObject)}'s attack ability is not selected: {prefabPathHyperlink}", weaponObject); }); } } }