From 10179d5453ad38c7e60d323a51116f5484599ac9 Mon Sep 17 00:00:00 2001 From: Ding Yuntian <1491671119@qq.com> Date: Fri, 2 May 2025 16:06:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E5=89=B2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Language/Dialog/FP_Peipei2.meta | 8 ++ Assets/Scenes/StandardFixScene.unity | 126 +++--------------- .../FixSystemNew/BodyModule/BodyModule.cs | 13 +- .../BodyModule/BodyModuleSystem.cs | 14 +- .../FixSystemNew/BodyModule/CutLine.cs | 41 +++--- .../ActionKit/Action/DOTweenAction.cs | 95 +++++++++++++ .../ActionKit/Action/DOTweenAction.cs.meta | 3 + .../Scripts/Framework/OtherKit/MonoCenter.cs | 6 - Assets/Scripts/Utility/ConstRef.cs | 7 + 9 files changed, 178 insertions(+), 135 deletions(-) create mode 100644 Assets/Language/Dialog/FP_Peipei2.meta create mode 100644 Assets/Scripts/Framework/ActionKit/Action/DOTweenAction.cs create mode 100644 Assets/Scripts/Framework/ActionKit/Action/DOTweenAction.cs.meta diff --git a/Assets/Language/Dialog/FP_Peipei2.meta b/Assets/Language/Dialog/FP_Peipei2.meta new file mode 100644 index 000000000..e51ad2915 --- /dev/null +++ b/Assets/Language/Dialog/FP_Peipei2.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0eb67c8a4cbd32440a35be19a8b7b9dc +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/StandardFixScene.unity b/Assets/Scenes/StandardFixScene.unity index 8f034f679..d8fb898ba 100644 --- a/Assets/Scenes/StandardFixScene.unity +++ b/Assets/Scenes/StandardFixScene.unity @@ -279,90 +279,6 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 ---- !u!1 &50965008 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 50965009} - - component: {fileID: 50965010} - m_Layer: 0 - m_Name: Circle - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &50965009 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 50965008} - serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -11, y: 0.81, z: 0} - m_LocalScale: {x: 0.4, y: 0.4, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 1610923217} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!212 &50965010 -SpriteRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 50965008} - m_Enabled: 1 - m_CastShadows: 0 - m_ReceiveShadows: 0 - m_DynamicOccludee: 1 - m_StaticShadowCaster: 0 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 0 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 0 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 1986402817 - m_SortingLayer: 19 - m_SortingOrder: 0 - m_Sprite: {fileID: -2413806693520163455, guid: a86470a33a6bf42c4b3595704624658b, type: 3} - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_FlipX: 0 - m_FlipY: 0 - m_DrawMode: 0 - m_Size: {x: 1, y: 1} - m_AdaptiveModeThreshold: 0.5 - m_SpriteTileMode: 0 - m_WasSpriteAssigned: 1 - m_MaskInteraction: 0 - m_SpriteSortPoint: 0 --- !u!1 &70700667 GameObject: m_ObjectHideFlags: 0 @@ -654,11 +570,11 @@ Transform: m_GameObject: {fileID: 124853503} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -3.2441864, y: -2.9744186, z: 0} + m_LocalPosition: {x: 0.009813547, y: -0.4144187, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 770430378} + m_Father: {fileID: 1305312188} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &124853505 SpriteRenderer: @@ -5401,6 +5317,7 @@ Transform: - {fileID: 1474095201} - {fileID: 859533817} - {fileID: 2114957730} + - {fileID: 1497264578} m_Father: {fileID: 719924201} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &703071695 @@ -6135,11 +6052,6 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - - {fileID: 124853504} - - {fileID: 1157582230} - - {fileID: 1808349580} - - {fileID: 1497264578} - - {fileID: 925801570} - {fileID: 1708742664} m_Father: {fileID: 265073919} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -7352,11 +7264,11 @@ Transform: m_GameObject: {fileID: 925801569} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -2.223256, y: 0.63953495, z: 0} + m_LocalPosition: {x: -1.0452552, y: 0.063534975, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 770430378} + m_Father: {fileID: 1365632492} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &925801571 SpriteRenderer: @@ -8666,11 +8578,11 @@ Transform: m_GameObject: {fileID: 1157582229} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -1.86, y: 2.076744, z: 0} + m_LocalPosition: {x: -1.1900005, y: -0.083256006, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 770430378} + m_Father: {fileID: 1672490540} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &1157582231 SpriteRenderer: @@ -9553,6 +9465,7 @@ Transform: m_Children: - {fileID: 1056483153} - {fileID: 836879224} + - {fileID: 124853504} m_Father: {fileID: 719924201} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1305312189 @@ -10159,6 +10072,7 @@ Transform: - {fileID: 1425842438} - {fileID: 1159839957} - {fileID: 878474148} + - {fileID: 925801570} m_Father: {fileID: 719924201} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1365632493 @@ -10293,6 +10207,7 @@ Transform: m_Children: - {fileID: 14820817} - {fileID: 1166446918} + - {fileID: 1808349580} m_Father: {fileID: 719924201} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1451220531 @@ -10656,11 +10571,11 @@ Transform: m_GameObject: {fileID: 1497264577} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -3.1209307, y: 2.598, z: 0} + m_LocalPosition: {x: 0.19307017, y: -0.004999876, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 770430378} + m_Father: {fileID: 703071694} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &1497264579 SpriteRenderer: @@ -11772,11 +11687,6 @@ MonoBehaviour: m_EditorClassIdentifier: taskTextPrefab: {fileID: 5295477770541402281, guid: ab166642babe53e4993fa1bd9bd57204, type: 3} taskListParent: {fileID: 1101482910} ---- !u!4 &1610923217 stripped -Transform: - m_CorrespondingSourceObject: {fileID: 4256475766480134775, guid: 95188b5d2a557274fb52febde14400b8, type: 3} - m_PrefabInstance: {fileID: 7026926953013077400} - m_PrefabAsset: {fileID: 0} --- !u!1 &1612743779 GameObject: m_ObjectHideFlags: 0 @@ -12277,6 +12187,7 @@ Transform: m_Children: - {fileID: 411686990} - {fileID: 667704761} + - {fileID: 1157582230} m_Father: {fileID: 719924201} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1672490541 @@ -12984,11 +12895,11 @@ Transform: m_GameObject: {fileID: 1808349579} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -4.702326, y: 2.1372094, z: 0} + m_LocalPosition: {x: 0.47267628, y: 0.06120944, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 770430378} + m_Father: {fileID: 1451220530} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &1808349581 SpriteRenderer: @@ -16469,13 +16380,10 @@ PrefabInstance: - target: {fileID: 8890064519865571154, guid: 95188b5d2a557274fb52febde14400b8, type: 3} propertyPath: cursor value: - objectReference: {fileID: 50965010} + objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] - m_AddedGameObjects: - - targetCorrespondingSourceObject: {fileID: 4256475766480134775, guid: 95188b5d2a557274fb52febde14400b8, type: 3} - insertIndex: -1 - addedObject: {fileID: 50965009} + m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 95188b5d2a557274fb52febde14400b8, type: 3} --- !u!1 &7169523939405871121 diff --git a/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs b/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs index 521beee3b..aea457eeb 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs @@ -2,7 +2,9 @@ using System; using System.Collections.Generic; using System.Linq; using AibisDream.Framework; +using AibisDream.Kit; using AibisDream.Utility; +using DG.Tweening; using Newtonsoft.Json; using UnityEngine; @@ -129,13 +131,20 @@ namespace AibisDream.FixSystem { _cutLine.OnCuttingDown -= OnCuttingDown; _cutting = false; - // TODO 播放切割动画 + // 模块脱落 + _cutLine.HideLine(); + _bodyModuleSystem.RemoveModule(this); + ActionKit.Sequence() + .Delay(0.5f) + .DOTween(() => transform.DOMoveY(ConstRef.TweenEndY, + (transform.position.y - ConstRef.TweenEndY) / ConstRef.FallSpeed).SetEase(Ease.InQuad)) + .Start(this, () => Destroy(gameObject)); } private void ShowCutLine() { // 切割线不存在,就新建一个 - if (_cutLine == null) + if (!_cutLine) { var prefab = ResourceKit.LoadAssetSync(ConstRef.CutLinePrefabName); var cutLineObj = Instantiate(prefab, transform); diff --git a/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleSystem.cs b/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleSystem.cs index 64ad2d68d..fd3347145 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleSystem.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleSystem.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Linq; using AibisDream.Framework; using Cinemachine; @@ -11,7 +12,7 @@ namespace AibisDream.FixSystem { #region 内部索引 - public BodyModule[] BodyModules { get; private set; } + public List BodyModules { get; private set; } private GameObject _bodyModuleGroup; private GameObject _headModuleGroup; @@ -200,10 +201,19 @@ namespace AibisDream.FixSystem } // 重新获取ModuleGroup var root = moduleState == ModuleState.Body ? _bodyModuleGroup : _headModuleGroup; - BodyModules = root?.GetComponentsInChildren(); + BodyModules = root?.GetComponentsInChildren().ToList(); // 更改data _data.moduleState = moduleState; } + + /// + /// 从模块中清除 + /// + /// 将要被移除的模块 + public void RemoveModule(BodyModule module) + { + BodyModules.Remove(module); + } } [LoadIndex(2)] diff --git a/Assets/Scripts/FixSystemNew/BodyModule/CutLine.cs b/Assets/Scripts/FixSystemNew/BodyModule/CutLine.cs index a08098081..2b240b45b 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/CutLine.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/CutLine.cs @@ -12,7 +12,7 @@ namespace AibisDream private static readonly int RangeCount = Shader.PropertyToID("_RangeCount"); #endregion - + private LineRenderer _lineRenderer; private Material _lineMaterial; @@ -36,6 +36,8 @@ namespace AibisDream _lineMaterial = _lineRenderer.materials[0]; } + _lineRenderer.gameObject.SetActive(true); + // 清除旧数据 ClearOldData(); // 生成归一化点 @@ -64,7 +66,7 @@ namespace AibisDream // 设置Shader _lineMaterial.SetFloat(TotalLength, _totalLength); _lineMaterial.SetInt(RangeCount, 1); - _lineMaterial.SetVectorArray(Ranges, new List {Vector4.zero} ); + _lineMaterial.SetVectorArray(Ranges, new List { Vector4.zero }); } private void UpdateMaterial() @@ -73,7 +75,7 @@ namespace AibisDream { return; } - + // 将Range组装成Shader可以读取的格式 var ranges = new List(); @@ -97,7 +99,7 @@ namespace AibisDream _linePoints = shapePoints .Select(item => new Vector2(item.x, item.y)) .ToArray(); - + var segmentLengths = new List(); // 计算总长度和各段长度 @@ -159,7 +161,7 @@ namespace AibisDream // 如果未覆盖直接计算下一段 continue; } - + // 将线段范围转成整体范围 var normalizedStart = _normalizedLinePoints[i - 1]; var normalizedEnd = _normalizedLinePoints[i]; @@ -177,7 +179,7 @@ namespace AibisDream // 合并所有重叠区间 MergeRanges(); - + // 判断当前切割有没有割到95% if (CalcTotalRange() >= 0.95) { @@ -193,8 +195,9 @@ namespace AibisDream { log += $"{range.x:F2}-{range.y:F2}; "; } + Debug.Log(log); - + UpdateMaterial(); } @@ -204,7 +207,7 @@ namespace AibisDream // 计算线段方向向量和长度 Vector2 lineDir = lineEnd - lineStart; float lineLength = lineDir.magnitude; - + // 如果线段长度为零(两个端点重合) if (Mathf.Approximately(lineLength, 0f)) { @@ -213,7 +216,7 @@ namespace AibisDream rawRange = distance <= radius ? new Vector2(0f, 1f) : default; return distance <= radius; } - + // 计算点到线段所在直线距离 Vector2 lineDirNormalized = lineDir / lineLength; // 归一化方向向量 Vector2 pointToStart = point - lineStart; // 计算点到线段起点的向量 @@ -221,23 +224,24 @@ namespace AibisDream float closestT = Mathf.Clamp01(projection / lineLength); // 计算实际最近点在线段上的比例位置 Vector2 closestPoint = lineStart + closestT * lineDir; // 计算最近点坐标 float distanceToLine = Vector2.Distance(point, closestPoint); // 计算点到最近点的距离 - + // 如果距离大于半径,完全没有覆盖 if (distanceToLine > radius) { rawRange = default; return false; } - + // 计算覆盖范围 - float halfCoveredLength = Mathf.Sqrt(radius * radius - distanceToLine * distanceToLine); // 计算实际覆盖的线段长度(勾股定理) - + float halfCoveredLength = + Mathf.Sqrt(radius * radius - distanceToLine * distanceToLine); // 计算实际覆盖的线段长度(勾股定理) + float startCoverage = (projection - halfCoveredLength) / lineLength; float endCoverage = (projection + halfCoveredLength) / lineLength; // 计算覆盖的起点和终点比例 - + startCoverage = Mathf.Clamp01(startCoverage); endCoverage = Mathf.Clamp01(endCoverage); // 限制在0-1范围内 - + // 如果起点和终点相同,表示只覆盖了一个点 if (Mathf.Approximately(startCoverage, endCoverage)) { @@ -287,7 +291,12 @@ namespace AibisDream #endregion - // 获取当前所有记录的范围(0-1之间的值) + public void HideLine() + { + gameObject.SetActive(false); + } + + // 获取当前所有记录的范围(0-1之间的值) public List GetRecordedRanges() { return new List(_recordedRanges); diff --git a/Assets/Scripts/Framework/ActionKit/Action/DOTweenAction.cs b/Assets/Scripts/Framework/ActionKit/Action/DOTweenAction.cs new file mode 100644 index 000000000..422a7f3d9 --- /dev/null +++ b/Assets/Scripts/Framework/ActionKit/Action/DOTweenAction.cs @@ -0,0 +1,95 @@ +using System; +using DG.Tweening; + +namespace AibisDream.Kit +{ + public class DOTweenAction : IAction + { + private DOTweenAction() + { + } + + private static readonly SimpleObjectPool Pool = new(() => new DOTweenAction(), null, 10); + + private Func _tweenGetter; + + public static DOTweenAction Allocate(Func tweenGetter) + { + var doTweenAction = Pool.Allocate(); + doTweenAction.ActionID = ActionKit.IDGenerator++; + doTweenAction.IsFinalized = false; + doTweenAction.Reset(); + doTweenAction._tweenGetter = tweenGetter; + return doTweenAction; + } + + private Tween _executingTween; + + public void OnStart() + { + _executingTween = _tweenGetter(); + _executingTween.Restart(); + + var tween = _tweenGetter(); + tween.Restart(); + } + + public void OnExecute(float dt) + { + if (_executingTween != null && !_executingTween.IsPlaying()) + { + this.Finish(); + } + } + + public void OnFinish() + { + _executingTween = null; + } + + public bool Paused { get; set; } + + public void Deinit() + { + if (!IsFinalized) + { + IsFinalized = true; + if (_executingTween != null) + { + if (_executingTween.IsPlaying()) + { + _executingTween.Kill(); + } + } + + _executingTween = null; + Pool.Recycle(this); + } + } + + public void Reset() + { + Status = ActionStatus.NotStart; + Paused = false; + _executingTween = null; + } + + public bool IsFinalized { get; set; } + public ulong ActionID { get; set; } + public ActionStatus Status { get; set; } + } + + public static class ActionKitDOTweenExtension + { + public static IAction ToAction(this Tween self) + { + self.Pause(); + return DOTweenAction.Allocate(() => self); + } + + public static ISequence DOTween(this ISequence self, Func tweenGetter) + { + return self.Append(DOTweenAction.Allocate(tweenGetter)); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Framework/ActionKit/Action/DOTweenAction.cs.meta b/Assets/Scripts/Framework/ActionKit/Action/DOTweenAction.cs.meta new file mode 100644 index 000000000..007c3d066 --- /dev/null +++ b/Assets/Scripts/Framework/ActionKit/Action/DOTweenAction.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 03d3c34c1dec4eb8841838c896164072 +timeCreated: 1649214191 \ No newline at end of file diff --git a/Assets/Scripts/Framework/OtherKit/MonoCenter.cs b/Assets/Scripts/Framework/OtherKit/MonoCenter.cs index 44f515443..f8b37966e 100644 --- a/Assets/Scripts/Framework/OtherKit/MonoCenter.cs +++ b/Assets/Scripts/Framework/OtherKit/MonoCenter.cs @@ -1,6 +1,5 @@ using System; using AibisDream.FixSystem; -using AibisDream.Utility; using UnityEngine; namespace AibisDream.Framework @@ -12,8 +11,6 @@ namespace AibisDream.Framework public static MonoCenter Mono; private static IOCContainer _iocContainer; - public SpriteRenderer cursor; - private void Awake() { if (Mono) @@ -46,9 +43,6 @@ namespace AibisDream.Framework private void Update() { OnUpdate?.Invoke(); - // var worldPos = CommonUtil.GetMouseWorldPos(Input.mousePosition); - // worldPos.z = 0; - // cursor.transform.position = worldPos; } } diff --git a/Assets/Scripts/Utility/ConstRef.cs b/Assets/Scripts/Utility/ConstRef.cs index 04e25c8d4..aa85e9470 100644 --- a/Assets/Scripts/Utility/ConstRef.cs +++ b/Assets/Scripts/Utility/ConstRef.cs @@ -27,5 +27,12 @@ namespace AibisDream.Utility public const string CutLinePrefabName = "CutLine"; #endregion + + #region 动画配置 + + public const float TweenEndY = -10; + public const float FallSpeed = 10; + + #endregion } } \ No newline at end of file