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

132 lines
5.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ColliderIgnore : MonoBehaviour
{
/* Collider2D[] colliders;
[ContextMenuItem("0115", "On0115")]
// [ContextMenuItem("0107", "On0107")]
// [ContextMenuItem("0108", "On0108")]
// [ContextMenuItem("0124", "On0124")]
// [ContextMenuItem("0125", "On0125")]
[ContextMenuItem("0112", "On0112")]
[ContextMenuItem("0114", "On0114")]
[ContextMenuItem("0117", "On0117")]
[ContextMenuItem("0204", "On0204")]
[ContextMenuItem("0207", "On0207")]
[ContextMenuItem("0601", "On0601")]
[ContextMenuItem("0507", "On0507")]
[SerializeField] private string[] nameColliders;
void On0115() => nameColliders = new string[] { "Arrow0115", "Button2_0115", "RotateAvia", "index0115", "TextBarPressure", "Frame2Text_115", "Frame2_0115", "Frame3Text115", "Frame3_0115", "Frame4_0115", "Frame4Text", "Poplavok0115" };
//void On0107() => nameColliders = new string[] { "Handle4_0107", "Handle5_0107" };
//void On0108() => nameColliders = new string[] { "Handle4_0108", "Handle5_0108" };
//void On0124() => nameColliders = new string[] { "Handle4_0124", "Handle5_0124" };
//void On0125() => nameColliders = new string[] { "Handle4_0125", "Handle5_0125" };
void On0112() => nameColliders = new string[] { "handle0112", "blenker0112_1", "blenker0112_2", "airPlane0112", "poplavok0112" };
void On0114() => nameColliders = new string[] { "Arrow0114", "Scale1_0114_2", "Scale1_0114_1" };
void On0117() => nameColliders = new string[] { "arrow1_0117_4", "arrow1_0117_3", "arrow1_0117_2", "arrow2_0117_2" };
void On0204() => nameColliders = new string[] { "Handle1_0204_2", "Handle2_0204_2" };
void On0207() => nameColliders = new string[] { "Handle1_0207_2", "Handle2_0207_2" };
void On0601() => nameColliders = new string[] { "bazatop_0601" };
void On0507() => nameColliders = new string[] { "Button1_0507_1", "Button2_0507_1", "Button3_0507_1" };
private void Awake()
{
colliders = transform.parent.GetComponentsInChildren<Collider2D>();
//nameColliders = new string[] { "Button2_0115", "RotateAvia", "index0115", "TextBarPressure", "Frame2Text_115", "Frame2_0115", "Frame3Text115", "Frame3_0115", "Frame4_0115", "Frame4Text", "Poplavok0115" };
for (int k = 0; k < nameColliders.Length; k++)
{
for (int i = 0; i < colliders.Length; i++)
{
if (colliders[i].name == nameColliders[k] && colliders[i].gameObject.GetComponent<ExitColliderIgnore>() == null)
{
colliders[i].gameObject.AddComponent<ExitColliderIgnore>();
colliders[i].gameObject.GetComponent<ExitColliderIgnore>().pan = this.gameObject.GetComponent<ColliderIgnore>();
}
}
}
}
private void Start()
{
//cam = GameObject.Find("Camera").GetComponent<Camera>();
if (man == null) man = GameObject.Find("Manager").GetComponent<Manager>();
cam = man.cam;
}
public void OnMouseEnter()
{
ChangeColliderIgnore(false);
}
public void OnMouseExit()
{
ChangeColliderIgnore(true);
}
public void ChangeColliderIgnore(bool enableCollider, string colliderTrue)
{
if (enableCollider)
{
for (int i = 0; i < colliders.Length; i++)
{
colliders[i].enabled = enableCollider;
}
}
else
{
for (int k = 0; k < nameColliders.Length; k++)
{
for (int i = 0; i < colliders.Length; i++)
{
if (colliders[i].name != colliderTrue)
{
colliders[i].enabled = enableCollider;
}
else
{
colliders[i].enabled = true;
}
}
}
}
}
Camera cam;
Manager man;
void Update()
{
if (!cam.gameObject.activeSelf) return;
Vector2 CurMousePos = cam.ScreenToWorldPoint(Input.mousePosition);
if (Input.GetMouseButtonUp(0))
{
RaycastHit2D[] allHits = Physics2D.RaycastAll(CurMousePos, Vector2.zero);
bool flag = true;
for (int k = 0; k < nameColliders.Length; k++)
{
for (int i = 0; i < allHits.Length; i++)
{
if (allHits[i].transform.name != nameColliders[k])
{
ChangeColliderIgnore(flag, "");
// Debug.Log($"flag = {flag} allHits[i].transform.name = {allHits[i].transform.name}");
}
else
{
flag = false;
ChangeColliderIgnore(flag, nameColliders[k]);
//Debug.Log($"flag = {flag} allHits[i].transform.name = {allHits[i].transform.name}");
break;
}
}
if (!flag) break;
}
}
}*/
}