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