363 lines
12 KiB
C#
363 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
namespace DongWuYiXue.DaoNiaoShu
|
|
{
|
|
public class PointLineManager : MonoBehaviour
|
|
{
|
|
#region 修改逻辑前脚本 暂未删除
|
|
//List<Point> points = new();
|
|
//List<Line> lines = new();
|
|
//public Line m_LinePfb;
|
|
//public RectTransform m_LineCon;
|
|
//public Color color;
|
|
//private List<Point> selectPoints = new();
|
|
//private void Start()
|
|
//{
|
|
// points = GetComponentsInChildren<Point>().ToList();
|
|
// for (int i = 0; i < points.Count; i++)
|
|
// {
|
|
// points[i].Init(this);
|
|
// }
|
|
//}
|
|
///// <summary>
|
|
///// 画线
|
|
///// </summary>
|
|
//public void DrawLine(Point p)
|
|
//{
|
|
// selectPoints.Add(p);
|
|
// if (selectPoints.Count == 2 && selectPoints[0].group != selectPoints[1].group)//凑齐两点,且两点不同区域
|
|
// {
|
|
// if (TwoPointsAlreadyConnected(selectPoints))//两点之间是否已经连线
|
|
// {
|
|
// UnselectPoints();
|
|
// return;
|
|
// }
|
|
// if (OnePointsAlreadyConnected(selectPoints[0]) && OnePointsAlreadyConnected(selectPoints[1]))//两点是否都与第三点有连线
|
|
// {
|
|
// if (selectPoints[0].multip && selectPoints[1].multip)
|
|
// {
|
|
// CreateLine(selectPoints[0], selectPoints[1]);
|
|
// }
|
|
// UnselectPoints();
|
|
// return;
|
|
// }
|
|
// if (OnePointsAlreadyConnected(selectPoints[0]))//点1是否都与第三点有连线
|
|
// {
|
|
// if (selectPoints[0].multip)
|
|
// {
|
|
// CreateLine(selectPoints[0], selectPoints[1]);
|
|
// }
|
|
// UnselectPoints();
|
|
// return;
|
|
// }
|
|
// if (OnePointsAlreadyConnected(selectPoints[1]))//点2是否都与第三点有连线
|
|
// {
|
|
// if (selectPoints[1].multip)
|
|
// {
|
|
// CreateLine(selectPoints[0], selectPoints[1]);
|
|
// }
|
|
// UnselectPoints();
|
|
// return;
|
|
// }
|
|
// CreateLine(selectPoints[0], selectPoints[1]);
|
|
// UnselectPoints();
|
|
// return;
|
|
// }
|
|
// if (selectPoints.Count == 2 && selectPoints[0].group == selectPoints[1].group)//凑齐两点,且两点同一区域
|
|
// {
|
|
// UnselectPoints();
|
|
// p.Select();
|
|
// selectPoints.Add(p);
|
|
// return;
|
|
// }
|
|
//}
|
|
///// <summary>
|
|
///// 两点之间是否已经有连线
|
|
///// </summary>
|
|
//public bool TwoPointsAlreadyConnected(List<Point> p)
|
|
//{
|
|
// for (int i = 0; i < lines.Count; i++)
|
|
// {
|
|
// if (lines[i].points.SequenceEqual(p))
|
|
// {
|
|
// return true;
|
|
// }
|
|
// }
|
|
// return false;
|
|
//}
|
|
///// <summary>
|
|
///// 一点是否已经连线
|
|
///// </summary>
|
|
//public bool OnePointsAlreadyConnected(Point p)
|
|
//{
|
|
// for (int i = 0; i < lines.Count; i++)
|
|
// {
|
|
// if (lines[i].points.Contains(p))
|
|
// {
|
|
// return true;
|
|
// }
|
|
// }
|
|
// return false;
|
|
//}
|
|
///// <summary>
|
|
///// 取消所有点击
|
|
///// </summary>
|
|
//public void UnselectPoints()
|
|
//{
|
|
// for (int i = 0; i < selectPoints.Count; i++)
|
|
// {
|
|
// selectPoints[i].UnSelect();
|
|
// }
|
|
// selectPoints.Clear();
|
|
//}
|
|
///// <summary>
|
|
///// 创建⼀条两点之间的线
|
|
///// </summary>
|
|
//private void CreateLine(Point p1, Point p2)
|
|
//{
|
|
// //实例化需要显⽰的线段图⽚pfb
|
|
// Line line = DrawLineTool.DrawLine(p1.transform.position, p2.transform.position, color, m_LineCon).GetComponent<Line>();
|
|
// line.AddPoint(p1);
|
|
// line.AddPoint(p2);
|
|
// line.gameObject.SetActive(true);
|
|
// lines.Add(line);
|
|
//}
|
|
///// <summary>
|
|
///// 清除线
|
|
///// </summary>
|
|
//public void ClearLine()
|
|
//{
|
|
// for (int i = 0; i < lines.Count; i++)
|
|
// {
|
|
// Destroy(lines[i].gameObject);
|
|
// }
|
|
// lines.Clear();
|
|
//}
|
|
///// <summary>
|
|
///// 判断对错
|
|
///// </summary>
|
|
//public bool JudgeLine()
|
|
//{
|
|
// bool trueOrFalse = true;
|
|
// for (int i = 0; i < lines.Count; i++)
|
|
// {
|
|
// if (lines[i].Judge())
|
|
// {
|
|
// lines[i].Correct();
|
|
// }
|
|
// else
|
|
// {
|
|
// lines[i].Error();
|
|
// trueOrFalse = false;
|
|
// }
|
|
// }
|
|
// for (int i = 0; i < points.Count; i++)
|
|
// {
|
|
// Point p = points[i];
|
|
// if (p.answers != null && !OnePointsAlreadyConnected(p))
|
|
// {
|
|
// trueOrFalse = false;
|
|
// }
|
|
// }
|
|
// return trueOrFalse;
|
|
//}
|
|
///// <summary>
|
|
///// 禁用按钮
|
|
///// </summary>
|
|
//public void ButtonForbidden()
|
|
//{
|
|
// for (int i = 0; i < points.Count; i++)
|
|
// {
|
|
// points[i].btn.interactable = false;
|
|
// }
|
|
//}
|
|
///// <summary>
|
|
///// 启用按钮
|
|
///// </summary>
|
|
//public void ButtonOnEnable()
|
|
//{
|
|
// for (int i = 0; i < points.Count; i++)
|
|
// {
|
|
// points[i].btn.interactable = true;
|
|
// }
|
|
//}
|
|
#endregion
|
|
|
|
List<Point> points = new();
|
|
List<Line> lines = new();
|
|
public Line m_LinePfb;
|
|
public RectTransform m_LineCon;
|
|
public Color color;
|
|
private List<Point> selectPoints = new();
|
|
private void Start()
|
|
{
|
|
points = GetComponentsInChildren<Point>().ToList();
|
|
for (int i = 0; i < points.Count; i++)
|
|
{
|
|
points[i].Init(this);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 画线
|
|
/// </summary>
|
|
public void DrawLine(Point p)
|
|
{
|
|
selectPoints.Add(p);
|
|
if (selectPoints.Count == 2 && selectPoints[0].group != selectPoints[1].group)//凑齐两点,且两点不同区域
|
|
{
|
|
if (TwoPointsAlreadyConnected(selectPoints))//两点之间是否已经连线
|
|
{
|
|
UnselectPoints();
|
|
return;
|
|
}
|
|
if (OnePointsAlreadyConnected(selectPoints[0]) && OnePointsAlreadyConnected(selectPoints[1]))//两点是否都与第三点有连线
|
|
{
|
|
if (selectPoints[0].multip && selectPoints[1].multip)
|
|
{
|
|
CreateLine(selectPoints[0], selectPoints[1]);
|
|
}
|
|
UnselectPoints();
|
|
return;
|
|
}
|
|
if (OnePointsAlreadyConnected(selectPoints[0]))//点1是否都与第三点有连线
|
|
{
|
|
if (selectPoints[0].multip)
|
|
{
|
|
CreateLine(selectPoints[0], selectPoints[1]);
|
|
}
|
|
UnselectPoints();
|
|
return;
|
|
}
|
|
if (OnePointsAlreadyConnected(selectPoints[1]))//点2是否都与第三点有连线
|
|
{
|
|
if (selectPoints[1].multip)
|
|
{
|
|
CreateLine(selectPoints[0], selectPoints[1]);
|
|
}
|
|
UnselectPoints();
|
|
return;
|
|
}
|
|
CreateLine(selectPoints[0], selectPoints[1]);
|
|
UnselectPoints();
|
|
return;
|
|
}
|
|
if (selectPoints.Count == 2 && selectPoints[0].group == selectPoints[1].group)//凑齐两点,且两点同一区域
|
|
{
|
|
UnselectPoints();
|
|
p.Select();
|
|
selectPoints.Add(p);
|
|
return;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 两点之间是否已经有连线
|
|
/// </summary>
|
|
public bool TwoPointsAlreadyConnected(List<Point> p)
|
|
{
|
|
for (int i = 0; i < lines.Count; i++)
|
|
{
|
|
if (lines[i].points.SequenceEqual(p))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
/// <summary>
|
|
/// 一点是否已经连线
|
|
/// </summary>
|
|
public bool OnePointsAlreadyConnected(Point p)
|
|
{
|
|
for (int i = 0; i < lines.Count; i++)
|
|
{
|
|
if (lines[i].points.Contains(p))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
/// <summary>
|
|
/// 取消所有点击
|
|
/// </summary>
|
|
public void UnselectPoints()
|
|
{
|
|
for (int i = 0; i < selectPoints.Count; i++)
|
|
{
|
|
selectPoints[i].UnSelect();
|
|
}
|
|
selectPoints.Clear();
|
|
}
|
|
/// <summary>
|
|
/// 创建⼀条两点之间的线
|
|
/// </summary>
|
|
private void CreateLine(Point p1, Point p2)
|
|
{
|
|
//实例化需要显⽰的线段图⽚pfb
|
|
Line line = DrawLineTool.DrawLine(p1.transform.position, p2.transform.position, color, m_LineCon).GetComponent<Line>();
|
|
line.AddPoint(p1);
|
|
line.AddPoint(p2);
|
|
line.gameObject.SetActive(true);
|
|
lines.Add(line);
|
|
}
|
|
/// <summary>
|
|
/// 清除线
|
|
/// </summary>
|
|
public void ClearLine()
|
|
{
|
|
for (int i = 0; i < lines.Count; i++)
|
|
{
|
|
Destroy(lines[i].gameObject);
|
|
}
|
|
lines.Clear();
|
|
}
|
|
/// <summary>
|
|
/// 判断对错
|
|
/// </summary>
|
|
public bool JudgeLine()
|
|
{
|
|
bool trueOrFalse = true;
|
|
if (lines.Count == 0)
|
|
{
|
|
trueOrFalse = false;
|
|
}
|
|
for (int i = 0; i < lines.Count; i++)
|
|
{
|
|
if (lines[i].Judge())
|
|
{
|
|
lines[i].Correct();
|
|
}
|
|
else
|
|
{
|
|
lines[i].Error();
|
|
trueOrFalse = false;
|
|
}
|
|
}
|
|
return trueOrFalse;
|
|
}
|
|
/// <summary>
|
|
/// 禁用按钮
|
|
/// </summary>
|
|
public void ButtonForbidden()
|
|
{
|
|
for (int i = 0; i < points.Count; i++)
|
|
{
|
|
points[i].btn.interactable = false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 启用按钮
|
|
/// </summary>
|
|
public void ButtonOnEnable()
|
|
{
|
|
for (int i = 0; i < points.Count; i++)
|
|
{
|
|
points[i].btn.interactable = true;
|
|
}
|
|
}
|
|
|
|
}
|
|
} |