任务:编写玩法框架

1.视野移动和死亡重开系统
(1.相机以一个可指定的、热更新的速度始终往右移动
(2.相机带有一个子物体,子物体带有触发器,触发器位于镜头最左端
(3.给马头添加碰撞体,用于判断镜头卡死死亡
(*.创建类:GameController,作为各种中介者使用
(4.当相机子物体的触发器检测到马头,说明马被卡死,给中介者发送信息触发死亡的一系列事件
((1.马死后,修改马状态至死亡
((2.相机不再移动
((3.关闭马的碰撞体,给一个右上的速度和旋转,马模型掉出地图
(5.设置按键以调试重开,目前是按R

DONE
This commit is contained in:
Roman 2022-07-28 15:58:55 +08:00
parent 7bbfa625a0
commit e1fa077241
8 changed files with 3083 additions and 347 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,73 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 相机管理员,主要控制游戏核心玩法中,相机向右移动和卡死死法的判定
/// </summary>
public class CameraManager : MonoBehaviour
{
/// <summary>
/// 相机移动的速度
/// </summary>
[Header("相机移动的速度")]
public float speed = 1f;
private Transform killWall;
void Start()
{
InitSth();
FindSth();
CreatSth();
}
void Update() {
//向右移动镜头
Move();
}
public void Death(GameController.Death deathInfo)
{
//相机不再运动
speed = 0;
}
void CreatSth()
{
killWall.gameObject.AddComponent<KillWall>();
}
void FindSth()
{
killWall = transform.Find("KillWall");
//killWall = GameObject.Find("KillWall").transform;
if(killWall == null) Debug.LogError("没找到KillWall,请检查相机是否有叫此名字的子物体");
}
void InitSth(){}
/// <summary>
/// 每帧调用,向右移动
/// </summary>
void Move(){
transform.position += (Vector3.right * speed * Time.deltaTime);
}
class KillWall : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D other) {
if(other.tag == "HorseHead")
{
GameController.Death death;
death.deadReason = GameController.Death.DeadReason.Camera;
GameController.Instance.GameOver(death);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 27aac20fffb2f4046bf09430bb01f2a7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameController : UnitySingleton<GameController>
{
public struct Death{
public enum DeadReason { Camera , UpDown }
public DeadReason deadReason;
}
private Horse horse;
private CameraManager cameraManager;
void Start()
{
FindSth();
}
void FindSth()
{
horse = FindObjectOfType<Horse>();
cameraManager = FindObjectOfType<CameraManager>();
}
public void GameOver(Death deathInfo)
{
//触发马的死亡功能
horse.Death(deathInfo);
//告诉相机马死了
cameraManager.Death(deathInfo);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c17660bc4daa2e34b8ba3dd2c7f224cd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -80,7 +80,7 @@ public class Horse : MonoBehaviour
/// <summary>
/// 马状态Stand代表无输入Move为有输入着地行走Jump为跳跃当两对足均并拢时进入
/// </summary>
public enum HorseState { Stand, Move, Jump}
public enum HorseState { Stand, Move, Jump, Dead}
/// <summary>
/// 单次跳跃过程中的状态量,Ready表示还没开始累计最终力Charge表示已经开始蓄力jump表示已经触发跳跃
@ -99,6 +99,9 @@ public class Horse : MonoBehaviour
[BoxGroup("马的基本运动信息")][Header("马跳跃力度")]
public float jumpForce;
[BoxGroup("马的其他信息")][Header("马被相机挤死后飞出有多大的力")]
public float deadFlySpeed;
@ -236,6 +239,11 @@ public class Horse : MonoBehaviour
/// </summary>
private Vector2 jumpChargeVelocity;
/// <summary>
/// 死亡后的旋转中心
/// </summary>
private Transform rotateCenter;
void Start()
{
@ -251,17 +259,40 @@ public class Horse : MonoBehaviour
{
//更新一些数据
UpdateDataEarly();
//计算马脚目标位置
CaculateTargetPosition();
//让马脚朝着目标移动
MoveFoot();
//让马整体运动
MoveHorse();
//跳跃检测和物理实现
if(horseState == HorseState.Jump) CheckJump();
if(horseState != HorseState.Dead)
{
//计算马脚目标位置
CaculateTargetPosition();
//让马脚朝着目标移动
MoveFoot();
//让马整体运动
MoveHorse();
//跳跃检测和物理实现
if(horseState == HorseState.Jump) CheckJump();
}
//更新一些数据
UpdateDataLate();
}
public void Death(GameController.Death deathInfo)
{
//修改状态至死亡
horseState = HorseState.Dead;
//关闭马蹄的碰撞体,并给一个右上角的速度和旋转,让马的模型掉出地图
foreach(foot foot in foots){
//foot.footBoxCollider2D.enabled = false;
//马蹄刚体也需要给速度,否则会黏在地上飞不起来
foot.footRigidbody2D.velocity = Vector2.one * deadFlySpeed * 1.5f;
}
//马身体的碰撞体也要关
List<BoxCollider2D> temp = new List<BoxCollider2D>();
GetComponentsInChildren<BoxCollider2D>(temp);
foreach(BoxCollider2D box in temp)
box.enabled = false;
horseRig.velocity = Vector2.one * deadFlySpeed;
horseRig.AddTorque(deadFlySpeed * 2f);
}
private void Jump()
{
@ -317,10 +348,13 @@ public class Horse : MonoBehaviour
private void UpdateDataEarly()
{
//判断是否两腿均并拢若是进入跳跃状态否则设置为Stand状态
if (isFrontFootMerged && isBackFootMerged) horseState = HorseState.Jump;
else horseState = HorseState.Stand;
if(horseState != HorseState.Dead)
{
if (isFrontFootMerged && isBackFootMerged) horseState = HorseState.Jump;
else horseState = HorseState.Stand;
}
Debug.Log("jumpState = " + jumpState);
//Debug.Log("jumpState = " + jumpState);
}
@ -457,6 +491,9 @@ public class Horse : MonoBehaviour
//找到马的刚体
horseRig = GetComponent<Rigidbody2D>();
//
rotateCenter = transform.Find("马死后的旋转中心");
}

View File

@ -5,6 +5,7 @@ TagManager:
serializedVersion: 2
tags:
- Ground
- HorseHead
layers:
- Default
- TransparentFX

View File

@ -121,7 +121,7 @@ MonoBehaviour:
m_MinSize: {x: 400, y: 200}
m_MaxSize: {x: 32384, y: 16192}
vertical: 0
controlID: 454
controlID: 38
--- !u!114 &6
MonoBehaviour:
m_ObjectHideFlags: 52
@ -146,7 +146,7 @@ MonoBehaviour:
m_MinSize: {x: 100, y: 200}
m_MaxSize: {x: 8096, y: 16192}
vertical: 1
controlID: 455
controlID: 68
--- !u!114 &7
MonoBehaviour:
m_ObjectHideFlags: 52
@ -165,7 +165,7 @@ MonoBehaviour:
x: 0
y: 0
width: 635.2
height: 515.2
height: 369.6
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 12}
@ -189,11 +189,11 @@ MonoBehaviour:
m_Position:
serializedVersion: 2
x: 0
y: 515.2
y: 369.6
width: 635.2
height: 207.59998
m_MinSize: {x: 201, y: 221}
m_MaxSize: {x: 4001, y: 4021}
height: 353.19998
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 13}
m_Panes:
- {fileID: 13}
@ -300,7 +300,7 @@ MonoBehaviour:
x: 0
y: 73.6
width: 634.2
height: 494.2
height: 348.6
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
@ -524,9 +524,9 @@ MonoBehaviour:
m_PlayAudio: 0
m_AudioPlay: 0
m_Position:
m_Target: {x: 22.567099, y: 7.2557883, z: -0.38658428}
m_Target: {x: -7.975728, y: 2.9624567, z: -0.17913768}
speed: 2
m_Value: {x: 22.567099, y: 7.2557883, z: -0.38658428}
m_Value: {x: -7.975728, y: 2.9624567, z: -0.17913768}
m_RenderMode: 0
m_CameraMode:
drawMode: 0
@ -577,9 +577,9 @@ MonoBehaviour:
speed: 2
m_Value: {x: 0, y: 0, z: 0, w: 1}
m_Size:
m_Target: 34.807396
m_Target: 8.098453
speed: 2
m_Value: 34.807396
m_Value: 8.098453
m_Ortho:
m_Target: 1
speed: 2
@ -625,9 +625,9 @@ MonoBehaviour:
m_Pos:
serializedVersion: 2
x: 0
y: 588.8
y: 443.2
width: 634.2
height: 186.59998
height: 332.19998
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
@ -638,7 +638,7 @@ MonoBehaviour:
m_ShowGizmos: 0
m_TargetDisplay: 0
m_ClearColor: {r: 0, g: 0, b: 0, a: 0}
m_TargetSize: {x: 368, y: 206.99997}
m_TargetSize: {x: 692, y: 388.99997}
m_TextureFilterMode: 0
m_TextureHideFlags: 61
m_RenderIMGUI: 1
@ -653,10 +653,10 @@ MonoBehaviour:
m_VRangeLocked: 0
hZoomLockedByDefault: 0
vZoomLockedByDefault: 0
m_HBaseRangeMin: -147.2
m_HBaseRangeMax: 147.2
m_VBaseRangeMin: -82.79999
m_VBaseRangeMax: 82.79999
m_HBaseRangeMin: -276.80002
m_HBaseRangeMax: 276.80002
m_VBaseRangeMin: -155.59999
m_VBaseRangeMax: 155.59999
m_HAllowExceedBaseRangeMin: 1
m_HAllowExceedBaseRangeMax: 1
m_VAllowExceedBaseRangeMin: 1
@ -665,7 +665,7 @@ MonoBehaviour:
m_HSlider: 0
m_VSlider: 0
m_IgnoreScrollWheelUntilClicked: 0
m_EnableMouseInput: 0
m_EnableMouseInput: 1
m_EnableSliderZoomHorizontal: 0
m_EnableSliderZoomVertical: 0
m_UniformScale: 1
@ -675,9 +675,9 @@ MonoBehaviour:
x: 0
y: 21
width: 634.2
height: 165.59998
height: 311.19998
m_Scale: {x: 1, y: 1}
m_Translation: {x: 317.1, y: 82.79999}
m_Translation: {x: 317.1, y: 155.59999}
m_MarginLeft: 0
m_MarginRight: 0
m_MarginTop: 0
@ -685,12 +685,12 @@ MonoBehaviour:
m_LastShownAreaInsideMargins:
serializedVersion: 2
x: -317.1
y: -82.79999
y: -155.59999
width: 634.2
height: 165.59998
height: 311.19998
m_MinimalGUI: 1
m_defaultScale: 1
m_LastWindowPixelSize: {x: 792.75, y: 233.24997}
m_LastWindowPixelSize: {x: 792.75, y: 415.24997}
m_ClearInEditMode: 1
m_NoCameraWarning: 1
m_LowResolutionForAspectRatios: 00000000000000000000
@ -727,9 +727,9 @@ MonoBehaviour:
m_SceneHierarchy:
m_TreeViewState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 0efbffff
m_SelectedIDs: 5c770000
m_LastClickedID: 30556
m_ExpandedIDs: 669bffffceb1ffffe6bdffff72d7ffffe4e0ffff34eaffff5eeaffff88eaffffe0eafffffaeeffff0efbffff4c760000a0760000c49d0000eca40000d2aa000000ac00002ead000090d10000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@ -807,9 +807,9 @@ MonoBehaviour:
m_IsLocked: 0
m_FolderTreeState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: c4770000
m_LastClickedID: 30660
m_ExpandedIDs: 00000000987700009a7700009c7700009e770000
m_SelectedIDs: de770000
m_LastClickedID: 30686
m_ExpandedIDs: 00000000aa770000ac770000ae770000b0770000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@ -837,7 +837,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 00000000987700009a7700009c7700009e770000
m_ExpandedIDs: 00000000aa770000ac770000ae770000b0770000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@ -928,7 +928,7 @@ MonoBehaviour:
m_ControlHash: -371814159
m_PrefName: Preview_InspectorPreview
m_LastInspectedObjectInstanceID: -1
m_LastVerticalScrollValue: 0
m_LastVerticalScrollValue: 402.40002
m_GlobalObjectId:
m_InspectorMode: 0
m_LockTracker: