Files
MI-38/Heli_with_panels/Assets/Scripts/Panel2D/SwitchHoldState.cs
2022-07-04 13:15:35 +03:00

87 lines
3.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}