线条切割
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Utility;
|
||||
using Newtonsoft.Json;
|
||||
@@ -51,7 +52,7 @@ namespace AibisDream.FixSystem
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_cutting && Input.GetMouseButtonDown(0))
|
||||
if (_cutting && Input.GetMouseButton(0))
|
||||
{
|
||||
OnCut();
|
||||
}
|
||||
@@ -114,6 +115,7 @@ namespace AibisDream.FixSystem
|
||||
{
|
||||
// 打开或获取CutLine
|
||||
ShowCutLine();
|
||||
_cutLine.OnCuttingDown += OnCuttingDown;
|
||||
_cutting = true;
|
||||
}
|
||||
|
||||
@@ -123,6 +125,13 @@ namespace AibisDream.FixSystem
|
||||
_cutLine.DetectLineClick(mousePos, clickRadius);
|
||||
}
|
||||
|
||||
private void OnCuttingDown()
|
||||
{
|
||||
_cutLine.OnCuttingDown -= OnCuttingDown;
|
||||
_cutting = false;
|
||||
// TODO 播放切割动画
|
||||
}
|
||||
|
||||
private void ShowCutLine()
|
||||
{
|
||||
// 切割线不存在,就新建一个
|
||||
@@ -132,7 +141,7 @@ namespace AibisDream.FixSystem
|
||||
var cutLineObj = Instantiate(prefab, transform);
|
||||
_cutLine = cutLineObj.GetComponent<CutLine>();
|
||||
}
|
||||
|
||||
|
||||
// 对切割线进行初始化
|
||||
var shapePoints = new List<Vector2>();
|
||||
_targetSpriteRenderer.sprite.GetPhysicsShape(0, shapePoints);
|
||||
@@ -141,8 +150,13 @@ namespace AibisDream.FixSystem
|
||||
Debug.LogWarning($"{name} has no shape");
|
||||
return;
|
||||
}
|
||||
|
||||
_cutLine.Init(shapePoints, clickRadius);
|
||||
|
||||
// 本地坐标转世界坐标
|
||||
var shapePointsV3 = shapePoints
|
||||
.Select(item => _targetSpriteRenderer.transform.TransformPoint(item))
|
||||
.ToList();
|
||||
|
||||
_cutLine.Init(shapePointsV3, clickRadius);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user