300 lines
11 KiB
C#
300 lines
11 KiB
C#
using DG.Tweening;
|
||
using HighlightPlus;
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Drawing;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
|
||
public class LineManager : MonoBehaviour
|
||
{
|
||
public static LineManager instance;
|
||
public Transform point1;
|
||
public Transform point2;
|
||
public GameObject Tips;
|
||
public TextMeshProUGUI TipTexts;
|
||
public List<GameObject> Models = new List<GameObject>();
|
||
LineData lineData = new LineData();
|
||
public GameObject Lights;
|
||
/// <summary>
|
||
/// ¸ßÁÁ°å
|
||
/// </summary>
|
||
public HighlightEffect LightPanel;
|
||
public List<HighlightEffect> Highlights = new List<HighlightEffect>();
|
||
|
||
public List<HighlightEffect> Highlights_Backup = new List<HighlightEffect>();
|
||
|
||
public int hightindext = 0;
|
||
|
||
public string line1;
|
||
public string line2;
|
||
private void Awake()
|
||
{
|
||
instance = this;
|
||
PlayerPrefs.SetString("LineData", "");
|
||
}
|
||
void Start()
|
||
{
|
||
Initialization();
|
||
}
|
||
private void Initialization()
|
||
{
|
||
if (PlayerPrefs.GetString("LineData") != "")
|
||
{
|
||
lineData = JsonConvert.DeserializeObject<LineData>(PlayerPrefs.GetString("LineData"));
|
||
|
||
for (int i = 0; i < lineData.Modelname.Count; i++)
|
||
{
|
||
for (int j = 0; j < Models.Count; j++)
|
||
{
|
||
if (lineData.Modelname[i].Contains(Models[j].name))
|
||
{
|
||
Models[j].SetActive(true);
|
||
}
|
||
if (lineData.Modelname[i].Equals(Models[j].name) && Models[j].name.Equals("diannaoxian"))
|
||
{
|
||
Models[j].transform.DOLocalMove(new Vector3(-0.56f, -0.293f, -0.163f), 0.5f);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
for (int i = 0; i < Highlights.Count; i++)
|
||
{
|
||
if (i != 0)
|
||
{
|
||
Highlights[i].highlighted = false;
|
||
}
|
||
}
|
||
}
|
||
bool isshow;
|
||
void Update()
|
||
{
|
||
if (Input.GetMouseButtonDown(2))
|
||
{
|
||
point1 = null;
|
||
point2 = null;
|
||
PlayerPrefs.SetString("LineData", "");
|
||
}
|
||
if (allline >= Models.Count && !isshow)
|
||
{
|
||
isshow = true;
|
||
TipTexts.text = "ÏßÒÑÈ«²¿Á¬½Ó£¡";
|
||
StartCoroutine(WaitHide(Tips));
|
||
}
|
||
}
|
||
/// <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));
|
||
//}
|
||
if (point.name.Equals("diannaoxian"))
|
||
{
|
||
if (!lineData.Modelname.Contains(point.name))
|
||
{
|
||
allline++;
|
||
lineData.Modelname.Add(point.name);
|
||
string json = JsonConvert.SerializeObject(lineData);
|
||
PlayerPrefs.SetString("LineData", json);
|
||
}
|
||
point.DOLocalMove(new Vector3(-0.56f, -0.293f, -0.163f), 0.5f);
|
||
}
|
||
|
||
if (point.name.Equals("¿ª¹Ø"))
|
||
{
|
||
//if (!lineData.Modelname.Contains(point.name))
|
||
//{
|
||
// allline++;
|
||
// lineData.Modelname.Add(point.name);
|
||
// string json = JsonConvert.SerializeObject(lineData);
|
||
// PlayerPrefs.SetString("LineData", json);
|
||
//}
|
||
point.DORotateQuaternion(Quaternion.Euler(-17f, 0, 0), 0.5f);
|
||
}
|
||
if (point.name.Equals("Õ¢"))
|
||
{
|
||
//if (!lineData.Modelname.Contains(point.name))
|
||
//{
|
||
// allline++;
|
||
// lineData.Modelname.Add(point.name);
|
||
// string json = JsonConvert.SerializeObject(lineData);
|
||
// PlayerPrefs.SetString("LineData", json);
|
||
//}
|
||
Material material = Lights.GetComponent<MeshRenderer>().material;
|
||
material.EnableKeyword("_EMISSION");
|
||
material.color = UnityEngine.Color.red;
|
||
point.DORotateQuaternion(Quaternion.Euler(-50f, 0, 0), 0.5f);
|
||
}
|
||
for (int i = 0; i < Highlights.Count; i++)
|
||
{
|
||
if (Highlights[i].name.Equals(point.name))
|
||
{
|
||
hightindext = i;
|
||
Highlights[i].highlighted = false;
|
||
Highlights.Remove(Highlights[i]);
|
||
break;
|
||
}
|
||
}
|
||
if (hightindext < Highlights.Count)
|
||
{
|
||
Highlights[hightindext].highlighted = true;
|
||
Highlights[hightindext].GetComponent<BoxCollider>().enabled = true;
|
||
}
|
||
LightPanel.highlighted = false;
|
||
}
|
||
|
||
public 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))
|
||
{
|
||
yield return null;
|
||
StartCoroutine(WaitHide(Tips));
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
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ÏàÁ¬£¡";
|
||
LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
|
||
return false;
|
||
}
|
||
else if (line1.interfaceType == InterfaceType.Õý12V && line2.interfaceType != InterfaceType.Õý12V
|
||
|| line2.interfaceType == InterfaceType.Õý12V && line1.interfaceType != InterfaceType.Õý12V
|
||
)
|
||
{
|
||
TipTexts.text = "Á¬½Ó´íÎó£¬12VÓ¦¸ÃÓë12VÏàÁ¬£¡";
|
||
LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
|
||
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();
|
||
// LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
|
||
// 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ÏàÁ¬£¡";
|
||
LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
|
||
return false;
|
||
}
|
||
else if (line1.interfaceType == InterfaceType.OUT1 && (line2.interfaceType != InterfaceType.IN4 && line2.interfaceType != InterfaceType.IN2_200K)
|
||
|| line2.interfaceType == InterfaceType.OUT1 && line1.interfaceType != InterfaceType.IN4)
|
||
{
|
||
TipTexts.text = "Á¬½Ó´íÎó£¬OUT1Ó¦¸ÃÓëIN4ÏàÁ¬£¡";
|
||
LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
|
||
return false;
|
||
}
|
||
else if (line1.interfaceType == InterfaceType.AD1 && line2.interfaceType != InterfaceType.OUT2
|
||
|| line2.interfaceType == InterfaceType.AD1 && line1.interfaceType != InterfaceType.OUT2)
|
||
{
|
||
TipTexts.text = "Á¬½Ó´íÎó£¬AD1Ó¦¸ÃÓëOUT2ÏàÁ¬£¡";
|
||
LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
|
||
return false;
|
||
}
|
||
else if ((line1.interfaceType == InterfaceType.ÁãV && (line2.interfaceType != InterfaceType.GND && line2.interfaceType != InterfaceType.III)
|
||
|| line2.interfaceType == InterfaceType.GND && line1.interfaceType != InterfaceType.ÁãV)
|
||
)
|
||
{
|
||
TipTexts.text = "Á¬½Ó´íÎó£¬0VÓ¦¸ÃÓëGNDÏàÁ¬£¡";
|
||
LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
|
||
return false;
|
||
}
|
||
else if (line1.interfaceType == InterfaceType.OUT && line2.interfaceType != InterfaceType.IN1
|
||
|| line2.interfaceType == InterfaceType.OUT && line1.interfaceType != InterfaceType.IN1)
|
||
{
|
||
TipTexts.text = "Á¬½Ó´íÎó£¬OUTÓ¦¸ÃÓëIN1ÏàÁ¬£¡";
|
||
LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
|
||
return false;
|
||
}
|
||
else if (line1.interfaceType == InterfaceType.AD2 && line2.interfaceType != InterfaceType.IN1
|
||
|| line2.interfaceType == InterfaceType.AD2 && line1.interfaceType != InterfaceType.IN1)
|
||
{
|
||
TipTexts.text = "Á¬½Ó´íÎó£¬AD2Ó¦¸ÃÓëIN1ÏàÁ¬£¡";
|
||
LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
|
||
return false;
|
||
}
|
||
else if (line1.IsNotLine == true || line2.IsNotLine == true)
|
||
{
|
||
TipTexts.text = "Á¬½Ó´íÎ󣬲»ÐèÒª´ËÁ¬Ïß";
|
||
// WireDrawingSystem.instance.currentState = WireDrawingSystem.DrawingState.Idle;
|
||
//WireDrawingSystem.instance.HandleDelete();
|
||
//WireDrawingSystem.instance.ClearSnapPreview();
|
||
LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
|
||
return false;
|
||
}
|
||
else
|
||
{
|
||
for (int i = 0; i < Models.Count; i++)
|
||
{
|
||
string[] splitname = Models[i].name.Split('Á¬');
|
||
if (splitname[0] == line1.interfaceType.ToString() && splitname[1] == line2.interfaceType.ToString() ||
|
||
splitname[0] == line2.interfaceType.ToString() && splitname[1] == line1.interfaceType.ToString())
|
||
{
|
||
if (!lineData.Modelname.Contains(Models[i].name))
|
||
{
|
||
allline++;
|
||
lineData.Modelname.Add(Models[i].name);
|
||
string json = JsonConvert.SerializeObject(lineData);
|
||
PlayerPrefs.SetString("LineData", json);
|
||
}
|
||
Models[i].SetActive(true);
|
||
}
|
||
|
||
}
|
||
LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
|
||
return true;
|
||
}
|
||
}
|
||
int allline = 0;
|
||
public void Init()
|
||
{
|
||
point2 = null;
|
||
point1 = null;
|
||
}
|
||
|
||
IEnumerator WaitHide(GameObject game)
|
||
{
|
||
game.SetActive(true);
|
||
yield return new WaitForSeconds(1.5f);
|
||
game.SetActive(false);
|
||
}
|
||
}
|
||
|
||
public class LineData
|
||
{
|
||
public List<string> Modelname = new List<string>();
|
||
}
|