No Description
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.

InputFieldTests.cs 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Linq;
  3. using NUnit.Framework;
  4. using UnityEngine;
  5. using UnityEngine.EventSystems;
  6. using UnityEngine.TestTools;
  7. using System.Collections;
  8. using System.IO;
  9. using UnityEditor;
  10. using UnityEngine.UI;
  11. using System.Reflection;
  12. namespace InputfieldTests
  13. {
  14. public class BaseInputFieldTests
  15. {
  16. protected GameObject m_PrefabRoot;
  17. public void CreateInputFieldAsset(string prefabPath)
  18. {
  19. #if UNITY_EDITOR
  20. var rootGO = new GameObject("rootGo");
  21. var canvasGO = new GameObject("Canvas", typeof(Canvas));
  22. canvasGO.transform.SetParent(rootGO.transform);
  23. var canvas = canvasGO.GetComponent<Canvas>();
  24. canvas.referencePixelsPerUnit = 100;
  25. GameObject inputFieldGO = new GameObject("InputField", typeof(RectTransform), typeof(InputField));
  26. inputFieldGO.transform.SetParent(canvasGO.transform);
  27. GameObject textGO = new GameObject("Text", typeof(RectTransform), typeof(Text));
  28. textGO.transform.SetParent(inputFieldGO.transform);
  29. GameObject eventSystemGO = new GameObject("EventSystem", typeof(EventSystem), typeof(FakeInputModule));
  30. eventSystemGO.transform.SetParent(rootGO.transform);
  31. InputField inputField = inputFieldGO.GetComponent<InputField>();
  32. inputField.interactable = true;
  33. inputField.enabled = true;
  34. inputField.textComponent = textGO.GetComponent<Text>();
  35. inputField.textComponent.fontSize = 12;
  36. inputField.textComponent.supportRichText = false;
  37. if (!Directory.Exists("Assets/Resources/"))
  38. Directory.CreateDirectory("Assets/Resources/");
  39. PrefabUtility.SaveAsPrefabAsset(rootGO, prefabPath);
  40. GameObject.DestroyImmediate(rootGO);
  41. #endif
  42. }
  43. }
  44. }