using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SwitchHoldState : MonoBehaviour { Manager man; // public Switch3DRotate sw3Drotate; public Switch3DHRotate sw3DHrotate; void Start() { Transform[] btnList = this.transform.parent.gameObject.GetComponentsInChildren(); for (int i = 1; i < btnList.Length; i++) { if (i == 1) continue; btnList[i].gameObject.GetComponent().enabled = false; } man = GameObject.Find("Manager").GetComponent(); btnList[3].gameObject.GetComponent().enabled = true; } void OnMouseDown() { if (man.mode == "scedit" || man.mode == "play") return; Transform[] btnList = this.transform.parent.gameObject.GetComponentsInChildren(); for (int i = 1; i < btnList.Length; i++) { //if (i == 1) continue; btnList[i].gameObject.GetComponent().enabled = false; } this.gameObject.GetComponent().enabled = true; // btnList[1].gameObject.GetComponent().enabled = false; ConnectWith3DSwitchHorizontal(); } void OnMouseUp() { if (man.mode == "scedit" || man.mode == "play") return; Transform[] btnList = this.transform.parent.gameObject.GetComponentsInChildren(); for (int i = 1; i < btnList.Length; i++) { //if (i == 1) continue; btnList[i].gameObject.GetComponent().enabled = false; } btnList[3].gameObject.GetComponent().enabled = true; // Временный костыль возврата переключателя после отжатия, ситчаем что у всех таких выключателей возврат в середину 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(2); } public void switchOn() { Transform[] btnList = this.transform.parent.gameObject.GetComponentsInChildren(); for (int i = 1; i < btnList.Length; i++) btnList[i].gameObject.GetComponent().enabled = false; this.gameObject.GetComponent().enabled = true; } 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); } }