mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 02:45:39 +03:00
04.07.2022
This commit is contained in:
89
Heli_with_panels/Assets/Scripts/Panel2D/SwitchState.cs
Normal file
89
Heli_with_panels/Assets/Scripts/Panel2D/SwitchState.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SwitchState : MonoBehaviour
|
||||
{
|
||||
//public Switch3DRotate sw3Drotate;
|
||||
public Switch3DHRotate sw3DHrotate;
|
||||
Manager man;
|
||||
|
||||
void Start()
|
||||
{
|
||||
//sw3Drotate = FindObjectOfType<Switch3DRotate>();
|
||||
// Debug.Log(sw3Drotate + " объекты" );
|
||||
man = GameObject.Find("Manager").GetComponent<Manager>();
|
||||
}
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
if (man.mode == "scedit" || man.mode == "play")
|
||||
return;
|
||||
Transform[] btnList = this.transform.parent.gameObject.GetComponentsInChildren<Transform>();
|
||||
for (int i = 0; i < btnList.Length; i++)
|
||||
{
|
||||
if (i == 0) continue;
|
||||
if(btnList[i].gameObject.GetComponent<Image>()!=null)
|
||||
btnList[i].gameObject.GetComponent<Image>().enabled = false;
|
||||
else
|
||||
btnList[i].gameObject.GetComponent<SpriteRenderer>().enabled = false;
|
||||
}
|
||||
//this.gameObject.GetComponent<Image>().enabled = true;
|
||||
if (this.gameObject.GetComponent<Image>() != null)
|
||||
this.gameObject.GetComponent<Image>().enabled = true;
|
||||
else
|
||||
this.gameObject.GetComponent<SpriteRenderer>().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<Transform>();
|
||||
string currentSw3Dname = this.name.Substring(0, this.name.Length - 1) + "3D";
|
||||
GameObject currentSw3D = GameObject.Find(currentSw3Dname);
|
||||
Switch3DRotate sw3Drotate = currentSw3D.GetComponent<Switch3DRotate>();
|
||||
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<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);
|
||||
}
|
||||
|
||||
public void switchOn()
|
||||
{
|
||||
Transform[] btnList = this.transform.parent.gameObject.GetComponentsInChildren<Transform>();
|
||||
for (int i = 0; i < btnList.Length; i++)
|
||||
{
|
||||
if (i == 0) continue;
|
||||
if (btnList[i].gameObject.GetComponent<Image>() != null)
|
||||
btnList[i].gameObject.GetComponent<Image>().enabled = false;
|
||||
else
|
||||
btnList[i].gameObject.GetComponent<SpriteRenderer>().enabled = false;
|
||||
}
|
||||
//this.gameObject.GetComponent<Image>().enabled = true;
|
||||
if (this.gameObject.GetComponent<Image>() != null)
|
||||
this.gameObject.GetComponent<Image>().enabled = true;
|
||||
else
|
||||
this.gameObject.GetComponent<SpriteRenderer>().enabled = true;
|
||||
//GetComponent<Switch3DRotate>().pos = btnList.Length;
|
||||
//GetComponent<Switch3DRotate>().numpos = int.Parse(this.name.Substring(this.name.Length - 1));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user