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

139 lines
5.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CoverState : MonoBehaviour
{
public Cover3DVrotate cw3DVrotate;
public Cover3DHrotate cw3DHrotate;
Manager man;
public void Start()
{
man = GameObject.Find("Manager").GetComponent<Manager>();
}
void OnMouseDown()
{
if (man.mode == "scedit" || man.mode == "play")
return;
switchOn();
//Switch3DVrotate sw3DVrotate = this.GetComponent<Switch3DVrotate>();
/* 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<SpriteRenderer>() != null)
{
btnList[i].gameObject.GetComponent<SpriteRenderer>().enabled = true;
btnList[i].gameObject.GetComponent<BoxCollider2D>().enabled = true;
}
if (btnList[i].gameObject.GetComponent<Image>() != null)
{
btnList[i].gameObject.GetComponent<Image>().enabled = true;
btnList[i].gameObject.GetComponent<BoxCollider2D>().enabled = true;
}
}
if (this.gameObject.GetComponent<SpriteRenderer>() != null)
{
this.gameObject.GetComponent<SpriteRenderer>().enabled = false;
this.gameObject.GetComponent<BoxCollider2D>().enabled = false;
}
else
if (this.gameObject.GetComponent<Image>() != null)
{
this.gameObject.GetComponent<Image>().enabled = false;
this.gameObject.GetComponent<BoxCollider2D>().enabled = false;
}*/
}
public void switchOn()
{
Transform[] btnList = this.transform.parent.gameObject.GetComponentsInChildren<Transform>();
for (int i = 1; i < btnList.Length; i++)
{
//if (i == 0) continue;
if (btnList[i].gameObject.GetComponent<SpriteRenderer>() != null)
{
btnList[i].gameObject.GetComponent<SpriteRenderer>().enabled = true;
btnList[i].gameObject.GetComponent<BoxCollider2D>().enabled = true;
}
else
if (btnList[i].gameObject.GetComponent<Image>() != null)
{
btnList[i].gameObject.GetComponent<Image>().enabled = true;
btnList[i].gameObject.GetComponent<BoxCollider2D>().enabled = true;
}
}
//this.gameObject.GetComponent<Image>().enabled = true;
if (this.gameObject.GetComponent<SpriteRenderer>() != null)
{
this.gameObject.GetComponent<SpriteRenderer>().enabled = false;
this.gameObject.GetComponent<BoxCollider2D>().enabled = false;
ConnectWith3d();
ConnectWith3dh();
}
else
if (this.gameObject.GetComponent<Image>() != null)
{
this.gameObject.GetComponent<Image>().enabled = false;
this.gameObject.GetComponent<BoxCollider2D>().enabled = false;
ConnectWith3d();
ConnectWith3dh();
}
if(man == null) man = GameObject.Find("Manager").GetComponent<Manager>();
// частные случаи работы крышек, переключателей и др., не предусматриваемые механикой файла objects.xml - короче "костыли"
if (this.transform.parent.gameObject.name == "Cover1_0502" && this.gameObject.name.EndsWith("_2"))
man.objects.Find("Tumbler2_0502").SetObjectState(2);
if (this.transform.parent.gameObject.name == "Cover2_0511" && this.gameObject.name.EndsWith("_2"))
man.objects.Find("Tumbler2_0511").SetObjectState(0);
}
public void ConnectWith3d()
{
string currentSw3Dname = this.transform.parent.name.Substring(0, transform.parent.name.Length) + "_3D";
GameObject currentSw3D = GameObject.Find(currentSw3Dname);
if (currentSw3D != null)
{
Cover3DVrotate cw3DVrotate = currentSw3D.GetComponent<Cover3DVrotate>();
if (cw3DVrotate != null)
cw3DVrotate.Rotate(int.Parse(this.name.Substring(this.name.Length - 1)));
}
}
public void ConnectWith3dh()
{
string currentSw3DHname = this.transform.parent.name.Substring(0, transform.parent.name.Length) + "_3D";
//Debug.Log(currentSw3DHname);
GameObject currentSw3DH = GameObject.Find(currentSw3DHname);
if (currentSw3DH != null)
{
Cover3DHrotate cw3DHrotate = currentSw3DH.GetComponent<Cover3DHrotate>();
if (cw3DHrotate != null)
cw3DHrotate.RotateH(int.Parse(this.name.Substring(this.name.Length - 1)));
}
}
}