Scriptum/Assets/Scripts/REFACTORING/Application/Dialogue/Panel/Factory/PanelComponentFactory.cs
2022-12-04 20:48:40 +01:00

105 lines
3.9 KiB
C#

using UnityEngine;
using UnityEngine.UI;
public static class PanelComponentFactory
{
/// <summary>
///
/// </summary>
/// <param name="position"></param>
/// <param name="size"></param>
/// <param name="scale"></param>
/// <returns></returns>
public static GameObject BuildCustomPanel(Vector3 position, Vector2 size, Vector3 scale, bool withContinue = true)
{
var panel = DialoguePanelsPrefabsList.GetPanel();
panel.GetComponent<RectTransform>().position = position;
panel.GetComponent<RectTransform>().localScale = scale;
panel.GetComponent<RectTransform>().sizeDelta = size;
GameObject prefab = MonoBehaviour.Instantiate(panel, panel.GetComponent<RectTransform>().localPosition, panel.transform.rotation) as GameObject;
prefab.name = "DialoguePanel";
prefab.transform.SetParent(GameObject.FindGameObjectWithTag("GUI").transform, false);
return prefab;
}
public static GameObject BuildCustomPanelWithContinue(Vector3 position, Vector2 size, Vector3 scale)
{
var panel = BuildCustomPanel(position, size, scale);
GameObject continueButton = BuildContinueButton(new Vector3(-100, 150, 0), new Vector2(115, 90), new Vector3(1.2f, 1.2f, 1));
continueButton.transform.SetParent(panel.transform, false);
return panel;
}
public static GameObject BuildCustomButton(ButtonPanelModel answerModel)
{
var panel = DialoguePanelsPrefabsList.GetBaseButton();
panel.GetComponent<RectTransform>().position = answerModel.Position;
panel.GetComponent<RectTransform>().localScale = answerModel.Scale;
panel.GetComponent<RectTransform>().sizeDelta = answerModel.Size;
GameObject prefab = MonoBehaviour.Instantiate(panel, panel.GetComponent<RectTransform>().localPosition, panel.transform.rotation) as GameObject;
prefab.name = answerModel.Response;
// Assign content
prefab.transform.Find("Text").GetComponent<Text>().text = answerModel.Response;
// Assign actions
prefab.GetComponent<Button>().onClick.AddListener(() => answerModel.ButtonActions.Invoke());
return prefab;
}
public static GameObject BuildAcceptButton(Vector3 position, Vector2 size, Vector3 scale)
{
var panel = DialoguePanelsPrefabsList.GetAcceptButton();
panel.GetComponent<RectTransform>().position = position;
panel.GetComponent<RectTransform>().localScale = scale;
panel.GetComponent<RectTransform>().sizeDelta = size;
GameObject prefab = MonoBehaviour.Instantiate(panel, panel.GetComponent<RectTransform>().localPosition, panel.transform.rotation) as GameObject;
prefab.name = "AcceptButton";
return prefab;
}
public static GameObject BuildRejectButton(Vector3 position, Vector2 size, Vector3 scale)
{
var panel = DialoguePanelsPrefabsList.GetRejectButton();
panel.GetComponent<RectTransform>().position = position;
panel.GetComponent<RectTransform>().localScale = scale;
panel.GetComponent<RectTransform>().sizeDelta = size;
GameObject prefab = MonoBehaviour.Instantiate(panel, panel.GetComponent<RectTransform>().localPosition, panel.transform.rotation) as GameObject;
prefab.name = "RejectButton";
return prefab;
}
public static GameObject BuildContinueButton(Vector3 position, Vector2 size, Vector3 scale)
{
var panel = DialoguePanelsPrefabsList.GetContinueButton();
panel.GetComponent<RectTransform>().position = position;
panel.GetComponent<RectTransform>().sizeDelta = size;
panel.GetComponent<RectTransform>().localScale = scale;
GameObject prefab = MonoBehaviour.Instantiate(panel, panel.GetComponent<RectTransform>().localPosition, panel.transform.rotation) as GameObject;
prefab.name = "ContinueButton";
return prefab;
}
}