80 lines
2.6 KiB
C#
80 lines
2.6 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
|
|||
|
|
namespace GeneralTools
|
|||
|
|
{
|
|||
|
|
[ExecuteInEditMode]
|
|||
|
|
public class ShowSeam : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
public bool isShowSeam = false;
|
|||
|
|
public int widthCount = 0;
|
|||
|
|
public int heightCount = 0;
|
|||
|
|
[Range(0, 10)]
|
|||
|
|
public float lineWidth = 2;
|
|||
|
|
public Color lineColor = Color.white;
|
|||
|
|
|
|||
|
|
|
|||
|
|
public RectTransform linePrefab;
|
|||
|
|
public Transform seamCnavas;
|
|||
|
|
|
|||
|
|
void Update()
|
|||
|
|
{
|
|||
|
|
#if UNITY_EDITOR
|
|||
|
|
UtilityTool.DeleteChild(seamCnavas);
|
|||
|
|
if (!isShowSeam)
|
|||
|
|
return;
|
|||
|
|
//边
|
|||
|
|
CreateHorizontalLine(new Vector2(0, -Screen.height / 2));
|
|||
|
|
CreateHorizontalLine(new Vector2(0, Screen.height / 2));
|
|||
|
|
CreateVerticalLine(new Vector2(-Screen.width / 2, 0));
|
|||
|
|
CreateVerticalLine(new Vector2(Screen.width / 2, 0));
|
|||
|
|
//内部
|
|||
|
|
if (widthCount >= 2)
|
|||
|
|
{
|
|||
|
|
int lineCount = widthCount - 1;
|
|||
|
|
float leftX = -Screen.width / 2;
|
|||
|
|
float interval = Screen.width / widthCount;
|
|||
|
|
for (int i = 0; i < lineCount; i++)
|
|||
|
|
{
|
|||
|
|
Vector2 newPos = new Vector2(leftX + interval * (i + 1), 0);
|
|||
|
|
CreateVerticalLine(newPos);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
if (heightCount >= 2)
|
|||
|
|
{
|
|||
|
|
int lineCount = heightCount - 1;
|
|||
|
|
float downY = -Screen.height / 2;
|
|||
|
|
float interval = Screen.height / heightCount;
|
|||
|
|
for (int i = 0; i < lineCount; i++)
|
|||
|
|
{
|
|||
|
|
Vector2 newPos = new Vector2(0, downY + interval * (i + 1));
|
|||
|
|
CreateHorizontalLine(newPos);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endif
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
protected void CreateHorizontalLine(Vector2 pos)
|
|||
|
|
{
|
|||
|
|
RectTransform newLine = Instantiate(linePrefab, seamCnavas);
|
|||
|
|
newLine.localScale = Vector3.one;
|
|||
|
|
newLine.eulerAngles = Vector3.zero;
|
|||
|
|
newLine.sizeDelta = new Vector2(Screen.width, lineWidth);
|
|||
|
|
newLine.localPosition = pos;
|
|||
|
|
newLine.GetComponent<Image>().color = lineColor;
|
|||
|
|
}
|
|||
|
|
protected void CreateVerticalLine(Vector2 pos)
|
|||
|
|
{
|
|||
|
|
RectTransform newLine = Instantiate(linePrefab, seamCnavas);
|
|||
|
|
newLine.localScale = Vector3.one;
|
|||
|
|
newLine.eulerAngles = Vector3.zero;
|
|||
|
|
newLine.sizeDelta = new Vector2(lineWidth, Screen.height);
|
|||
|
|
newLine.localPosition = pos;
|
|||
|
|
newLine.GetComponent<Image>().color = lineColor;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|