using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CoverState : MonoBehaviour { public Cover3DVrotate cw3DVrotate; public Cover3DHrotate cw3DHrotate; Manager man; public void Start() { man = GameObject.Find("Manager").GetComponent(); } void OnMouseDown() { if (man.mode == "scedit" || man.mode == "play") return; switchOn(); //Switch3DVrotate sw3DVrotate = this.GetComponent(); /* Transform[] btnList = this.transform.parent.gameObject.GetComponentsInChildren(); for (int i = 0; i < btnList.Length; i++) { if (i == 0) continue; if (btnList[i].gameObject.GetComponent() != null) { btnList[i].gameObject.GetComponent().enabled = true; btnList[i].gameObject.GetComponent().enabled = true; } if (btnList[i].gameObject.GetComponent() != null) { btnList[i].gameObject.GetComponent().enabled = true; btnList[i].gameObject.GetComponent().enabled = true; } } if (this.gameObject.GetComponent() != null) { this.gameObject.GetComponent().enabled = false; this.gameObject.GetComponent().enabled = false; } else if (this.gameObject.GetComponent() != null) { this.gameObject.GetComponent().enabled = false; this.gameObject.GetComponent().enabled = false; }*/ } public void switchOn() { Transform[] btnList = this.transform.parent.gameObject.GetComponentsInChildren(); for (int i = 1; i < btnList.Length; i++) { //if (i == 0) continue; if (btnList[i].gameObject.GetComponent() != null) { btnList[i].gameObject.GetComponent().enabled = true; btnList[i].gameObject.GetComponent().enabled = true; } else if (btnList[i].gameObject.GetComponent() != null) { btnList[i].gameObject.GetComponent().enabled = true; btnList[i].gameObject.GetComponent().enabled = true; } } //this.gameObject.GetComponent().enabled = true; if (this.gameObject.GetComponent() != null) { this.gameObject.GetComponent().enabled = false; this.gameObject.GetComponent().enabled = false; ConnectWith3d(); ConnectWith3dh(); } else if (this.gameObject.GetComponent() != null) { this.gameObject.GetComponent().enabled = false; this.gameObject.GetComponent().enabled = false; ConnectWith3d(); ConnectWith3dh(); } if(man == null) man = GameObject.Find("Manager").GetComponent(); // частные случаи работы крышек, переключателей и др., не предусматриваемые механикой файла objects.xml - короче "костыли" if (this.transform.parent.gameObject.name == "Cover1_0502" && this.gameObject.name.EndsWith("_2")) man.objects.Find("Tumbler2_0502").SetObjectState(2); if (this.transform.parent.gameObject.name == "Cover2_0511" && this.gameObject.name.EndsWith("_2")) man.objects.Find("Tumbler2_0511").SetObjectState(0); } public void ConnectWith3d() { string currentSw3Dname = this.transform.parent.name.Substring(0, transform.parent.name.Length) + "_3D"; GameObject currentSw3D = GameObject.Find(currentSw3Dname); if (currentSw3D != null) { Cover3DVrotate cw3DVrotate = currentSw3D.GetComponent(); if (cw3DVrotate != null) cw3DVrotate.Rotate(int.Parse(this.name.Substring(this.name.Length - 1))); } } public void ConnectWith3dh() { string currentSw3DHname = this.transform.parent.name.Substring(0, transform.parent.name.Length) + "_3D"; //Debug.Log(currentSw3DHname); GameObject currentSw3DH = GameObject.Find(currentSw3DHname); if (currentSw3DH != null) { Cover3DHrotate cw3DHrotate = currentSw3DH.GetComponent(); if (cw3DHrotate != null) cw3DHrotate.RotateH(int.Parse(this.name.Substring(this.name.Length - 1))); } } }