#if UNITY_EDITOR using System; using UnityEngine; namespace RuntimeUnitTestToolkit.Editor { // functional declarative construction like flutter. internal interface IBuilder { GameObject GameObject { get; } T GetComponent(); } internal class Builder : IBuilder where T : Component { public T Component1 { get; private set; } public GameObject GameObject { get; private set; } public Transform Transform { get { return GameObject.transform; } } public RectTransform RectTransform { get { return GameObject.GetComponent(); } } public Action SetTarget { set { value(this.GameObject); } } public IBuilder Child { set { value.GameObject.transform.SetParent(GameObject.transform); } } public IBuilder[] Children { set { foreach (var item in value) { item.GameObject.transform.SetParent(GameObject.transform); } } } public Builder(string name) { this.GameObject = new GameObject(name); this.Component1 = GameObject.AddComponent(); } public Builder(string name, out T referenceSelf) // out primary reference. { this.GameObject = new GameObject(name); this.Component1 = GameObject.AddComponent(); referenceSelf = this.Component1; } public TComponent GetComponent() { return this.GameObject.GetComponent(); } } internal class Builder : Builder where T1 : Component where T2 : Component { public T2 Component2 { get; private set; } public Builder(string name) : base(name) { this.Component2 = GameObject.AddComponent(); } public Builder(string name, out T1 referenceSelf) : base(name, out referenceSelf) { this.Component2 = GameObject.AddComponent(); } } internal class Builder : Builder where T1 : Component where T2 : Component where T3 : Component { public T3 Component3 { get; private set; } public Builder(string name) : base(name) { this.Component3 = GameObject.AddComponent(); } public Builder(string name, out T1 referenceSelf) : base(name, out referenceSelf) { this.Component3 = GameObject.AddComponent(); } } internal class Builder : Builder where T1 : Component where T2 : Component where T3 : Component where T4 : Component { public T4 Component4 { get; private set; } public Builder(string name) : base(name) { this.Component4 = GameObject.AddComponent(); } public Builder(string name, out T1 referenceSelf) : base(name, out referenceSelf) { this.Component4 = GameObject.AddComponent(); } } } #endif