ND_SimulationAutomaticControl/Assets/Scripts/Line/LineManager.cs

295 lines
11 KiB
C#
Raw Blame History

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;
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 = "<22><><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>";
StartCoroutine(WaitHide(Tips));
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </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("<22><><EFBFBD><EFBFBD>"))
{
//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;
}
}
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.<EFBFBD><EFBFBD>12V && line2.interfaceType != InterfaceType.<EFBFBD><EFBFBD>12V ||
line2.interfaceType == InterfaceType.<EFBFBD><EFBFBD>12V && line1.interfaceType != InterfaceType.<EFBFBD><EFBFBD>12V)
{
TipTexts.text = "<22><><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>-12VӦ<56><D3A6><EFBFBD><EFBFBD>-12V<32><56><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
return false;
}
else if (line1.interfaceType == InterfaceType.<EFBFBD><EFBFBD>12V && line2.interfaceType != InterfaceType.<EFBFBD><EFBFBD>12V
|| line2.interfaceType == InterfaceType.<EFBFBD><EFBFBD>12V && line1.interfaceType != InterfaceType.<EFBFBD><EFBFBD>12V
)
{
TipTexts.text = "<22><><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>12VӦ<56><D3A6><EFBFBD><EFBFBD>12V<32><56><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
return false;
}
//else if (line1.interfaceType == InterfaceType.<2E><>V && line2.interfaceType != InterfaceType.GND
// || line2.interfaceType == InterfaceType.GND && line1.interfaceType != InterfaceType.<2E><>V)
//{
// TipTexts.text = "<22><><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>0VӦ<56><D3A6><EFBFBD><EFBFBD>GND<4E><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
// // 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 = "<22><><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>200KӦ<4B><D3A6><EFBFBD><EFBFBD>OUT1<54><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
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 = "<22><><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>OUT1Ӧ<31><D3A6><EFBFBD><EFBFBD>IN4<4E><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
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 = "<22><><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>AD1Ӧ<31><D3A6><EFBFBD><EFBFBD>OUT2<54><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
return false;
}
else if ((line1.interfaceType == InterfaceType.<EFBFBD><EFBFBD>V && (line2.interfaceType != InterfaceType.GND && line2.interfaceType != InterfaceType.III)
|| line2.interfaceType == InterfaceType.GND && line1.interfaceType != InterfaceType.<EFBFBD><EFBFBD>V)
)
{
TipTexts.text = "<22><><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>0VӦ<56><D3A6><EFBFBD><EFBFBD>GND<4E><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
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 = "<22><><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>OUTӦ<54><D3A6><EFBFBD><EFBFBD>IN1<4E><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
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 = "<22><><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>AD2Ӧ<32><D3A6><EFBFBD><EFBFBD>IN1<4E><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
LineShowModel.Instance.DeleteWiresByCollider(line1.gameObject);
return false;
}
else if (line1.IsNotLine == true || line2.IsNotLine == true)
{
TipTexts.text = "<22><><EFBFBD>Ӵ<EFBFBD><D3B4>󣬲<EFBFBD><F3A3ACB2><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
// 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('<EFBFBD><EFBFBD>');
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>();
}