using UnityEngine; using UnityEngine.UI; public class SwitchState : MonoBehaviour { //public Switch3DRotate sw3Drotate; public Switch3DHRotate sw3DHrotate; Manager man; void Start() { //sw3Drotate = FindObjectOfType(); // Debug.Log(sw3Drotate + " объекты" ); man = GameObject.Find("Manager").GetComponent(); } void OnMouseDown() { if (man.mode == "scedit" || man.mode == "play") return; 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 = false; else btnList[i].gameObject.GetComponent().enabled = false; } //this.gameObject.GetComponent().enabled = true; if (this.gameObject.GetComponent() != null) this.gameObject.GetComponent().enabled = true; else this.gameObject.GetComponent().enabled = true; //Debug.Log(int.Parse(this.name.Substring(this.name.Length - 1)) + " конец этого"); //if(sw3Drotate!=null) ConnectWith3DSwitchVertikal(); //if (sw3DHrotate!=null) ConnectWith3DSwitchHorizontal(); ConnectWith3DSwitchVertikal(); ConnectWith3DSwitchHorizontal(); } /*Функция связывает вертикальные выключатели 2D и 3D */ public void ConnectWith3DSwitchVertikal() { Transform[] btnList = this.transform.parent.gameObject.GetComponentsInChildren(); string currentSw3Dname = this.name.Substring(0, this.name.Length - 1) + "3D"; GameObject currentSw3D = GameObject.Find(currentSw3Dname); Switch3DRotate sw3Drotate = currentSw3D.GetComponent(); if (sw3Drotate != null) // sw3Drotate.RotateVertikalSwitch(btnList.Length - 1, int.Parse(this.name.Substring(this.name.Length - 1))); sw3Drotate.RotateVertikalSwitch(int.Parse(this.name.Substring(this.name.Length - 1))-1); // добавили в передаваемое значение -1. Спрайты имеют концовку 1,2,3, а numpos в редакторе начинается с нуля } /*Функция связывает горизонтальные выключатели 2D и 3D */ public void ConnectWith3DSwitchHorizontal() { Transform[] btnList = this.transform.parent.gameObject.GetComponentsInChildren(); string currentSw3DHname = this.name.Substring(0, this.name.Length - 1) + "3D"; GameObject currentSw3DH = GameObject.Find(currentSw3DHname); Switch3DHRotate sw3DHrotate = currentSw3DH.GetComponent(); if (sw3DHrotate != null) //sw3DHrotate.RotateHorizontalSwitch(btnList.Length - 1, int.Parse(this.name.Substring(this.name.Length - 1))); sw3DHrotate.RotateHorizontalSwitch(int.Parse(this.name.Substring(this.name.Length - 1)) - 1); } public void switchOn() { 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 = false; else btnList[i].gameObject.GetComponent().enabled = false; } //this.gameObject.GetComponent().enabled = true; if (this.gameObject.GetComponent() != null) this.gameObject.GetComponent().enabled = true; else this.gameObject.GetComponent().enabled = true; //GetComponent().pos = btnList.Length; //GetComponent().numpos = int.Parse(this.name.Substring(this.name.Length - 1)); } }