using System.Collections; using System.Collections.Generic; using NUnit.Framework; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.TestTools; using UnityEngine.UI; internal class GraphicRaycasterButtonTests { Camera m_Camera; EventSystem m_EventSystem; Canvas m_Canvas; Button m_ParentButton; Button m_ChildButton; Sprite m_Sprite; const int TextureSize = 64; readonly Texture2D texture = new Texture2D(TextureSize, TextureSize); [UnitySetUp] public IEnumerator TestSetup() { m_Camera = new GameObject("Camera").AddComponent(); m_Camera.transform.position = new Vector3(0, 0, -10); m_Canvas = new GameObject("Canvas").AddComponent(); m_Canvas.renderMode = RenderMode.ScreenSpaceOverlay; m_Canvas.gameObject.AddComponent(); m_EventSystem = new GameObject("Event System").AddComponent(); Color[] colors = new Color[TextureSize * TextureSize]; for (int y = 24; y < 40; y++) for (int x = 0; x < TextureSize; x++) colors[y + TextureSize * x] = colors[x + TextureSize * y] = Color.red; texture.SetPixels(colors); texture.Apply(); m_Sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100); var parentImage = new GameObject("ParentButton", typeof(RectTransform)).AddComponent(); parentImage.transform.SetParent(m_Canvas.transform); parentImage.rectTransform.anchoredPosition = new Vector2(0, 0); parentImage.sprite = m_Sprite; parentImage.SetNativeSize(); m_ParentButton = parentImage.gameObject.AddComponent