From 37ccc08c85076392af9e185cff62742643c80f5d Mon Sep 17 00:00:00 2001 From: Roman <1325980292@qq.com> Date: Sat, 11 Dec 2021 02:12:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=EF=BC=9A=E6=90=AD=E5=BB=BA?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E7=9A=84=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.编写塞钱箱逻辑 (1.初始为有钱 (2.创建事件,当被塞钱,修改塞钱箱状态 (3.创建事件,当被拿钱,修改塞钱箱状态 (*:修改塞钱箱继承自普通可交互物体 2.编写玩家塞钱逻辑 (1.创建交互按键,当检测到交互执行,执行所catch物体的OnCall,根据所catch物体不同触发不同的动作。当catch到的是塞钱箱,执行塞钱功能 (2.创建塞钱功能,持有特殊金币-1 3.修改爱欲品掉钱逻辑 (1.修改死亡事件,当检测到主人为地藏并且玩家身上已经没钱了的时候,生成一个特殊硬币 4.编写特殊硬币逻辑 (1.继承于可交互物体(×) (2.OnCall的时候触发玩家加钱功能 (3.物理层上不与除地面以外的其他东西碰撞 (4.捡拾上,给硬币添加一个子物体,通过子物体上的触发器和攻击类来判断捡拾与否 5.编写地藏拿钱攻击逻辑 (*.参照钟的逻辑 (1.新建地藏手 (2.新建组件:地藏手 (3.收到攻击信号后,从外部从上至下伸入一只手,伴随抖动,到一定位置后停止 (4.手有碰撞体,触碰到玩家时,对玩家造成伤害 (5.抄一段普通怪物的受击逻辑,当手被攻击了,触发动画,稍微抬起一小段,并且剧烈震动,同时通知主人被打 6.整理脚本 至此,关卡已经能按照正常的逻辑跑起来了 --- Assets/InputAssets/Player.cs | 40 ++++ Assets/InputAssets/Player.inputactions | 30 +++ Assets/Prefabs/爱欲品.prefab | 2 + Assets/Prefabs/硬币.prefab | 232 ++++++++++++++++++++++ Assets/Prefabs/硬币.prefab.meta | 7 + Assets/Scenes/DiZangStageTest.unity | 251 ++++++++++++++++++++++-- Assets/Scripts/AiYuPin.cs | 35 ++++ Assets/Scripts/Coin.cs | 50 +++++ Assets/Scripts/Coin.cs.meta | 11 ++ Assets/Scripts/DiZang.cs | 12 +- Assets/Scripts/DiZangsHadn.cs | 197 +++++++++++++++++++ Assets/Scripts/DiZangsHadn.cs.meta | 11 ++ Assets/Scripts/Enemy.cs | 4 +- Assets/Scripts/Interactive.cs | 37 ++++ Assets/Scripts/Interactive.cs.meta | 11 ++ Assets/Scripts/MoneyBox.cs | 27 ++- Assets/Scripts/MyPlayer.cs | 72 +++++-- Assets/材质/弹性.physicsMaterial2D | 11 ++ Assets/材质/弹性.physicsMaterial2D.meta | 8 + Logs/ApiUpdaterCheck.txt | 10 + ProjectSettings/Physics2DSettings.asset | 2 +- ProjectSettings/TagManager.asset | 8 +- 22 files changed, 1027 insertions(+), 41 deletions(-) create mode 100644 Assets/Prefabs/硬币.prefab create mode 100644 Assets/Prefabs/硬币.prefab.meta create mode 100644 Assets/Scripts/Coin.cs create mode 100644 Assets/Scripts/Coin.cs.meta create mode 100644 Assets/Scripts/DiZangsHadn.cs create mode 100644 Assets/Scripts/DiZangsHadn.cs.meta create mode 100644 Assets/Scripts/Interactive.cs create mode 100644 Assets/Scripts/Interactive.cs.meta create mode 100644 Assets/材质/弹性.physicsMaterial2D create mode 100644 Assets/材质/弹性.physicsMaterial2D.meta diff --git a/Assets/InputAssets/Player.cs b/Assets/InputAssets/Player.cs index 15d051e..8a7a035 100644 --- a/Assets/InputAssets/Player.cs +++ b/Assets/InputAssets/Player.cs @@ -49,6 +49,14 @@ public class @Player : IInputActionCollection, IDisposable ""expectedControlType"": ""Button"", ""processors"": """", ""interactions"": """" + }, + { + ""name"": ""Interactive"", + ""type"": ""Button"", + ""id"": ""7cf0a787-dc2d-42b1-9ed9-c840ccfa3ce9"", + ""expectedControlType"": ""Button"", + ""processors"": """", + ""interactions"": """" } ], ""bindings"": [ @@ -183,6 +191,28 @@ public class @Player : IInputActionCollection, IDisposable ""action"": ""Sickle"", ""isComposite"": false, ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""d5e36b3d-645c-4a18-914e-7a7ae9046eda"", + ""path"": ""/buttonNorth"", + ""interactions"": """", + ""processors"": """", + ""groups"": ""Play"", + ""action"": ""Interactive"", + ""isComposite"": false, + ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""30b75de0-1d5e-403d-8da3-a8da696490ee"", + ""path"": ""/f"", + ""interactions"": """", + ""processors"": """", + ""groups"": ""Play"", + ""action"": ""Interactive"", + ""isComposite"": false, + ""isPartOfComposite"": false } ] } @@ -212,6 +242,7 @@ public class @Player : IInputActionCollection, IDisposable m_Normal_Jump = m_Normal.FindAction("Jump", throwIfNotFound: true); m_Normal_Wave = m_Normal.FindAction("Wave", throwIfNotFound: true); m_Normal_Sickle = m_Normal.FindAction("Sickle", throwIfNotFound: true); + m_Normal_Interactive = m_Normal.FindAction("Interactive", throwIfNotFound: true); } public void Dispose() @@ -265,6 +296,7 @@ public class @Player : IInputActionCollection, IDisposable private readonly InputAction m_Normal_Jump; private readonly InputAction m_Normal_Wave; private readonly InputAction m_Normal_Sickle; + private readonly InputAction m_Normal_Interactive; public struct NormalActions { private @Player m_Wrapper; @@ -273,6 +305,7 @@ public class @Player : IInputActionCollection, IDisposable public InputAction @Jump => m_Wrapper.m_Normal_Jump; public InputAction @Wave => m_Wrapper.m_Normal_Wave; public InputAction @Sickle => m_Wrapper.m_Normal_Sickle; + public InputAction @Interactive => m_Wrapper.m_Normal_Interactive; public InputActionMap Get() { return m_Wrapper.m_Normal; } public void Enable() { Get().Enable(); } public void Disable() { Get().Disable(); } @@ -294,6 +327,9 @@ public class @Player : IInputActionCollection, IDisposable @Sickle.started -= m_Wrapper.m_NormalActionsCallbackInterface.OnSickle; @Sickle.performed -= m_Wrapper.m_NormalActionsCallbackInterface.OnSickle; @Sickle.canceled -= m_Wrapper.m_NormalActionsCallbackInterface.OnSickle; + @Interactive.started -= m_Wrapper.m_NormalActionsCallbackInterface.OnInteractive; + @Interactive.performed -= m_Wrapper.m_NormalActionsCallbackInterface.OnInteractive; + @Interactive.canceled -= m_Wrapper.m_NormalActionsCallbackInterface.OnInteractive; } m_Wrapper.m_NormalActionsCallbackInterface = instance; if (instance != null) @@ -310,6 +346,9 @@ public class @Player : IInputActionCollection, IDisposable @Sickle.started += instance.OnSickle; @Sickle.performed += instance.OnSickle; @Sickle.canceled += instance.OnSickle; + @Interactive.started += instance.OnInteractive; + @Interactive.performed += instance.OnInteractive; + @Interactive.canceled += instance.OnInteractive; } } } @@ -329,5 +368,6 @@ public class @Player : IInputActionCollection, IDisposable void OnJump(InputAction.CallbackContext context); void OnWave(InputAction.CallbackContext context); void OnSickle(InputAction.CallbackContext context); + void OnInteractive(InputAction.CallbackContext context); } } diff --git a/Assets/InputAssets/Player.inputactions b/Assets/InputAssets/Player.inputactions index 7be13f3..f634b89 100644 --- a/Assets/InputAssets/Player.inputactions +++ b/Assets/InputAssets/Player.inputactions @@ -36,6 +36,14 @@ "expectedControlType": "Button", "processors": "", "interactions": "" + }, + { + "name": "Interactive", + "type": "Button", + "id": "7cf0a787-dc2d-42b1-9ed9-c840ccfa3ce9", + "expectedControlType": "Button", + "processors": "", + "interactions": "" } ], "bindings": [ @@ -170,6 +178,28 @@ "action": "Sickle", "isComposite": false, "isPartOfComposite": false + }, + { + "name": "", + "id": "d5e36b3d-645c-4a18-914e-7a7ae9046eda", + "path": "/buttonNorth", + "interactions": "", + "processors": "", + "groups": "Play", + "action": "Interactive", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "30b75de0-1d5e-403d-8da3-a8da696490ee", + "path": "/f", + "interactions": "", + "processors": "", + "groups": "Play", + "action": "Interactive", + "isComposite": false, + "isPartOfComposite": false } ] } diff --git a/Assets/Prefabs/爱欲品.prefab b/Assets/Prefabs/爱欲品.prefab index 6a34674..71231ef 100644 --- a/Assets/Prefabs/爱欲品.prefab +++ b/Assets/Prefabs/爱欲品.prefab @@ -309,3 +309,5 @@ MonoBehaviour: catchOffset: {x: 0, y: 0, z: 0} breakFreeCount: 5 breakFreeCountLeft: 0 + hasOwner: 0 + coinObj: {fileID: 2312258847787666435, guid: 012ab20ff74f1af4e802d80157b4b4e0, type: 3} diff --git a/Assets/Prefabs/硬币.prefab b/Assets/Prefabs/硬币.prefab new file mode 100644 index 0000000..8e76184 --- /dev/null +++ b/Assets/Prefabs/硬币.prefab @@ -0,0 +1,232 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &830885186 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 830885187} + - component: {fileID: 830885188} + m_Layer: 0 + m_Name: "\u6361\u62FE" + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &830885187 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 830885186} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 2312258847787666463} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!61 &830885188 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 830885186} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0, y: 0} + oldSize: {x: 0, y: 0} + newSize: {x: 0, y: 0} + adaptiveTilingThreshold: 0 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 1, y: 1} + m_EdgeRadius: 0 +--- !u!1 &2312258847787666435 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2312258847787666463} + - component: {fileID: 2312258847787666462} + - component: {fileID: 2312258847787666433} + - component: {fileID: 2312258847787666432} + - component: {fileID: 2312258847787666460} + - component: {fileID: 1219690094} + m_Layer: 6 + m_Name: "\u786C\u5E01" + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2312258847787666463 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2312258847787666435} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0.01860857, y: -2.61, z: 0} + m_LocalScale: {x: 0.3, y: 0.3, z: 0.3} + m_Children: + - {fileID: 830885187} + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!212 &2312258847787666462 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2312258847787666435} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + 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: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_Sprite: {fileID: 7482667652216324306, guid: 48e93eef0688c4a259cb0eddcd8661f7, 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!61 &2312258847787666433 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2312258847787666435} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 6200000, guid: 6129a8c119a09f446a90609124f9bfbe, type: 2} + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0.5, y: 0.5} + oldSize: {x: 1, y: 1} + newSize: {x: 1, y: 1} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 1, y: 1} + m_EdgeRadius: 0 +--- !u!50 &2312258847787666432 +Rigidbody2D: + serializedVersion: 4 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2312258847787666435} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 1 + m_LinearDrag: 0 + m_AngularDrag: 0.05 + m_GravityScale: 1 + m_Material: {fileID: 0} + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 0 +--- !u!114 &2312258847787666460 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2312258847787666435} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1b5bb24587f94d94f81dfbe3ac6df31c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_rigidbody: {fileID: 0} +--- !u!61 &1219690094 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2312258847787666435} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0.5, y: 0.5} + oldSize: {x: 1, y: 1} + newSize: {x: 1, y: 1} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 2.62, y: 1} + m_EdgeRadius: 0 diff --git a/Assets/Prefabs/硬币.prefab.meta b/Assets/Prefabs/硬币.prefab.meta new file mode 100644 index 0000000..7abf7aa --- /dev/null +++ b/Assets/Prefabs/硬币.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 012ab20ff74f1af4e802d80157b4b4e0 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/DiZangStageTest.unity b/Assets/Scenes/DiZangStageTest.unity index a0bc79c..48d6432 100644 --- a/Assets/Scenes/DiZangStageTest.unity +++ b/Assets/Scenes/DiZangStageTest.unity @@ -179,6 +179,7 @@ GameObject: - component: {fileID: 295389548} - component: {fileID: 295389547} - component: {fileID: 295389549} + - component: {fileID: 295389550} m_Layer: 0 m_Name: "\u585E\u94B1\u7BB1" m_TagString: Untagged @@ -263,7 +264,34 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b74c9082c8d1a6044b40dfae78d89cab, type: 3} m_Name: m_EditorClassIdentifier: - hasMoney: 0 + itemName: 0 + hasMoney: 1 +--- !u!61 &295389550 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 295389546} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0.5, y: 0.5} + oldSize: {x: 1, y: 1} + newSize: {x: 1, y: 1} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 1, y: 1} + m_EdgeRadius: 0 --- !u!1 &525554315 GameObject: m_ObjectHideFlags: 0 @@ -274,7 +302,7 @@ GameObject: m_Component: - component: {fileID: 525554317} - component: {fileID: 525554316} - m_Layer: 0 + m_Layer: 8 m_Name: "\u7A7A\u6C14\u5899\uFF08\u53F3" m_TagString: Untagged m_Icon: {fileID: 0} @@ -403,6 +431,8 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 1871661725} + - {fileID: 575347545} + - {fileID: 2086773092} m_Father: {fileID: 0} m_RootOrder: 10 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -435,6 +465,7 @@ MonoBehaviour: - {fileID: 28312535} - {fileID: 2059592404} CallAiYuPinEndTime: 5 + throwingPointGroupUse: [] --- !u!61 &552131611 BoxCollider2D: m_ObjectHideFlags: 0 @@ -506,6 +537,152 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 18 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &575347544 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 575347545} + - component: {fileID: 575347546} + - component: {fileID: 575347547} + - component: {fileID: 575347548} + - component: {fileID: 575347549} + m_Layer: 2 + m_Name: "\u624B" + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &575347545 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 575347544} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 10, z: 0} + m_LocalScale: {x: 1, y: 10.01, z: 1} + m_Children: [] + m_Father: {fileID: 552131609} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!212 &575347546 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 575347544} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + 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: 0 + m_SortingLayer: 0 + m_SortingOrder: 3 + m_Sprite: {fileID: 7482667652216324306, guid: 48e93eef0688c4a259cb0eddcd8661f7, 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!114 &575347547 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 575347544} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9301adfb53cc18946a129399d50298bf, type: 3} + m_Name: + m_EditorClassIdentifier: + owner: {fileID: 0} + TakeMoneyTime: 2 +--- !u!61 &575347548 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 575347544} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0.5, y: 0.5} + oldSize: {x: 1, y: 1} + newSize: {x: 1, y: 1} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 1, y: 1} + m_EdgeRadius: 0 +--- !u!50 &575347549 +Rigidbody2D: + serializedVersion: 4 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 575347544} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 200 + m_LinearDrag: 0 + m_AngularDrag: 0.05 + m_GravityScale: 0 + m_Material: {fileID: 0} + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 4 --- !u!1 &609324641 GameObject: m_ObjectHideFlags: 0 @@ -517,7 +694,7 @@ GameObject: - component: {fileID: 609324642} - component: {fileID: 609324644} - component: {fileID: 609324643} - m_Layer: 0 + m_Layer: 3 m_Name: "\u9570\u5200\u98DE\u51FA\u6D88\u9664\u89E6\u53D1\u5668\u53F3" m_TagString: Untagged m_Icon: {fileID: 0} @@ -630,7 +807,7 @@ GameObject: - component: {fileID: 761593105} - component: {fileID: 761593104} - component: {fileID: 761593103} - m_Layer: 0 + m_Layer: 3 m_Name: "\u73A9\u5BB6" m_TagString: Untagged m_Icon: {fileID: 0} @@ -745,6 +922,22 @@ MonoBehaviour: m_CallState: 2 m_ActionId: d92eaf00-7eaf-4292-ae80-6bfff20b5930 m_ActionName: Normal/Sickle[/Keyboard/u,/XInputControllerWindows/rightTrigger] + - m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 761593105} + m_TargetAssemblyTypeName: MyPlayer, Assembly-CSharp + m_MethodName: OnInteractive + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_ActionId: 7cf0a787-dc2d-42b1-9ed9-c840ccfa3ce9 + m_ActionName: Normal/Interactive[/XInputControllerWindows/buttonNorth,/Keyboard/f] m_NeverAutoSwitchControlSchemes: 0 m_DefaultControlScheme: Play m_DefaultActionMap: Normal @@ -769,14 +962,16 @@ MonoBehaviour: sicklePrefab: {fileID: 8280362330273855463, guid: 2e2fb120ae20d5e4faaad5a2a2fcca30, type: 3} HP: 10 hitToflyParameter: {x: 10, y: 10} + isCatching: 0 + catingAiYuPin: {fileID: 0} + catching: {fileID: 0} + specialMoneyCount: 0 inputDir: 0 isLanding: 0 hammerCDLeft: 0 sickleCDLeft: 0 inControl: 1 HPLeft: 0 - isCatching: 0 - catingAiYuPin: {fileID: 0} --- !u!50 &761593106 Rigidbody2D: serializedVersion: 4 @@ -903,7 +1098,7 @@ GameObject: m_Component: - component: {fileID: 861291080} - component: {fileID: 861291081} - m_Layer: 0 + m_Layer: 3 m_Name: "\u9524\u5B50\u7684\u65CB\u8F6C\u4E2D\u5FC3" m_TagString: Untagged m_Icon: {fileID: 0} @@ -1510,7 +1705,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1226109627} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.037861586, y: -1.6225245, z: -10} + m_LocalPosition: {x: 0.037862062, y: -1.6225212, z: -10} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -1723,7 +1918,7 @@ GameObject: - component: {fileID: 1322954041} - component: {fileID: 1322954040} - component: {fileID: 1322954039} - m_Layer: 0 + m_Layer: 3 m_Name: "\u9524\u5B50" m_TagString: Untagged m_Icon: {fileID: 0} @@ -1929,7 +2124,7 @@ GameObject: - component: {fileID: 1625727453} - component: {fileID: 1625727455} - component: {fileID: 1625727454} - m_Layer: 0 + m_Layer: 3 m_Name: "\u9570\u5200\u98DE\u51FA\u6D88\u9664\u89E6\u53D1\u5668\u5DE6" m_TagString: Untagged m_Icon: {fileID: 0} @@ -2176,7 +2371,7 @@ GameObject: m_Component: - component: {fileID: 1678223710} - component: {fileID: 1678223709} - m_Layer: 0 + m_Layer: 8 m_Name: "\u7A7A\u6C14\u5899\uFF08\u5DE6" m_TagString: Untagged m_Icon: {fileID: 0} @@ -2526,7 +2721,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 1954591987} - m_Layer: 0 + m_Layer: 3 m_Name: "\u9570\u5200\u53D1\u5C04\u70B9" m_TagString: Untagged m_Icon: {fileID: 0} @@ -2558,7 +2753,7 @@ GameObject: - component: {fileID: 1963485815} - component: {fileID: 1963485814} - component: {fileID: 1963485816} - m_Layer: 0 + m_Layer: 8 m_Name: "01-1\u573A\u666F\u8349\u56FE" m_TagString: "\u5730\u9762" m_Icon: {fileID: 0} @@ -2830,6 +3025,36 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 19 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &2086773091 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2086773092} + m_Layer: 2 + m_Name: "\u624B\u7684\u7EC8\u70B9\u4F4D\u7F6E" + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2086773092 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2086773091} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0.12, y: 4.8, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 552131609} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2132302661 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/AiYuPin.cs b/Assets/Scripts/AiYuPin.cs index 3b093a0..9dfa130 100644 --- a/Assets/Scripts/AiYuPin.cs +++ b/Assets/Scripts/AiYuPin.cs @@ -30,6 +30,16 @@ public class AiYuPin : NormalEnemy /// [Header("玩家挣脱爱欲品还需要多少次方向转换操作")][FoldoutGroup("爱欲品")][ReadOnly] public int breakFreeCountLeft; + /// + /// 这个爱欲品有主人吗?也就是地藏 + /// + [HideInInspector] + public bool hasOwner; + /// + /// 打死后掉落的钱的预制体 + /// + [Header("打死后掉落的钱的预制体")][FoldoutGroup("预制体")] + public GameObject coinObj; // _____ _ _ // | __ \ (_) | | @@ -78,6 +88,7 @@ public class AiYuPin : NormalEnemy //初始化爱欲品属性 breakFreeCountLeft = breakFreeCount;//初始化挣脱需要的操作次数 target = FindObjectOfType().transform;//初始化追踪目标为玩家 + if(FindObjectOfType()) hasOwner = true; } /// @@ -96,6 +107,21 @@ public class AiYuPin : NormalEnemy transform.rotation.z); } + /// + /// 制造一个特殊的钱,用来塞钱的那种 + /// + private void MakeAnCoin(){ + GameObject coin = Instantiate( + coinObj, + transform.position, + Quaternion.identity + ); + coin.GetComponent().velocity = new Vector2( + Random.Range(-1f,1f), + Random.Range(-1f,1f) + ).normalized * (5f); + } + // ______ _ // | ____| | | // | |____ _____ _ __ | |_ @@ -190,6 +216,15 @@ public class AiYuPin : NormalEnemy FindObjectOfType().BreakFreeCompletely(); } + protected override void OnDead(){ + base.OnDead(); + if( + hasOwner && + target.GetComponent().specialMoneyCount == 0 && + FindObjectOfType() == null + )MakeAnCoin(); + } + /// /// 玩家尝试挣脱的时候触发这个 /// diff --git a/Assets/Scripts/Coin.cs b/Assets/Scripts/Coin.cs new file mode 100644 index 0000000..335a67d --- /dev/null +++ b/Assets/Scripts/Coin.cs @@ -0,0 +1,50 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// +/// 用来塞的钱那个类,但是是小怪打死后掉落的那种 +/// +[RequireComponent(typeof(BoxCollider2D))] +[RequireComponent(typeof(Rigidbody2D))] +public class Coin : MonoBehaviour +{ + public Rigidbody2D m_rigidbody; + + void Start(){ + Init(); + } + + void Init(){ + m_rigidbody = GetComponent(); + transform.GetChild(0).gameObject.AddComponent().owner = this; + } + + public void PlayerPickUpMe(){ + Destroy(gameObject); + } + + + + /// + /// 本类的工具类,初始化时给子物体装一个组件,用来检测玩家是否能捡拾硬币 + /// + private class PickUpCoin : Interactive + { + /// + /// 这个捡拾范围所存在于的硬币 + /// + public Coin owner; + void Start(){ + Init(); + } + + private void Init(){ + itemName = ItemName.硬币; + } + public override void OnCall(){ + owner.PlayerPickUpMe(); + } + } + +} \ No newline at end of file diff --git a/Assets/Scripts/Coin.cs.meta b/Assets/Scripts/Coin.cs.meta new file mode 100644 index 0000000..a228343 --- /dev/null +++ b/Assets/Scripts/Coin.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1b5bb24587f94d94f81dfbe3ac6df31c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/DiZang.cs b/Assets/Scripts/DiZang.cs index e9db6ec..6b2002a 100644 --- a/Assets/Scripts/DiZang.cs +++ b/Assets/Scripts/DiZang.cs @@ -62,6 +62,7 @@ public class DiZang : Enemy [SerializeField][ListDrawerSettings][ReadOnly] private List throwingPointGroupUse; private Bell myBell; + private DiZangsHadn myHand; // _____ _ _ ____ _ // / ____| | | | _ \ | | @@ -84,7 +85,8 @@ public class DiZang : Enemy //找到组件和物体 moneyBox = FindObjectOfType(); player = FindObjectOfType(); - myBell = transform.GetChild(0).GetComponent(); + myBell = transform.Find("钟").GetComponent(); + myHand = transform.Find("手").GetComponent(); //告诉钟自己是主人 myBell.owner = this; } @@ -110,7 +112,7 @@ public class DiZang : Enemy /// 召唤爱欲品的时候Call这个 /// private IEnumerator CallAiYuPin(){ - Debug.Log("正在使用:召唤"); + Debug.Log("正在使用:召唤"); //确定玩家在上半边还是下半边 PlayerState playerState = ((player.transform.position.y > aiYuPinBuildLimit) ? PlayerState.上半: PlayerState.下半); @@ -158,7 +160,7 @@ public class DiZang : Enemy /// 敲钟的时候Call这个 /// private IEnumerator RingTheBell(){ - Debug.Log("正在使用:敲钟"); + Debug.Log("正在使用:敲钟"); yield return new WaitForEndOfFrame(); myBell.ATK(player); } @@ -168,8 +170,8 @@ public class DiZang : Enemy /// private IEnumerator TakeTheMoney(){ yield return new WaitForEndOfFrame(); - Debug.Log("正在使用:拿钱"); - + Debug.Log("正在使用:拿钱"); + myHand.ATK(); } // ______ _ diff --git a/Assets/Scripts/DiZangsHadn.cs b/Assets/Scripts/DiZangsHadn.cs new file mode 100644 index 0000000..29ed398 --- /dev/null +++ b/Assets/Scripts/DiZangsHadn.cs @@ -0,0 +1,197 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using DG.Tweening; +using Sirenix.OdinInspector; + +/// +/// 地藏的手组件 +/// +public class DiZangsHadn : MonoBehaviour +{ + // _____ _ _ _ + // | __ \ | | | (_) + // | |__) | _| |__ | |_ ___ + // | ___/ | | | '_ \| | |/ __| + // | | | |_| | |_) | | | (__ + // |_| \__,_|_.__/|_|_|\___| + [HideInInspector] + public DiZang owner; + + /// + /// 手下落到目标点后会停留多长时间 + /// + public float TakeMoneyTime; + + + // _____ _ _ + // | __ \ (_) | | + // | |__) | __ ___ ____ _| |_ ___ + // | ___/ '__| \ \ / / _` | __/ _ \ + // | | | | | |\ V / (_| | || __/ + // |_| |_| |_| \_/ \__,_|\__\___| + + /// + /// 手拿钱移动到的目标点位 + /// + private Transform target; + /// + /// 浮动动画,用来重启浮动动画解决Tween的一些局限性问题 + /// + private Tweener floatTweener; + /// + /// 手在屏幕外的起点 + /// + private Vector3 start; + /// + /// 此时是否可被攻击 + /// + [Header("此时能否被攻击")][SerializeField] + private bool canBeHit = false; + /// + /// 是否被玩家的攻击打断了? + /// + [Header("此时是否被打断")][SerializeField] + private bool wasInteruput; + + // _____ _ _ ____ _ + // / ____| | | | _ \ | | + // | | __ _| | | |_) | __ _ ___| | __ + // | | / _` | | | _ < / _` |/ __| |/ / + // | |___| (_| | | | |_) | (_| | (__| < + // \_____\__,_|_|_|____/ \__,_|\___|_|\_\ + void Start(){Init();} + + // _ _ _ + // | \ | | | | + // | \| | ___ _ __ _ __ ___ __ _| | + // | . ` |/ _ \| '__| '_ ` _ \ / _` | | + // | |\ | (_) | | | | | | | | (_| | | + // |_| \_|\___/|_| |_| |_| |_|\__,_|_| + private void Init(){ + //找到需要的物体和组件 + owner = FindObjectOfType(); + target = owner.transform.Find("手的终点位置"); + start = transform.position; + } + + /// + /// 主人发命令拿钱时触发 + /// + public void ATK(){ + //创建、播放并记录一个抖动动画 + Tweener floatTweener = transform.DOShakePosition(2f,0.05f,50,90,false,false); + this.floatTweener = floatTweener; + //创建、播放并记录一个下移动画 + Tweener tweener = transform.DOMoveY( + target.position.y, + 2f + ); + //创建并给予下移动画结束事件 + TweenCallback action = () =>{ + //下移结束,标记为可被攻击 + canBeHit = true; + //删掉正在播放的抖动动画 + floatTweener.Kill(); + //拿走钱 + FindObjectOfType().OnBeTakeMoney(); + //开始协程,等待拿钱时间结束后上移回去手 + Invoke("TakeMoneyAndRun",TakeMoneyTime); + }; + tweener.OnComplete(action); + } + + /// + /// 手到塞钱箱后触发,执行等待和返回操作 + /// + private void TakeMoneyAndRun(){ + //如果没有被打断,才会执行正常的上移 + if(!wasInteruput){ + //创建、播放并记录一个抖动动画 + Tweener floatTweener = transform.DOShakePosition(2f,0.05f,50,90,false,false); + this.floatTweener = floatTweener; + //创建、播放并记录一个上移动画 + Tweener tweener = transform.DOMoveY( + start.y, + 2f + ); + //创建并给予下移动画结束事件 + TweenCallback action = () =>{ + //为下一次下移做准备,标记自身不可再被击中 + canBeHit = false; + //删掉抖动动画 + floatTweener.Kill(); + //通知主人,攻击结束 + owner.ATKEnd(); + }; + tweener.OnComplete(action); + } + } + + // ______ _ + // | ____| | | + // | |____ _____ _ __ | |_ + // | __\ \ / / _ \ '_ \| __| + // | |___\ V / __/ | | | |_ + // |______\_/ \___|_| |_|\__| + + /// + /// 当创到玩家触发,触发玩家的被击功能 + /// + private void OnTouchThePlayer(MyPlayer player){ + //告诉玩家,你被攻击了 + player.OnBeHit(owner.ATK, + ((transform.position.x - + player.transform.position.x) + > 0) ? 1 : -1);//通过自身位置和玩家位置的比较来返回玩家本次的受击方向 + } + + /// + /// 当手被攻击触发 + /// + public void OnBeHit(MyPlayer.AtkMethod hitMethod, int hitDir){ + //标记此时被打断 + wasInteruput = true; + CancelInvoke("TakeMoneyAndRun"); + //突然抬起一段,伴随着剧烈的震动 + //创建、播放并记录一个抖动动画 + Tweener floatTweener = transform.DOShakePosition(0.5f,0.5f,50,90,false,false); + this.floatTweener = floatTweener; + //创建一个猛烈上移动画 + Tweener tweener = transform.DOMoveY( + transform.position.y + 2f, + 0.5f + ); + //给猛烈上移动画添加结束事件 + TweenCallback action = () =>{ + floatTweener.Kill(); + canBeHit = false; + wasInteruput = false; + Invoke("TakeMoneyAndRun",TakeMoneyTime); + }; + tweener.OnComplete(action); + + //结算生命值 + owner.HPLeft -= MyPlayer.atkMethodMagnification[hitMethod]; + //看下死了没 + if(owner.CheckDead()) {} + } + + // _____ _ _ _ _ + // / ____| | | (_) (_) + // | | ___ | | |_ ___ _ ___ _ __ + // | | / _ \| | | / __| |/ _ \| '_ \ + // | |___| (_) | | | \__ \ | (_) | | | | + // \_____\___/|_|_|_|___/_|\___/|_| |_| + protected void OnCollisionEnter2D(Collision2D other)//当有物体碰上 + { + if(other.collider.gameObject.TryGetComponent(out MyPlayer player)) + {OnTouchThePlayer(player);}//如果创到的是玩家,则Call事件 + //如果被镰刀创到,Call一下OnBeHit事件,传入攻击方式和攻击来袭方向 + else if(other.collider.gameObject.TryGetComponent(out Sickle sickle)){ + if(canBeHit) + OnBeHit(MyPlayer.AtkMethod.镰刀, + (transform.position.x - sickle.transform.position.x > 0) ? -1 : 1); + Destroy(sickle.gameObject);} + } +} diff --git a/Assets/Scripts/DiZangsHadn.cs.meta b/Assets/Scripts/DiZangsHadn.cs.meta new file mode 100644 index 0000000..6a25e99 --- /dev/null +++ b/Assets/Scripts/DiZangsHadn.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9301adfb53cc18946a129399d50298bf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Enemy.cs b/Assets/Scripts/Enemy.cs index 1692a9b..11b4070 100644 --- a/Assets/Scripts/Enemy.cs +++ b/Assets/Scripts/Enemy.cs @@ -64,7 +64,7 @@ public class Enemy : MonoBehaviour /// 当前生命值 /// [ReadOnly][SerializeField][ProgressBar(0,10,0.15f,0.47f,0.74f)][FoldoutGroup("状态")] - protected float HPLeft; + public float HPLeft; // ______ _ @@ -110,7 +110,7 @@ public class Enemy : MonoBehaviour /// /// 看看死了没 /// - protected bool CheckDead(){return !(HPLeft > 0);} + public bool CheckDead(){return !(HPLeft > 0);} // _____ _ _ _ _ diff --git a/Assets/Scripts/Interactive.cs b/Assets/Scripts/Interactive.cs new file mode 100644 index 0000000..da67add --- /dev/null +++ b/Assets/Scripts/Interactive.cs @@ -0,0 +1,37 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// +/// 可交互物体基类 +/// +public class Interactive : MonoBehaviour +{ + + /// + /// 这个是什么东西 + /// + public enum ItemName{ + 塞钱箱, + 硬币 + }; + + public ItemName itemName; + + //这是一对碰撞检测代码。当玩家进入,将自身传给玩家。当玩家退出,把玩家的catch清空 + void OnTriggerEnter2D(Collider2D other){ + if(other.TryGetComponent(out MyPlayer player)) + player.catching = this; + } + void OnTriggerExit2D(Collider2D other) + { + if(other.TryGetComponent(out MyPlayer player)){ + //如果目前退出当前交互区域的时候,玩家的捕捉物体是自己,才把玩家的捕捉清空。否则说明玩家在推出前就捕捉到了新的 + //对象。这样是用来解决排布密集的可交互物体的问题 + if(player.catching == this)player.catching = null; + } + } + + public virtual void OnCall(){} + public virtual void OnBeGaveMoney(){} +} diff --git a/Assets/Scripts/Interactive.cs.meta b/Assets/Scripts/Interactive.cs.meta new file mode 100644 index 0000000..917036f --- /dev/null +++ b/Assets/Scripts/Interactive.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 32fadff7625f74747a7fb890f3ff39df +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/MoneyBox.cs b/Assets/Scripts/MoneyBox.cs index 54c7e56..09e209e 100644 --- a/Assets/Scripts/MoneyBox.cs +++ b/Assets/Scripts/MoneyBox.cs @@ -1,14 +1,37 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using Sirenix.OdinInspector; /// /// 塞钱箱类 /// -public class MoneyBox : MonoBehaviour +[RequireComponent(typeof(BoxCollider2D))] +public class MoneyBox : Interactive { /// /// 箱子里有钱吗? /// - public bool hasMoney = false; + + public bool hasMoney; + void Start(){ + Init(); + } + + private void Init(){ + itemName = ItemName.塞钱箱; + } + public override void OnCall(){ + OnBeGaveMoney(); + } + + /// + /// 当被塞钱的时候触发 + /// + public override void OnBeGaveMoney(){hasMoney = true;} + + /// + /// 当被拿钱的时候触发 + /// + public void OnBeTakeMoney(){hasMoney = false;} } diff --git a/Assets/Scripts/MyPlayer.cs b/Assets/Scripts/MyPlayer.cs index 20b30c8..8f69a73 100644 --- a/Assets/Scripts/MyPlayer.cs +++ b/Assets/Scripts/MyPlayer.cs @@ -17,9 +17,9 @@ public class MyPlayer : MonoBehaviour // | | | |_| | |_) | | | (__ // |_| \__,_|_.__/|_|_|\___| - [Header("玩家平时地面移动的速度")][FoldoutGroup("Info")] + [Header("玩家平时地面移动的速度")][FoldoutGroup("属性")] public float speed = 10f; - [Header("玩家跳跃力度的大小")][FoldoutGroup("Info")] + [Header("玩家跳跃力度的大小")][FoldoutGroup("属性")] public float jumpForce = 10f; [FoldoutGroup("CD")][Header("挥动锤子的CD时长")] public float hammerCD = 1f; @@ -31,7 +31,7 @@ public class MyPlayer : MonoBehaviour /// /// 生命值上限 /// - [FoldoutGroup("Info")][Header("生命值上限")] + [FoldoutGroup("属性")][Header("生命值上限")] public float HP; /// /// 被击飞后的飞行方向的调整值 @@ -46,7 +46,7 @@ public class MyPlayer : MonoBehaviour /// /// 记录此时自己是否被爱欲品缠抱 /// - [Header("被缠抱了吗?")][SerializeField][ReadOnly][FoldoutGroup("Info")] + [Header("被缠抱了吗?")][SerializeField][ReadOnly][FoldoutGroup("状态")] public bool isCatching = false; /// /// 正抓着玩家的爱欲品 @@ -54,6 +54,17 @@ public class MyPlayer : MonoBehaviour [HideInInspector] public AiYuPin catingAiYuPin; + /// + /// 玩家此时捕捉着的可交互物体 + /// + [Header("玩家此时捕捉着的可交互物体")][FoldoutGroup("状态")][ReadOnly] + public Interactive catching; + /// + /// 当前身上有多少特殊硬币,用来塞钱的那种 + /// + [FoldoutGroup("状态")][Header("当前身上有多少特殊硬币,用来塞钱的那种")] + public int specialMoneyCount = 0; + // _____ _ _ // | __ \ (_) | | // | |__) | __ ___ ____ _| |_ ___ @@ -62,9 +73,9 @@ public class MyPlayer : MonoBehaviour // |_| |_| |_| \_/ \__,_|\__\___| private Rigidbody2D m_rigidbody;//自身刚体组件 - [SerializeField][ReadOnly][FoldoutGroup("Info")] + [SerializeField][ReadOnly][FoldoutGroup("状态")] private int inputDir;//当前输入方向,-1左,1右,0静止 - [SerializeField][ReadOnly][FoldoutGroup("Info")] + [SerializeField][ReadOnly][FoldoutGroup("状态")] private bool isLanding;//记录自己当前是否着地 private DOTweenAnimation wavingAnimation;//锤子挥动动画组件 private SpriteRenderer hammerSprite;//锤子的图片组件 @@ -77,9 +88,9 @@ public class MyPlayer : MonoBehaviour private Transform sickleFirePoint;//镰刀发射点的transform private Transform sickleClearerL;//左边的镰刀清除触发器 private Transform sickleClearerR;//右边的镰刀清除触发器 - [FoldoutGroup("其他",false,1)][Header("玩家现在是否处于控制状态下(物理)")][SerializeField][ReadOnly] + [FoldoutGroup("状态",false,1)][Header("玩家现在是否处于控制状态下(物理)")][SerializeField][ReadOnly] private bool inControl = true; - [SerializeField][ReadOnly][ProgressBar(0,10,0.15f,0.47f,0.74f)][FoldoutGroup("Info")] + [SerializeField][ReadOnly][ProgressBar(0,10,0.15f,0.47f,0.74f)][FoldoutGroup("状态")] private float HPLeft; /// /// 自身动画控制器组件 @@ -226,6 +237,20 @@ public class MyPlayer : MonoBehaviour HPLeft -= FindObjectOfType().ATK; } + /// + /// 塞钱 + /// + private void GiveMoney(){ + specialMoneyCount--; + } + + /// + /// 捡到钱了 + /// + private void IPickedACoin(){ + specialMoneyCount++; + } + // _____ _ _ _ _ // / ____| | | (_) (_) // | | ___ | | |_ ___ _ ___ _ __ @@ -301,18 +326,37 @@ public class MyPlayer : MonoBehaviour public void OnSickle(InputAction.CallbackContext context) { - if(context.started && sickleCDLeft <= 0 && inControl) - { + if(context.started && sickleCDLeft <= 0 && inControl){ Sickle sickle = Instantiate( - sicklePrefab, - sickleFirePoint.position, - Quaternion.identity). - GetComponent(); + sicklePrefab, + sickleFirePoint.position, + Quaternion.identity + ).GetComponent(); sickle.dir = faceDir; sickleCDLeft = sickleCD; } } + public void OnInteractive(InputAction.CallbackContext context){ + if(context.performed && catching != null){ + switch(catching.itemName){ + case Interactive.ItemName.塞钱箱 : + if( + specialMoneyCount > 0 && + !FindObjectOfType().hasMoney + ){ + catching.OnCall(); + GiveMoney(); + } + break; + case Interactive.ItemName.硬币 : + IPickedACoin(); + catching.OnCall(); + break; + } + } + } + // ______ _ // | ____| | | // | |____ _____ _ __ | |_ diff --git a/Assets/材质/弹性.physicsMaterial2D b/Assets/材质/弹性.physicsMaterial2D new file mode 100644 index 0000000..fd6a526 --- /dev/null +++ b/Assets/材质/弹性.physicsMaterial2D @@ -0,0 +1,11 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!62 &6200000 +PhysicsMaterial2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: "\u5F39\u6027" + friction: 0.4 + bounciness: 0.5 diff --git a/Assets/材质/弹性.physicsMaterial2D.meta b/Assets/材质/弹性.physicsMaterial2D.meta new file mode 100644 index 0000000..8e504c5 --- /dev/null +++ b/Assets/材质/弹性.physicsMaterial2D.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6129a8c119a09f446a90609124f9bfbe +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 6200000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Logs/ApiUpdaterCheck.txt b/Logs/ApiUpdaterCheck.txt index ad13c02..d8ac907 100644 --- a/Logs/ApiUpdaterCheck.txt +++ b/Logs/ApiUpdaterCheck.txt @@ -135,3 +135,13 @@ C# parse time : 185ms candidates check time : 34ms console write time : 0ms +[api-updater (non-obsolete-error-filter)] 2021/12/11 0:02:14 : Starting D:/unity/Editor/2020.3.20f1c1/Editor/Data/Tools/ScriptUpdater/APIUpdater.NonObsoleteApiUpdaterDetector.exe +[api-updater (non-obsolete-error-filter)] +---------------------------------- +jit/startup time : 835.39ms +moved types parse time: 53ms +candidates parse time : 1ms +C# parse time : 673ms +candidates check time : 49ms +console write time : 1ms + diff --git a/ProjectSettings/Physics2DSettings.asset b/ProjectSettings/Physics2DSettings.asset index 6cfcdda..a7c7028 100644 --- a/ProjectSettings/Physics2DSettings.asset +++ b/ProjectSettings/Physics2DSettings.asset @@ -53,4 +53,4 @@ Physics2DSettings: m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} - m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + m_LayerCollisionMatrix: bfffffffbfffffffbfffffffbfffffffbfffffffbfffffff00ffffffbfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 2855949..905506a 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -10,12 +10,12 @@ TagManager: - Default - TransparentFX - Ignore Raycast - - + - "\u73A9\u5BB6" - Water - UI - - - - - - + - "\u786C\u5E01" + - "\u602A\u7269" + - "\u5730\u9762" - - -