Scriptum/Assets/closePossibleButtonInfo.cs
kabix09 602c94726a Add scene manager for items
Start rebuild Save & Load game system
2022-06-19 01:25:49 +02:00

58 lines
2.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class closePossibleButtonInfo : MonoBehaviour
{
[SerializeField]
public List<GameObject> Panels; // for Quest panel && Dialogue Panel and in future for all others which could require to close info-panels
public List<string> actionPanels = new List<string>{"E-InteractivePanel", "E-InteractivePanelAbove", "Spacebar-InteractivePanel", "Spacebar-InteractivePanelAbove"};
void Update()
{
int index = Panels.FindIndex(panel => panel.active == true);
if (index >= 0)
{
// BRUTAL AND NAIVE SOLUTION
// TODO rewrite during refactoring dialogue panels module !!! - 18.06.2022
// EPanel.SetActive(false);
// EPanel1.SetActive(false);
// SpacePanel.SetActive(false);
// SpacePanel1.SetActive(false);
// the same solution prescribed for the needs of dynamic toolpits - also rewrite later -
// TODO - cahne whole logic
// 1. Fetch "space hit" and all other panels and destroy them if exists as GUI object children
// Because its in "Update" object are destroyed all time - again and again and again - when cndition is met
// TODO
// add action which will block open action-into-panels again if one of "Panels" is currently opened and allow this after close
// add condition for each object whisch have "OpenPanelOnCollision" script
// GetComponent<OpenPanelOnCollision>().isAllowedToShowPanels = false;
GameObject globalGUI = GameObject.FindGameObjectsWithTag("GUI")[0];
foreach (Transform eachChild in globalGUI.transform) {
int match = actionPanels.FindIndex(actionPanelName => (actionPanelName == eachChild.name || actionPanelName + "(Clone)" == eachChild.name));
if(match >= 0)
{
//Debug.Log("Destroy " + eachChild.name);
Destroy(eachChild.gameObject);
}
}
}
}
}