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 switchesList = new Dictionary(); // Обычные переключатели Dictionary switchesListHold = new Dictionary(); // Переключатели которые не фиксируются Dictionary buttonList = new Dictionary(); Dictionary buttonCheckList = new Dictionary(); // Нажимно-отжимные, с тегом buttonscheck Dictionary buttonCheckList3 = new Dictionary(); // Переключатели и кнопки с любым количеством спрайтов,переключающиеся друг за другом Dictionary mybtnCheckList3 = new Dictionary(); // Переключатели и кнопки с нажатием (первый объект),с любым количеством спрайтов,переключающиеся друг за другом Dictionary coverList = new Dictionary(); // Крышки и колпачки Dictionary handlerList = new Dictionary(); // Крутилки Dictionary rotateAngleList = new Dictionary(); // Крутилки 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(); cam = man.cam; layerName = LayerMask.LayerToName(gameObject.layer); coll2d = this.gameObject.GetComponentsInChildren(); 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 switches = uObj.FindChildsWithTag("toggle"); foreach (UnityObject sw in switches) { sw.gameObject.AddComponent(); switchesList.Add(sw.gameObject.name, sw.gameObject); //Debug.Log("Имена sw " + sw.name); } List switcheshold = uObj.FindChildsWithTag("togglehold"); foreach (UnityObject swh in switcheshold) { //Debug.Log(swh); swh.gameObject.AddComponent(); switchesListHold.Add(swh.gameObject.name, swh.gameObject); } List buttons = uObj.FindChildsWithTag("buttons"); foreach (UnityObject btn in buttons) { btn.gameObject.AddComponent(); buttonList.Add(btn.gameObject.name, btn.gameObject); //Debug.Log("Имена sw " + sw.name); } List buttonscheck = uObj.FindChildsWithTag("buttonscheck"); foreach (UnityObject _buttonscheck in buttonscheck) { _buttonscheck.gameObject.AddComponent(); buttonCheckList.Add(_buttonscheck.gameObject.name, _buttonscheck.gameObject); if (!_buttonscheck.gameObject.activeInHierarchy && !_buttonscheck.gameObject.GetComponent().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().isStarted) yield return null; parentGO.SetActive(false); } } } List buttonscheck3 = uObj.FindChildsWithTag("buttonscheck3"); foreach (UnityObject _buttonscheck3 in buttonscheck3) { _buttonscheck3.gameObject.AddComponent(); buttonCheckList3.Add(_buttonscheck3.gameObject.name, _buttonscheck3.gameObject); } List mybtnCheck = uObj.FindChildsWithTag("myBtnCheck"); foreach (UnityObject _mybtnCheck in mybtnCheck) { _mybtnCheck.gameObject.AddComponent(); mybtnCheckList3.Add(_mybtnCheck.gameObject.name, _mybtnCheck.gameObject); } List cover = uObj.FindChildsWithTag("cover"); foreach (UnityObject _cover in cover) { _cover.gameObject.AddComponent(); coverList.Add(_cover.gameObject.name, _cover.gameObject); } List handler = uObj.FindChildsWithTag("handles"); foreach (UnityObject _handler in handler) { if(_handler.gameObject.GetComponent() == null) _handler.gameObject.AddComponent(); if (!_handler.gameObject.activeInHierarchy && !_handler.gameObject.GetComponent().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().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().isStarted); handlerList.Add(_handler.gameObject.name, _handler.gameObject); } List rotateangle = uObj.FindChildsWithTag("rotateangle"); foreach (UnityObject _rotateangle in rotateangle) { _rotateangle.gameObject.AddComponent(); rotateAngleList.Add(_rotateangle.gameObject.name, _rotateangle.gameObject); } // switchesList["Toggle1_0213"].GetComponent().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 objs = uo.FindChildsWithTag("Untagged"); foreach (UnityObject _handler in objs) if (_handler.gameObject.GetComponent() != 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); } } }