설명 없음
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PrebuildSceneSetupAttribute.cs 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. namespace UnityEngine.TestTools
  3. {
  4. /// <summary>
  5. /// PrebuildSetup attribute run if the test or test class is in the current test run. The test is included either by running all tests or setting a filter that includes the test. If multiple tests reference the same pre-built setup or post-build cleanup, then it only runs once.
  6. /// </summary>
  7. [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
  8. public class PrebuildSetupAttribute : Attribute
  9. {
  10. /// <summary>
  11. /// Initializes and returns an instance of PrebuildSetupAttribute by type.
  12. /// </summary>
  13. /// <param name="targetClass">The type of the target class.</param>
  14. public PrebuildSetupAttribute(Type targetClass)
  15. {
  16. TargetClass = targetClass;
  17. }
  18. /// <summary>
  19. ///
  20. /// </summary>
  21. /// <param name="targetClassName"></param>
  22. /// <example>
  23. /// <code>
  24. /// [TestFixture]
  25. /// public class CreateSpriteTest : IPrebuildSetup
  26. /// {
  27. /// Texture2D m_Texture;
  28. /// Sprite m_Sprite;
  29. ///
  30. /// public void Setup()
  31. /// {
  32. ///
  33. /// #if UNITY_EDITOR
  34. ///
  35. /// var spritePath = "Assets/Resources/Circle.png";
  36. /// var ti = UnityEditor.AssetImporter.GetAtPath(spritePath) as UnityEditor.TextureImporter;
  37. /// ti.textureCompression = UnityEditor.TextureImporterCompression.Uncompressed;
  38. /// ti.SaveAndReimport();
  39. ///
  40. /// #endif
  41. /// }
  42. ///
  43. /// [SetUp]
  44. /// public void SetUpTest()
  45. /// {
  46. /// m_Texture = Resources.Load&lt;Texture2D&gt;("Circle");
  47. /// }
  48. ///
  49. /// [Test]
  50. /// public void WhenNullTextureIsPassed_CreateShouldReturnNullSprite()
  51. /// {
  52. ///
  53. /// // Check with Valid Texture.
  54. /// LogAssert.Expect(LogType.Log, "Circle Sprite Created");
  55. /// Sprite.Create(m_Texture, new Rect(0, 0, m_Texture.width, m_Texture.height), new Vector2(0.5f, 0.5f));
  56. /// Debug.Log("Circle Sprite Created");
  57. ///
  58. /// // Check with NULL Texture. Should return NULL Sprite.
  59. /// m_Sprite = Sprite.Create(null, new Rect(0, 0, m_Texture.width, m_Texture.heig`t), new Vector2(0.5f, 0.5f));
  60. /// Assert.That(m_Sprite, Is.Null, "Sprite created with null texture should be null");
  61. /// }
  62. /// }
  63. /// </code>
  64. /// Tip: Use `#if UNITY_EDITOR` if you want to access Editor only APIs, but the setup/cleanup is inside a **Play Mode** assembly.
  65. /// </example>
  66. public PrebuildSetupAttribute(string targetClassName)
  67. {
  68. TargetClass = AttributeHelper.GetTargetClassFromName(targetClassName, typeof(IPrebuildSetup));
  69. }
  70. internal Type TargetClass { get; private set; }
  71. }
  72. }