SAIMA/Assets//脚本/Person.cs
Roman cab00851df 短学期Log
任务:替换和实装美术素材
1.在教程场景布置图标和文字提示内容
DONE
2.制作GamePlay中背景元素的动画并实装
DONE
3.替换拆迁障碍物美术素材
DONE

任务:实装音乐和音效
1.为两个场景添加音乐,并且在GamePlay场景不重开音乐。
DONE
2.实装人摔地音效
DONE
3.实装人跑动音效
DONE
4.实装人马分离音效
DONE
5.实装创烂障碍物音效
DOING
6.实装圣火点燃音效
7.实装马磕磕碰碰音效
8.实装马似音效
9.实装马着地音效
10.实装马起跳音效

任务:实装特效
……

任务:完善没写的零散逻辑
1.在教程场景,若人马分离障碍处没接到人,过一个转场然后复位人和马
**:仍然存在问题,当如此,人的动画失效。这个问题现在不好修,等待人的死亡动画实装后再修
WAIT
2.在教程场景,点燃圣火仅有进入触发器后加载转场然后转移场景的功能,没有点燃圣火的过程,现补充其逻辑
DONE
3.开发GamePlay距离记录和重开系统
……

修复Bug
1.在教程场景,可破坏障碍物的碎片的层级不对,创烂瞬间会有层级突变的问题。在GamePlay层级,也出现了这个问题。
2.现在的高障碍实在太高了,基本有80%以上的概率导致马翻,应该调低障碍物、或者调大马的跳跃力度。
2022-08-27 02:51:21 +08:00

227 lines
7.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using Sirenix.OdinInspector;
using UnityEngine.SceneManagement;
/// <summary>
/// 马背上人的控制类
/// </summary>
public class Person : MonoBehaviour
{
public enum PersonState{
Normal,//骑在马背
Shoot,//从发射到着地平台
Walk,//在平台行走
FallingOff,//下落,从脱离平台到判定有结果前
Recover,//判定成功到恢复到Normal的过程态
Dead//判定失败后均为此态
}
/// <summary>
/// 人此时的状态
/// </summary>
[Header("信息显示")]
[Title("人此时的状态")]
[EnumPaging()]
public PersonState state;
/// <summary>
/// 人在人马分离障碍的平台上时的行走速度
/// </summary>
[FoldoutGroup("主要参数",true)]
[Title("人在人马分离障碍的平台上时的行走速率")]
public float walkSpeed = 1f;
/// <summary>
/// 人在人马分离障碍前,被抛出的速度
/// </summary>
[FoldoutGroup("附加参数",false)]
[Title("人在人马分离障碍前,被抛出的速度")]
public Vector2 throwingSpeed;
[FoldoutGroup("附加参数",false)]
[Title("人在离开平台时起跳的速度")]
public Vector2 jumpSpeed;
[FoldoutGroup("附加参数")][Title("人死后的飞出速度")]
public Vector2 deadFlyVeloctiy;
[FoldoutGroup("附加参数")][Title("人死后的飞出的旋转的角速度")]
public float deadFlyRotateSpeed;
[FoldoutGroup("音效剪辑")][Title("人死音效剪辑")]
public AudioClip deadSE;
[FoldoutGroup("音效剪辑")][Title("人走路音效剪辑")]
public AudioClip walkSE;
[FoldoutGroup("音效剪辑")][Title("人起跳音效剪辑")]
public AudioClip shootSE;
/// <summary>
/// 默认状态下的追踪点
/// </summary>
private Transform defaultTrackingPoint;
private Rigidbody2D m_rigidbody2D;
private Animator m_animator;
private AudioSource m_audioSource;
void Start(){
//Init
//Init
//Find
defaultTrackingPoint = GameObject.Find("人的默认位置(不可改名)").transform;
m_rigidbody2D = GetComponent<Rigidbody2D>();
m_animator = GetComponentInChildren<Animator>();
m_audioSource = GetComponent<AudioSource>();
//Find
}
void Update(){
//默认状态下的Update
if(state == PersonState.Normal){
//同步人和马的位置和旋转
transform.position = defaultTrackingPoint.position;
transform.rotation = defaultTrackingPoint.rotation;
}
//行走状态下的Update
else if(state == PersonState.Walk){
//让人向右移动
transform.position += (Vector3.right * walkSpeed * Time.deltaTime);
}
}
/// <summary>
/// 人发射的瞬间触发一次,由人马分离障碍物触发
/// </summary>
public void Shoot(){
Debug.Log("人发射");
state = PersonState.Shoot;
//给与刚体一个右上角的速度,使其刚好能抛到平台上
m_rigidbody2D.velocity = throwingSpeed;
//1秒内修正人的旋转
transform.DORotate(new Vector3(0,0,0),1).OnComplete(
//旋转修正结束后锁定刚体Z轴旋转
() => m_rigidbody2D.constraints = RigidbodyConstraints2D.FreezeRotation
);
//动画
m_animator.SetTrigger("跳上");
//
m_audioSource.clip = shootSE;
m_audioSource.Play();
m_audioSource.loop = false;
}
/// <summary>
/// 人接触到平台的瞬间触发,由人马分离障碍物触发
/// </summary>
public void Walk(){
Debug.Log("人行走");
state = PersonState.Walk;
//动画
m_animator.SetTrigger("跑步");
//
m_audioSource.clip = walkSE;
m_audioSource.Play();
m_audioSource.loop = true;
}
/// <summary>
/// 人离开平台的瞬间触发,由人马分离障碍物触发
/// </summary>
public void FallingOff(){
Debug.Log("人降落");
state = PersonState.FallingOff;
//给刚体一个右上的速度,模拟一下起跳
m_rigidbody2D.velocity = jumpSpeed;
//动画
m_animator.SetTrigger("跳下");
//
m_audioSource.clip = shootSE;
m_audioSource.Play();
m_audioSource.loop = false;
}
public void Recover(){
Debug.Log("人成功降落到马背");
state = PersonState.Recover;
//1秒内修正人的位置和旋转与defaultTrackingPoint同步
//后发现,由于追踪的动画终点是定好了的,但是马在这一秒还是会运动,会导致问题,所以这里把时间改短
transform.DOMove(defaultTrackingPoint.position,0.2f);
transform.DORotate(defaultTrackingPoint.rotation.eulerAngles,0.2f).OnComplete(
() => state = PersonState.Normal
);
//动画
m_animator.SetTrigger("恢复");
}
/// <summary>
/// 由GameController触发用于控制人死后的动作
/// </summary>
public void Death(GameController.Death deathInfo){
state = PersonState.Dead;
//让人和马一样,旋转着飞出去,同时关闭自身的碰撞体
GetComponent<CapsuleCollider2D>().enabled = false;
Rigidbody2D rigidbody2D = GetComponent<Rigidbody2D>();
rigidbody2D.velocity = deadFlyVeloctiy;
rigidbody2D.angularVelocity = deadFlyRotateSpeed;
}
private void OnCollisionEnter2D(Collision2D other) {
//如果创到地面,且是在降落状态,则判定为游戏失败
if(other.gameObject.tag == "Ground" && state == PersonState.FallingOff){
//如果此时是GamePlay场景
if(SceneManager.GetActiveScene().name == "0813中期提交"){
GameController.Death death = new GameController.Death();
death.deadReason = GameController.Death.DeadReason.PersonFall;
GameController.Instance.GameOver(death);
Debug.Log("人掉落到地面");
}
//如果此时是教程场景试做
else if(SceneManager.GetActiveScene().name == "教程场景试做"){
StartCoroutine(DeadInStartCoroutine());
}
m_audioSource.clip = deadSE;
m_audioSource.Play();
}
}
private IEnumerator DeadInStartCoroutine(){
//切断输入
Player.Instance.ToNullMap();
//稍作等待
yield return new WaitForSeconds(0.5f);
//呼出黑幕
BlackController.Instance.Trans();
//等待屏幕完全变黑
yield return new WaitUntil(() => {return BlackController.Instance.AllBlack;});
//复位人和马
Transform horse = FindObjectOfType<Horse>().transform;
horse.position = new Vector3(31.2f,-11.4f,0);
horse.eulerAngles = Vector3.zero;
state = PersonState.Normal;
//重启自己的状态机
m_animator.enabled = false;
yield return new WaitForEndOfFrame();
m_animator.enabled = true;
//恢复障碍触发
FindObjectOfType<HumanHorseBreakObstacle>().hasShoot = false;
//等待上面几步完成
yield return new WaitForSeconds(0.5f);
//恢复输入
Player.Instance.ToMap();
}
}