diff --git a/Assets/InputAssets/Player.cs b/Assets/InputAssets/Player.cs index f4e2396..15d051e 100644 --- a/Assets/InputAssets/Player.cs +++ b/Assets/InputAssets/Player.cs @@ -194,12 +194,12 @@ public class @Player : IInputActionCollection, IDisposable ""devices"": [ { ""devicePath"": """", - ""isOptional"": false, + ""isOptional"": true, ""isOR"": false }, { ""devicePath"": """", - ""isOptional"": true, + ""isOptional"": false, ""isOR"": false } ] diff --git a/Assets/InputAssets/Player.inputactions b/Assets/InputAssets/Player.inputactions index 2104cfd..7be13f3 100644 --- a/Assets/InputAssets/Player.inputactions +++ b/Assets/InputAssets/Player.inputactions @@ -181,12 +181,12 @@ "devices": [ { "devicePath": "", - "isOptional": false, + "isOptional": true, "isOR": false }, { "devicePath": "", - "isOptional": true, + "isOptional": false, "isOR": false } ] diff --git a/Assets/Scenes/test.unity b/Assets/Scenes/test.unity index 53c0040..6acc4f9 100644 --- a/Assets/Scenes/test.unity +++ b/Assets/Scenes/test.unity @@ -960,6 +960,107 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1563287656 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1563287659} + - component: {fileID: 1563287658} + - component: {fileID: 1563287657} + m_Layer: 0 + m_Name: "\u5C0F\u602A" + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1563287657 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1563287656} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d45cf1348b8a0194f89c4dbf729c14df, type: 3} + m_Name: + m_EditorClassIdentifier: + HP: 10 + ATK: 1 + speed: 10 + coin: 10 + HPLeft: 0 + state: 0 +--- !u!212 &1563287658 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1563287656} + 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!4 &1563287659 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1563287656} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0.70010865, y: 0.6895708, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 4 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1802393384 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Enemy.cs b/Assets/Scripts/Enemy.cs new file mode 100644 index 0000000..a679f53 --- /dev/null +++ b/Assets/Scripts/Enemy.cs @@ -0,0 +1,129 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Sirenix.OdinInspector; + + +/// +/// 敌人的基类,一般怪物都继承其而来 +/// +public class Enemy : MonoBehaviour +{ + // _____ _ _ _ + // | __ \ | | | (_) + // | |__) | _| |__ | |_ ___ + // | ___/ | | | '_ \| | |/ __| + // | | | |_| | |_) | | | (__ + // |_| \__,_|_.__/|_|_|\___| + + /// + /// 生命值上限 + /// + [BoxGroup("属性")][Header("生命值上限")] + public float HP; + + /// + /// 攻击力 + /// + [BoxGroup("属性")][Header("攻击力")] + public float ATK; + + /// + /// 速度 + /// + [BoxGroup("属性")][Header("速度")] + public float speed; + + /// + /// 打死后掉多少金币 + /// + [BoxGroup("属性")][Header("掉落金币数")] + public int coin; + + /// + /// 怪物拥有的几种状态 + /// + public enum State{wander,seek,atk,dead}; + + // _____ _ _ + // | __ \ (_) | | + // | |__) | __ ___ ____ _| |_ ___ + // | ___/ '__| \ \ / / _` | __/ _ \ + // | | | | | |\ V / (_| | || __/ + // |_| |_| |_| \_/ \__,_|\__\___| + + /// + /// 当前生命值 + /// + [ReadOnly][SerializeField][ProgressBar(0,10,0.15f,0.47f,0.74f)] + protected float HPLeft; + + /// + /// 当前状态 + /// + [EnumPaging][SerializeField][ReadOnly][Header("当前状态")] + protected State state; + + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + + // ______ _ + // | ____| | | + // | |____ _____ _ __ | |_ + // | __\ \ / / _ \ '_ \| __| + // | |___\ V / __/ | | | |_ + // |______\_/ \___|_| |_|\__| + + /// + /// 当怪物死的时候Call这个函数 + /// + protected void OnDead(){} + + /// + /// 当怪物触碰到玩家的时候Call这个 + /// + protected void OnTouchThePlayer(){} + + /// + /// 当怪物被打的时候触发 + /// + /// 攻击方式,枚举类型,具体看MyPlayer + /// 受击方向,-1左,1右 + protected void OnBeHit(MyPlayer.AtkMethod hitMethod,int hitDir){} + + /// + /// 当怪物发现玩家的时候Call这个 + /// + protected void OnFindThePlayer(){} + + + // _____ _ _ _ _ + // / ____| | | (_) (_) + // | | ___ | | |_ ___ _ ___ _ __ + // | | / _ \| | | / __| |/ _ \| '_ \ + // | |___| (_) | | | \__ \ | (_) | | | | + // \_____\___/|_|_|_|___/_|\___/|_| |_| + protected void OnCollisionEnter2D(Collision2D other)//当有物体碰上 + { + if(other.gameObject.TryGetComponent(out MyPlayer player)) + {OnTouchThePlayer();}//如果创到的是玩家,则Call事件 + } + protected void OnTriggerEnter2D(Collider2D other) + { + if(other.gameObject.TryGetComponent(out MyPlayer player)) + {OnFindThePlayer();}//如果监视范围出现玩家,则Call事件 + } + + + +} diff --git a/Assets/Scripts/Enemy.cs.meta b/Assets/Scripts/Enemy.cs.meta new file mode 100644 index 0000000..eec7db9 --- /dev/null +++ b/Assets/Scripts/Enemy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d45cf1348b8a0194f89c4dbf729c14df +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/MyPlayer.cs b/Assets/Scripts/MyPlayer.cs index 0765e57..e61ceec 100644 --- a/Assets/Scripts/MyPlayer.cs +++ b/Assets/Scripts/MyPlayer.cs @@ -5,6 +5,7 @@ using UnityEngine.InputSystem; using DG.Tweening; using Sirenix.OdinInspector; + // _ // | | // _ __ | | __ _ _ _ ___ _ __ @@ -14,6 +15,10 @@ using Sirenix.OdinInspector; // | | __/ | // |_| |___/ +/// +/// 玩家类,控制玩家相关的东西 +/// + [RequireComponent(typeof(Rigidbody2D))] public class MyPlayer : MonoBehaviour { @@ -41,6 +46,7 @@ public class MyPlayer : MonoBehaviour [Header("镰刀发射点Transform")] [BoxGroup("预制体")] public GameObject sicklePrefab; + public enum AtkMethod{镰刀,锤子,反弹炸弹}; // _____ _ _ // | __ \ (_) | | @@ -235,6 +241,7 @@ public class MyPlayer : MonoBehaviour { if(other.TryGetComponent(out Sickle temp)) Destroy(temp.gameObject); + } - } + } }