mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 02:45:39 +03:00
87 lines
3.4 KiB
C#
87 lines
3.4 KiB
C#
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<Transform>();
|
||
|
||
for (int i = 1; i < btnList.Length; i++)
|
||
{
|
||
if (i == 1) continue;
|
||
|
||
btnList[i].gameObject.GetComponent<SpriteRenderer>().enabled = false;
|
||
}
|
||
man = GameObject.Find("Manager").GetComponent<Manager>();
|
||
btnList[3].gameObject.GetComponent<SpriteRenderer>().enabled = true;
|
||
}
|
||
|
||
|
||
|
||
void OnMouseDown()
|
||
{
|
||
if (man.mode == "scedit" || man.mode == "play")
|
||
return;
|
||
Transform[] btnList = this.transform.parent.gameObject.GetComponentsInChildren<Transform>();
|
||
for (int i = 1; i < btnList.Length; i++)
|
||
{
|
||
//if (i == 1) continue;
|
||
btnList[i].gameObject.GetComponent<SpriteRenderer>().enabled = false;
|
||
}
|
||
|
||
this.gameObject.GetComponent<SpriteRenderer>().enabled = true;
|
||
// btnList[1].gameObject.GetComponent<SpriteRenderer>().enabled = false;
|
||
ConnectWith3DSwitchHorizontal();
|
||
}
|
||
|
||
void OnMouseUp()
|
||
{
|
||
if (man.mode == "scedit" || man.mode == "play")
|
||
return;
|
||
Transform[] btnList = this.transform.parent.gameObject.GetComponentsInChildren<Transform>();
|
||
for (int i = 1; i < btnList.Length; i++)
|
||
{
|
||
//if (i == 1) continue;
|
||
btnList[i].gameObject.GetComponent<SpriteRenderer>().enabled = false;
|
||
}
|
||
btnList[3].gameObject.GetComponent<SpriteRenderer>().enabled = true;
|
||
|
||
|
||
// Временный костыль возврата переключателя после отжатия, ситчаем что у всех таких выключателей возврат в середину
|
||
string currentSw3DHname = this.name.Substring(0, this.name.Length - 1) + "3D";
|
||
GameObject currentSw3DH = GameObject.Find(currentSw3DHname);
|
||
Switch3DHRotate sw3DHrotate = currentSw3DH.GetComponent<Switch3DHRotate>();
|
||
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<Transform>();
|
||
for (int i = 1; i < btnList.Length; i++)
|
||
btnList[i].gameObject.GetComponent<SpriteRenderer>().enabled = false;
|
||
this.gameObject.GetComponent<SpriteRenderer>().enabled = true;
|
||
}
|
||
|
||
public void ConnectWith3DSwitchHorizontal()
|
||
{
|
||
Transform[] btnList = this.transform.parent.gameObject.GetComponentsInChildren<Transform>();
|
||
string currentSw3DHname = this.name.Substring(0, this.name.Length - 1) + "3D";
|
||
GameObject currentSw3DH = GameObject.Find(currentSw3DHname);
|
||
Switch3DHRotate sw3DHrotate = currentSw3DH.GetComponent<Switch3DHRotate>();
|
||
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);
|
||
}
|
||
|
||
}
|