ND_SimulationAutomaticControl/Assets/Scripts/Line/LineManager.cs

180 lines
7.6 KiB
C#
Raw 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;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class LineManager : MonoBehaviour
{
public static LineManager instance;
public Transform point1;
public Transform point2;
public GameObject Tips;
public TextMeshProUGUI TipTexts;
private void Awake()
{
instance = this;
}
void Start()
{
//// 测试连接
//TestConnection(InterfaceType.IN1, InterfaceType.OUT1); // 应该正确
//TestConnection(InterfaceType.IN1, InterfaceType.GND); // 应该错误
//TestConnection(InterfaceType.正12V, InterfaceType.GND); // 应该正确
//TestConnection(InterfaceType._1uF_star, InterfaceType._1uF_end); // 应该正确
}
void Update()
{
if (Input.GetMouseButtonDown(2))
{
point1 = null;
point2 = null;
}
}
/// <summary>
/// 鼠标点击的物体
/// </summary>
/// <param name="point"></param>
public void ClickPoint(Transform point)
{
if (point1 != null)
{
point2 = point;
}
if (point1 == null)
{
point1 = point;
}
if (point1 != null && point2 != null)
{
StartCoroutine(Checkconnection(point1, point2));
}
}
IEnumerator Checkconnection(Transform transform, Transform transform2)
{
LineConnect line = transform.GetComponent<LineConnect>();
LineConnect line2 = transform2.GetComponent<LineConnect>();
if (line != null && line2 != null)
{
if (!JudgmentLine(line, line2))
{
Tips.SetActive(true);
yield return new WaitForSeconds(2);
Tips.SetActive(false);
}
}
}
public bool JudgmentLine(LineConnect line1, LineConnect line2)
{
Init();
if (line1.interfaceType == InterfaceType.12V && line2.interfaceType != InterfaceType.12V ||
line2.interfaceType == InterfaceType.12V && line1.interfaceType != InterfaceType.12V)
{
TipTexts.text = "连接错误,-12V应该与-12V相连";
//WireDrawingSystem.instance.currentState = WireDrawingSystem.DrawingState.Idle;
WireDrawingSystem.instance.HandleDelete();
WireDrawingSystem.instance.ClearSnapPreview();
return false;
}
else if (line1.interfaceType == InterfaceType.12V && line2.interfaceType != InterfaceType.12V
|| line2.interfaceType == InterfaceType.12V && line1.interfaceType != InterfaceType.12V
)
{
TipTexts.text = "连接错误12V应该与12V相连";
//WireDrawingSystem.instance.currentState = WireDrawingSystem.DrawingState.Idle;
WireDrawingSystem.instance.HandleDelete();
WireDrawingSystem.instance.ClearSnapPreview();
return false;
}
else if (line1.interfaceType == InterfaceType.V && line2.interfaceType != InterfaceType.GND
|| line2.interfaceType == InterfaceType.GND && line1.interfaceType != InterfaceType.V)
{
TipTexts.text = "连接错误0V应该与GND相连";
// WireDrawingSystem.instance.currentState = WireDrawingSystem.DrawingState.Idle;
WireDrawingSystem.instance.HandleDelete();
WireDrawingSystem.instance.ClearSnapPreview();
return false;
}
else if (line1.interfaceType == InterfaceType.IN2_200K && line2.interfaceType != InterfaceType.OUT1
|| line2.interfaceType == InterfaceType.IN2_200K && line1.interfaceType != InterfaceType.OUT1)
{
TipTexts.text = "连接错误200K应该与OUT1相连";
//WireDrawingSystem.instance.currentState = WireDrawingSystem.DrawingState.Idle;
WireDrawingSystem.instance.HandleDelete();
WireDrawingSystem.instance.ClearSnapPreview();
return false;
}
else if (line1.interfaceType == InterfaceType.OUT1 && line2.interfaceType != InterfaceType.IN4
|| line2.interfaceType == InterfaceType.OUT1 && line1.interfaceType != InterfaceType.IN4)
{
TipTexts.text = "连接错误OUT1应该与IN4相连";
// WireDrawingSystem.instance.currentState = WireDrawingSystem.DrawingState.Idle;
WireDrawingSystem.instance.HandleDelete();
WireDrawingSystem.instance.ClearSnapPreview();
return false;
}
else if (line1.interfaceType == InterfaceType.AD1 && line2.interfaceType != InterfaceType.OUT2
|| line2.interfaceType == InterfaceType.AD1 && line1.interfaceType != InterfaceType.OUT2)
{
TipTexts.text = "连接错误200K应该与OUT1相连";
//WireDrawingSystem.instance.currentState = WireDrawingSystem.DrawingState.Idle;
WireDrawingSystem.instance.HandleDelete();
WireDrawingSystem.instance.ClearSnapPreview();
return false;
}
else if (line1.interfaceType == InterfaceType.V && line2.interfaceType != InterfaceType.GND
|| line2.interfaceType == InterfaceType.GND && line1.interfaceType != InterfaceType.V)
{
TipTexts.text = "连接错误0V应该与GND相连";
//WireDrawingSystem.instance.currentState = WireDrawingSystem.DrawingState.Idle;
WireDrawingSystem.instance.HandleDelete();
WireDrawingSystem.instance.ClearSnapPreview();
return false;
}
else if (line1.interfaceType == InterfaceType.OUT && line2.interfaceType != InterfaceType.IN1
|| line2.interfaceType == InterfaceType.OUT && line1.interfaceType != InterfaceType.IN1)
{
TipTexts.text = "连接错误OUT应该与IN1相连";
// WireDrawingSystem.instance.currentState = WireDrawingSystem.DrawingState.Idle;
WireDrawingSystem.instance.HandleDelete();
WireDrawingSystem.instance.ClearSnapPreview();
return false;
}
else if (line1.interfaceType == InterfaceType.AD2 && line2.interfaceType != InterfaceType.IN1
|| line2.interfaceType == InterfaceType.AD2 && line1.interfaceType != InterfaceType.IN1)
{
TipTexts.text = "连接错误OUT应该与IN1相连";
// WireDrawingSystem.instance.currentState = WireDrawingSystem.DrawingState.Idle;
WireDrawingSystem.instance.HandleDelete();
WireDrawingSystem.instance.ClearSnapPreview();
return false;
}
else if ((line1.interfaceType != InterfaceType.AD2 || line1.interfaceType != InterfaceType.OUT || line1.interfaceType != InterfaceType.V
|| line1.interfaceType != InterfaceType.AD1 || line1.interfaceType != InterfaceType.OUT1 || line1.interfaceType != InterfaceType.IN2_200K ||
line1.interfaceType != InterfaceType.12V || line1.interfaceType != InterfaceType.12V) && (line2.interfaceType != InterfaceType.AD2 || line2.interfaceType != InterfaceType.OUT || line2.interfaceType != InterfaceType.V
|| line2.interfaceType != InterfaceType.AD1 || line2.interfaceType != InterfaceType.OUT1 || line2.interfaceType != InterfaceType.IN2_200K ||
line2.interfaceType != InterfaceType.12V || line2.interfaceType != InterfaceType.12V))
{
TipTexts.text = "连接错误,不需要此连线";
// WireDrawingSystem.instance.currentState = WireDrawingSystem.DrawingState.Idle;
WireDrawingSystem.instance.HandleDelete();
WireDrawingSystem.instance.ClearSnapPreview();
return false;
}
else
{
return true;
}
}
public void Init()
{
point2 = null;
point1 = null;
}
}