mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-23 23:55:38 +03:00
190 lines
8.1 KiB
C#
190 lines
8.1 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
|
||
public class Panel2D : MonoBehaviour
|
||
{
|
||
|
||
//public ScriptA m_someOtherScriptOnAnotherGameObject;
|
||
// Start is called before the first frame update
|
||
public Dictionary<string, GameObject> switchesList = new Dictionary<string, GameObject>(); // Обычные переключатели
|
||
Dictionary<string, GameObject> switchesListHold = new Dictionary<string, GameObject>(); // Переключатели которые не фиксируются
|
||
Dictionary<string, GameObject> buttonList = new Dictionary<string, GameObject>();
|
||
Dictionary<string, GameObject> buttonCheckList = new Dictionary<string, GameObject>(); // Нажимно-отжимные, с тегом buttonscheck
|
||
Dictionary<string, GameObject> buttonCheckList3 = new Dictionary<string, GameObject>(); // Переключатели и кнопки с любым количеством спрайтов,переключающиеся друг за другом
|
||
Dictionary<string, GameObject> mybtnCheckList3 = new Dictionary<string, GameObject>(); // Переключатели и кнопки с нажатием (первый объект),с любым количеством спрайтов,переключающиеся друг за другом
|
||
Dictionary<string, GameObject> coverList = new Dictionary<string, GameObject>(); // Крышки и колпачки
|
||
Dictionary<string, GameObject> handlerList = new Dictionary<string, GameObject>(); // Крутилки
|
||
Dictionary<string, GameObject> rotateAngleList = new Dictionary<string, GameObject>(); // Крутилки
|
||
Manager man;
|
||
Camera cam;//камера для канваса с панелями
|
||
string layerName;
|
||
Collider2D[] coll2d;
|
||
public bool isStarted = false;
|
||
|
||
void Start()
|
||
{
|
||
if(!isStarted)
|
||
StartCoroutine(Init());
|
||
}
|
||
public IEnumerator Init()
|
||
{
|
||
man = GameObject.Find("Manager").GetComponent<Manager>();
|
||
cam = man.cam;
|
||
layerName = LayerMask.LayerToName(gameObject.layer);
|
||
coll2d = this.gameObject.GetComponentsInChildren<Collider2D>();
|
||
UnityObject uObj = man.objects.Find(this.gameObject.name);
|
||
while (!man.objects.isLoaded)
|
||
yield return null;
|
||
|
||
// Debug.Log("Start 2D " + this.gameObject.name);
|
||
|
||
if (uObj == null)
|
||
yield break;
|
||
|
||
List<UnityObject> switches = uObj.FindChildsWithTag("toggle");
|
||
foreach (UnityObject sw in switches)
|
||
{
|
||
sw.gameObject.AddComponent<Switch>();
|
||
switchesList.Add(sw.gameObject.name, sw.gameObject);
|
||
//Debug.Log("Имена sw " + sw.name);
|
||
}
|
||
|
||
List<UnityObject> switcheshold = uObj.FindChildsWithTag("togglehold");
|
||
foreach (UnityObject swh in switcheshold)
|
||
{
|
||
//Debug.Log(swh);
|
||
swh.gameObject.AddComponent<SwitchHold>();
|
||
switchesListHold.Add(swh.gameObject.name, swh.gameObject);
|
||
}
|
||
List<UnityObject> buttons = uObj.FindChildsWithTag("buttons");
|
||
foreach (UnityObject btn in buttons)
|
||
{
|
||
btn.gameObject.AddComponent<myButton>();
|
||
buttonList.Add(btn.gameObject.name, btn.gameObject);
|
||
//Debug.Log("Имена sw " + sw.name);
|
||
}
|
||
|
||
List<UnityObject> buttonscheck = uObj.FindChildsWithTag("buttonscheck");
|
||
foreach (UnityObject _buttonscheck in buttonscheck)
|
||
{
|
||
_buttonscheck.gameObject.AddComponent<ButtonCheckable>();
|
||
buttonCheckList.Add(_buttonscheck.gameObject.name, _buttonscheck.gameObject);
|
||
|
||
if (!_buttonscheck.gameObject.activeInHierarchy && !_buttonscheck.gameObject.GetComponent<ButtonCheckable>().isStarted)
|
||
{
|
||
|
||
string nm = _buttonscheck.gameObject.transform.parent.gameObject.name;
|
||
GameObject parentGO = _buttonscheck.gameObject.transform.parent.parent.gameObject;
|
||
if (nm == "view2_0801" || nm == "view2_0802" || nm == "view3_0801" || nm == "view3_0802" ||
|
||
nm == "Handle3_0701" || nm == "Handle3_0702")
|
||
{
|
||
parentGO.SetActive(true);
|
||
while (!_buttonscheck.gameObject.GetComponent<ButtonCheckable>().isStarted)
|
||
yield return null;
|
||
parentGO.SetActive(false);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
List<UnityObject> buttonscheck3 = uObj.FindChildsWithTag("buttonscheck3");
|
||
foreach (UnityObject _buttonscheck3 in buttonscheck3)
|
||
{
|
||
_buttonscheck3.gameObject.AddComponent<ButtonCheckable3>();
|
||
buttonCheckList3.Add(_buttonscheck3.gameObject.name, _buttonscheck3.gameObject);
|
||
}
|
||
|
||
List<UnityObject> mybtnCheck = uObj.FindChildsWithTag("myBtnCheck");
|
||
foreach (UnityObject _mybtnCheck in mybtnCheck)
|
||
{
|
||
_mybtnCheck.gameObject.AddComponent<MyBtnCheck3>();
|
||
mybtnCheckList3.Add(_mybtnCheck.gameObject.name, _mybtnCheck.gameObject);
|
||
}
|
||
|
||
List<UnityObject> cover = uObj.FindChildsWithTag("cover");
|
||
foreach (UnityObject _cover in cover)
|
||
{
|
||
_cover.gameObject.AddComponent<Cover>();
|
||
coverList.Add(_cover.gameObject.name, _cover.gameObject);
|
||
}
|
||
|
||
List<UnityObject> handler = uObj.FindChildsWithTag("handles");
|
||
foreach (UnityObject _handler in handler)
|
||
{
|
||
|
||
if(_handler.gameObject.GetComponent<Handler>() == null)
|
||
_handler.gameObject.AddComponent<Handler>();
|
||
if (!_handler.gameObject.activeInHierarchy && !_handler.gameObject.GetComponent<Handler>().isStarted)
|
||
{
|
||
|
||
string nm = _handler.gameObject.name;
|
||
GameObject parentGO = _handler.gameObject.transform.parent.gameObject;
|
||
if (nm == "view2_0801" || nm == "view2_0802" || nm == "view3_0801" || nm == "view3_0802" ||
|
||
nm == "Handle3_0701" || nm == "Handle3_0702")
|
||
{
|
||
parentGO.SetActive(true);
|
||
parentGO.SetActive(false);
|
||
}
|
||
}
|
||
while (!_handler.gameObject.GetComponent<Handler>().isStarted)
|
||
yield return null;
|
||
|
||
//if (_handler.gameObject.name == "Handle3_0701" || _handler.gameObject.name == "Handle3_0702")
|
||
// Debug.Log("Init Panel2D: handler " + _handler.gameObject.name + " is started " + _handler.gameObject.GetComponent<Handler>().isStarted);
|
||
|
||
handlerList.Add(_handler.gameObject.name, _handler.gameObject);
|
||
}
|
||
List<UnityObject> rotateangle = uObj.FindChildsWithTag("rotateangle");
|
||
foreach (UnityObject _rotateangle in rotateangle)
|
||
{
|
||
_rotateangle.gameObject.AddComponent<RotateAngle>();
|
||
rotateAngleList.Add(_rotateangle.gameObject.name, _rotateangle.gameObject);
|
||
}
|
||
|
||
// switchesList["Toggle1_0213"].GetComponent<Switch>().setState(0);
|
||
//Debug.Log("End Start 2D " + this.gameObject.name);
|
||
|
||
isStarted = true;
|
||
|
||
/*for (int i = 0; i < man.objects.obj.Count; i++)
|
||
{
|
||
UnityObject uo = man.objects.obj[i];
|
||
if (uo == null) continue;
|
||
List<UnityObject> objs = uo.FindChildsWithTag("Untagged");
|
||
foreach (UnityObject _handler in objs)
|
||
if (_handler.gameObject.GetComponent<Handler>() != null)
|
||
Debug.Log("Untagged handles " + _handler.gameObject.name);
|
||
}*/
|
||
}
|
||
private void EnableCollider( bool isEnable)
|
||
{
|
||
for (int i = 0; i < coll2d.Length; i++)
|
||
{
|
||
coll2d[i].enabled = isEnable;
|
||
}
|
||
}
|
||
public void setEnabled()
|
||
{
|
||
cam.cullingMask |= 1 << LayerMask.NameToLayer(layerName);
|
||
this.gameObject.SetActive(true);
|
||
if (layerName.StartsWith("MFI")) EnableCollider(true);
|
||
}
|
||
|
||
public void setDisabled()
|
||
{
|
||
cam.cullingMask = 0;
|
||
if (!layerName.StartsWith("MFI"))
|
||
{
|
||
|
||
this.gameObject.SetActive(false);
|
||
}
|
||
else
|
||
{
|
||
EnableCollider(false);
|
||
}
|
||
}
|
||
|
||
}
|