边缘
This commit is contained in:
@@ -4,7 +4,6 @@ using AibisDream.Framework;
|
||||
using AibisDream.Utility;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace AibisDream.FixSystem
|
||||
{
|
||||
@@ -23,14 +22,15 @@ namespace AibisDream.FixSystem
|
||||
|
||||
private SpriteRenderer _targetSpriteRenderer; // 目标的 SpriteRenderer
|
||||
|
||||
private LineRenderer _dotLine;
|
||||
private LineRenderer _cutLine;
|
||||
private CutLine _cutLine;
|
||||
|
||||
#endregion
|
||||
|
||||
// 模块基本数据
|
||||
[SerializeField] public BodyModuleData data;
|
||||
public float clickRadius = 0.5f;
|
||||
private bool _available = true;
|
||||
private bool _cutting;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -49,6 +49,14 @@ namespace AibisDream.FixSystem
|
||||
_alarmMaterial = Resources.Load<Material>("Materials/AlarmMaterial");
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_cutting && Input.GetMouseButtonDown(0))
|
||||
{
|
||||
OnCut();
|
||||
}
|
||||
}
|
||||
|
||||
#region 插槽功能
|
||||
|
||||
public bool IsAvailable()
|
||||
@@ -104,35 +112,37 @@ namespace AibisDream.FixSystem
|
||||
|
||||
public void EnableCut()
|
||||
{
|
||||
// 显示虚线
|
||||
var dotLine = GetOrCreateDotLine();
|
||||
// 指针转为锯片
|
||||
// 打开或获取CutLine
|
||||
ShowCutLine();
|
||||
_cutting = true;
|
||||
}
|
||||
|
||||
private void OnCut()
|
||||
{
|
||||
//
|
||||
Vector2 mousePos = CommonUtil.GetMouseWorldPos(Input.mousePosition);
|
||||
_cutLine.DetectLineClick(mousePos, clickRadius);
|
||||
}
|
||||
|
||||
private LineRenderer GetOrCreateDotLine()
|
||||
private void ShowCutLine()
|
||||
{
|
||||
if (_dotLine != null)
|
||||
// 切割线不存在,就新建一个
|
||||
if (_cutLine == null)
|
||||
{
|
||||
return _dotLine;
|
||||
var prefab = ResourceKit.LoadAssetSync<GameObject>(ConstRef.CutLinePrefabName);
|
||||
var cutLineObj = Instantiate(prefab, transform);
|
||||
_cutLine = cutLineObj.GetComponent<CutLine>();
|
||||
}
|
||||
|
||||
var dotLine = new GameObject("Dot Line").AddComponent<LineRenderer>();
|
||||
// 设置Line的参数
|
||||
dotLine.sortingLayerName = ConstRef.FixMiddleLayer;
|
||||
dotLine.sortingOrder = 4;
|
||||
dotLine.materials = new[] { ResourceKit.LoadAssetSync<Material>(ConstRef.DotLineMaterialName) };
|
||||
dotLine.textureMode = LineTextureMode.Tile;
|
||||
dotLine.loop = true;
|
||||
|
||||
// 设置line的周长
|
||||
_targetSpriteRenderer.sprite.GetPhysicsShape(0, new List<Vector2>());
|
||||
// 对切割线进行初始化
|
||||
var shapePoints = new List<Vector2>();
|
||||
_targetSpriteRenderer.sprite.GetPhysicsShape(0, shapePoints);
|
||||
if (shapePoints.Count <= 0)
|
||||
{
|
||||
Debug.LogWarning($"{name} has no shape");
|
||||
return;
|
||||
}
|
||||
|
||||
return dotLine;
|
||||
_cutLine.Init(shapePoints, clickRadius);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user