Files
bansonic_beta_main/Assets/scripts/UI/Panel/dontdestroyonload/loadtopandbottom[Prefab.cs
T

52 lines
1.5 KiB
C#

using UnityEngine;
public class loadtopandbottomPrefab: MonoBehaviour
{
[Header("father obj")]
public GameObject top_and_bottom_Panel;
public GameObject gameobject_to_Instantiate_below;
[SerializeField] bool notify_Main_Panel = true;
void Start()
{
if (top_and_bottom_Panel != null && gameobject_to_Instantiate_below != null)
{
GameObject instantiated = Instantiate(top_and_bottom_Panel, gameobject_to_Instantiate_below.transform);
Canvas canvas = instantiated.GetComponent<Canvas>();
if (canvas != null)
{
Camera cam = Camera.main;
if (cam == null)
{
cam = Object.FindAnyObjectByType<Camera>();
}
canvas.worldCamera = cam;
cam = null;
}
if (notify_Main_Panel)
{
Bind_Main_Panel(instantiated);
}
}
}
void Bind_Main_Panel(GameObject instantiated)
{
if (instantiated == null)
{
return;
}
UI_Panel_Main main = Object.FindAnyObjectByType<UI_Panel_Main>();
if (main == null)
{
return;
}
RectTransform top = instantiated.transform.Find("TOP") as RectTransform;
RectTransform bottom = instantiated.transform.Find("BTM") as RectTransform;
if (top != null || bottom != null)
{
main.Bind_Top_Bottom(top, bottom);
}
}
}