代码合并

This commit is contained in:
MuHua-123
2024-11-08 18:15:06 +08:00
parent 5f169b90bb
commit 497b43a446
146 changed files with 2858 additions and 110 deletions
@@ -0,0 +1,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DataDesignPoint {
public readonly DataPlate dataPlate;
public DataDesignPoint(DataPlate dataPlate) { this.dataPlate = dataPlate; }
public int index;
public Vector2 postiton;
public Vector2 leftBezier;//贝塞尔曲线左(逆时针+)
public Vector2 rightBezier;//贝塞尔曲线右(顺时针-)
public List<Vector2> edgePoints = new List<Vector2>();
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 215036ac2145e9f45835ea28080aee53
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,29 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PrefabBezierPoint : MonoBehaviour {
public LineRenderer bezierLine;
private Vector2 position;
private DataDesignPoint value;
private Action<Vector2> callback;
public DataPlate DataPlate => value.dataPlate;
public Vector2 Position => position + value.postiton;
public void SetValue(DataDesignPoint value, Action<Vector2> callback) {
this.value = value;
this.callback = callback;
}
public void SetPosition(Vector2 position) {
this.position = position;
float lx = position.x * 50;
float ly = position.y * 50;
transform.localPosition = new Vector3(lx, ly, transform.localPosition.z);
bezierLine.SetPosition(1, position);
}
public void Change(Vector2 localPosition) {
Vector2 position = localPosition - value.postiton;
SetPosition(position);
callback?.Invoke(position);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1a3d9fd1b34a70c4ca6a4edaf6715131
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,54 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MuHua;
public class PrefabDesignPoint : MonoBehaviour, ITemplate<DataDesignPoint> {
public LineRenderer lineRenderer;
public EdgeCollider2D edgeCollider;
public PrefabBezierPoint bezierPoint1;
public PrefabBezierPoint bezierPoint2;
private DataDesignPoint value;
public int Index => value.index;
public Vector2 Position => value.postiton;
public List<Vector2> EdgePoints => value.edgePoints;
public DataPlate DataPlate => value.dataPlate;
public int MaxIndex => DataPlate.designPoints.Count;
public int NextIndex => DataPlateTool.NormalIndex(Index + 1, MaxIndex);
public void SetValue(DataDesignPoint value) {
this.value = value;
bezierPoint1.SetValue(value, (obj) => { value.leftBezier = obj; });
bezierPoint2.SetValue(value, (obj) => { value.rightBezier = obj; });
DataPlate.OnChangeDesignPoint += DataPlate_OnChangeDesignPoint;
DataPlate_OnChangeDesignPoint(Index);
}
private void OnDestroy() {
DataPlate.OnChangeDesignPoint -= DataPlate_OnChangeDesignPoint;
}
private void DataPlate_OnChangeDesignPoint(int index) {
if (index != Index) { return; }
transform.localPosition = Position;
//添加全部点
int maxIndex = EdgePoints.Count + 1;
lineRenderer.positionCount = maxIndex;
Vector2[] vectors = new Vector2[maxIndex];
for (int i = 0; i < EdgePoints.Count; i++) {
Vector2 position = EdgePoints[i] - Position;
lineRenderer.SetPosition(i, position);
vectors[i] = position;
}
//添加最后一个点
int last = maxIndex - 1;
DataDesignPoint nextDesignPoint = DataPlate.FindDesignPoint(NextIndex);
Vector2 position2 = nextDesignPoint.postiton - Position;
lineRenderer.SetPosition(last, position2);
vectors[last] = position2;
//更新2D线段碰撞器
edgeCollider.points = vectors;
//更新贝塞尔曲线
bezierPoint1.SetPosition(value.leftBezier);
bezierPoint2.SetPosition(value.rightBezier);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 76c13895912b8cd48a099779cbd0af65
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: