This commit is contained in:
JA
2026-06-20 19:34:23 +08:00
parent e5031c0068
commit d442805c3f
4136 changed files with 514641 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4d0bb11ea6c458148bdb5b29921de6e8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,337 @@
using Manager;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BossAI : CombaSystem
{
//基本信息类
public BossInfo _info;
Rigidbody2D rb;
//玩家信息,待优化
PlayerControler player;
CharacterCombat characterCombat;
private Transform currentTarget;
//玩家与敌人的距离方向
private float dis;
private Vector2 dir;
[Header("追击与攻击距离")]
public float cheseDistance = 3f;
public float attackDistance = 0.8f;
[SerializeField, Header("技能搭配")] private List<CombatAblilityBase> abilitys = new List<CombatAblilityBase>();
private CombatAblilityBase currentAblity;
//判断偏移
private List<Vector2> ablityOff;
//攻击段数
private int attackCount;
//计时器
public GameObject timer;
public bool isBegin = false;
List<CombatAblilityBase> tempAb = new List<CombatAblilityBase>();//可用技能组
int ran;//技能组索引
CameraVR cameraVR;
public bool isYuancheng=false;
protected override void Awake()
{
base.Awake();
_animator = GetComponentInChildren<Animator>();
rb = GetComponentInParent<Rigidbody2D>();
currentTarget = GameObject.FindWithTag("Player").transform;
_info = GetComponentInParent<BossInfo>();
foreach (var ab in abilitys)
{
ab.Init(this,_animator);
}
}
private void Update()
{
if (!_animator.CheckAnimationTag("summon")&&isBegin)
{
if (!isDie) //死亡或咆哮状态的时候不会进行攻击
{
MoveBoss();
}
}
}
private void FixedUpdate()
{
if (currentAblity != null)
{
currentAblity.UpdateAblity(currentTarget);
}
}
private void MoveBoss()
{
if (_animator.CheckAnimationTag("Wake"))
return;
if (_animator.CheckAnimationTag("hit") || _animator.CheckAnimationTag("Attack")||_animator.CheckAnimationTag("Attack_out"))
{
return;
}
if (currentTarget == null)
return;
LockTarget(currentTarget);
dis = Vector2.Distance(currentTarget.position, transform.position);
if (dis < cheseDistance)
{
rb.velocity = Vector2.zero;
//近战
if (dis < attackDistance)
{
//_animator.Play("attack-charge");
currentAblity = GetAblity(AblityClass.MelleeAttack);
if (currentAblity != null)
{
//SoundManager.Instance.PlayEffect(_audio, currentAblity.GetAbliltyVFX());
_animator.Play(currentAblity.GetAbliltyName());
currentAblity.UseAblity(currentAblity);
}
return;
}
//远程
else
{
currentAblity = GetAblity(AblityClass.YuanChenAttack);
if (currentAblity != null)
{
//SoundManager.Instance.PlayEffect(_audio, currentAblity.GetAbliltyVFX());
_animator.Play(currentAblity.GetAbliltyName());
currentAblity.UseAblity(currentAblity);
}
return;
}
}
else
{
if (!_info.isCanMove)
return;
_animator.Play("run");
rb.velocity = dir * _info._moveSpeed;
}
}
private void LockTarget(Transform target)
{
if (!_info.isLockTarget)
return;
dir = (target.position - transform.position).normalized;
if(_info.isFix)
{
Fix(dir);
}
}
private void Fix(Vector2 dir)
{
if (dir.x < 0)
{
transform.root.localScale = new Vector3(1, 1, 1);
}
if (dir.x > 0)
{
transform.root.localScale = new Vector3(-1, 1, 1);
}
}
public void Yuancheng()
{
isYuancheng = true;
}
public void OnCloseYuancheng()
{
isYuancheng = false;
}
public void TeleportEvent()
{
if (currentTarget == null) return;
transform.root.transform.position = currentTarget.transform.position;
}
/// <summary>
/// 近战攻击
/// </summary>
public override void MelleeAttackAnimEvent()
{
if (currentAblity != null)
{
AttackAreaPos = transform.position;
ablityOff = currentAblity.GetAbliltyOffest();
AttackAreaPos.x += ablityOff[attackCount].x;
AttackAreaPos.y += ablityOff[attackCount].y;
attackCount++;
if (attackCount >= ablityOff.Count)
{
attackCount = 0;
}
if (_info.isCanMove)
{
AttackAreaPos.x = this.transform.parent.localScale.x < 0 ? Mathf.Abs(offsetX) : -Mathf.Abs(offsetX);
}
}
else
{
base.MelleeAttackAnimEvent();
}
Collider2D[] hitColliders = Physics2D.OverlapBoxAll(AttackAreaPos, attackSize, 0, layerMasks[0]);
if(currentAblity!=null&&currentAblity.GetAbliltyVFX()!=null)
{
SoundManager.Instance.PlayEffect(_audio, currentAblity.GetAbliltyVFX());
}
foreach (Collider2D hitInfo in hitColliders)
{
player = hitInfo.GetComponent<PlayerControler>();
if (player != null && player.GetIsDodge())
{
Debug.Log("玩家无敌");
_animator.speed = 0;
StartCoroutine(ScalTime(1f));
return;
}
characterCombat = hitInfo.GetComponentInChildren<CharacterCombat>();
//if(characterCombat._animator.CheckAnimationTag("Roll"))
//{
// //无敌闪避
// _animator.speed = 0;
// StartCoroutine(ScalTime(1f));
// return;
//}
characterCombat.TakeDamage(attack);
Debug.Log("玩家受伤");
}
}
IEnumerator ScalTime(float timer)
{
yield return new WaitForSeconds(timer);
_animator.speed = 1;
}
public override void TakeDamage(string aniName, float attack)
{
if (isDie || _animator.CheckAnimationTag("summon")||_animator.CheckAnimationTag("Wake"))//咆哮不会被攻击
return;
Debug.Log("被玩家攻击" + _info.attackedCount);
_info.attackedCount++;//耐力次数增加
if (_info.attackedCount > _info.maxAttackedCount)
{
_info.attackedCount = 0;//重新计数
_animator.Play("summon");
if(_summerClip!=null)
{
SoundManager.Instance.PlayEffect(_audio,_summerClip);
}
//吼叫
//摄像机震动
cameraVR=UnityExpandFunction.GetCamera();
if (cameraVR != null)
{
cameraVR.ShakeCamera(1f, 5);
}
//回血
currentHp += 200;
if (currentHp >= maxHp)
currentHp = maxHp;
OnHit?.Invoke(currentHp);
return;
}
//受伤
currentHp -= attack;//血量减少
OnHit?.Invoke(currentHp);//执行受伤事件血量UI减少
if (currentHp <= 0)
{
isDie = true;
return;
}
if(_animator.CheckAnimationTag("Attack"))
{
return;
}
_animator.Play(aniName);
}
private CombatAblilityBase GetAblity(AblityClass ablity)
{
tempAb.Clear();
foreach (var ab in abilitys)
{
if (ab.GetAbliltyIsDone() && ab.GetAbliltyClass() == ablity)
{
tempAb.Add(ab);
}
}
if(tempAb.Count==0)
{
return null;
}
ran = UnityEngine.Random.Range(0,tempAb.Count);
if (tempAb[ran] != null)
return tempAb[ran];
return null;
}
public void SetBegin(bool b)
{
isBegin = b;
//开始
_animator.Play("sleeping");
UIManager.Instance.Show<UIEnterScene>().InitInfo(_info.bossHead, _info.bossName);
}
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(transform.position, cheseDistance);
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, attackDistance);
}
}

View File

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

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossInfo : MonoBehaviour
{
[Header("名字与头像")]
public string bossName;
public Sprite bossHead;
[Header("失衡最大次数")]
public int maxAttackedCount;
[Header("被攻击次数")]
public int attackedCount=0;
//是否允许锁定目标
[Header("索敌")]
public bool isLockTarget;
[Header("移动")]
public bool isCanMove;
[Header("翻转")]
public bool isFix;
[Header("移动速度")]
public float _moveSpeed;
}

View File

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

View File

@@ -0,0 +1,64 @@
//using System;
//using System.Collections;
//using System.Collections.Generic;
//using UnityEngine;
//using UnityEngine.Events;
//普通怪物
//public class Enemy : CharacterManager
//{
// [Header("距离")]
// public float cheseDistance = 3f;
// public float attackDistance = 0.8f;
// public UnityEvent<Vector2> OnMoveInput;
// public Action OnAttack;
// private Transform player;
// //玩家与敌人的距离方向
// private float dis;
// private Vector2 dir;
// private void Awake()
// {
// player = GameObject.FindWithTag("Player").transform;
// }
// private void Update()
// {
// if (player == null)
// return;
// dis = Vector2.Distance(player.position,transform.position);
// if(dis<cheseDistance)
// {
// //追击
// if(dis<=attackDistance)
// {
// OnMoveInput?.Invoke(Vector2.zero);
// //攻击
// OnAttack?.Invoke();
// }
// else
// {
// dir = player.position - transform.position;
// OnMoveInput?.Invoke(dir.normalized);
// }
// }
// else
// {
// OnMoveInput?.Invoke(Vector2.zero);//放弃追击
// }
// }
// private void OnDrawGizmosSelected()
// {
// Gizmos.color = Color.yellow;
// Gizmos.DrawWireSphere(transform.position,cheseDistance);
// Gizmos.color = Color.red;
// Gizmos.DrawWireSphere(transform.position, attackDistance);
// }
//}

View File

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

View File

@@ -0,0 +1,142 @@
//using System.Collections;
//using System.Collections.Generic;
//using UnityEngine;
//using System;
//using Manager;
//普通怪物
//public class EnemyController : MonoBehaviour
//{
// public GameObject attackVFX;
// [Header("移动速度")] public float currentSpeed;
// [Header("攻击")]
// [SerializeField] private bool isAttack = true;
// [SerializeField] private float attackCollDuration = 1;
// private bool isDead=false;
// public Vector2 MoveInput
// {
// get;set;
// }
// private Enemy enemy;
// private Rigidbody2D rb;
// private SpriteRenderer sr;
// private Animator animator;
// private Collider2D colliderEnemy;
// [Header("攻击,间隔")]
// public float attackDamage = 20;
// public float attackDuration = 1.5f;
// public LayerMask playerLayer;
// private void Awake()
// {
// rb = transform.parent.GetComponent<Rigidbody2D>();
// colliderEnemy = transform.parent.GetComponent<Collider2D>();
// sr = GetComponent<SpriteRenderer>();
// animator = GetComponent<Animator>();
// enemy = transform.parent.GetComponent<Enemy>();
// }
// private void Start()
// {
// enemy.OnAttack += OnAttack;
// }
// private void FixedUpdate()
// {
// if(!isDead)
// {
// OnMove();
// }
// SetAnimation();
// }
// private void OnMove()
// {
// if (MoveInput.magnitude > 0.1f && currentSpeed > 0)
// {
// rb.velocity = MoveInput * currentSpeed;
// if(MoveInput.x<0)
// {
// sr.flipX = false;
// }
// if (MoveInput.x > 0)
// {
// sr.flipX = true;
// }
// }
// else
// {
// rb.velocity = Vector2.zero;
// }
// }
// void OnAttack()
// {
// if(isAttack)
// {
// isAttack = false;
// StartCoroutine(nameof(AttackCoroutine));
// }
// }
// IEnumerator AttackCoroutine()
// {
// animator.SetTrigger("Attack");
// yield return new WaitForSeconds(attackCollDuration);
// isAttack = true;
// }
// public void EnemyHurt()
// {
// animator.SetTrigger("Hurt");
// }
// public void EnemyDead()
// {
// rb.velocity = Vector2.zero;
// isDead = true;
// colliderEnemy.enabled = false;
// }
// void SetAnimation()
// {
// animator.SetBool("isWalk",MoveInput.magnitude>0);
// animator.SetBool("isDead", isDead);
// }
// public void DestoryEnemy()
// {
// Destroy(transform.parent.gameObject);
// }
// public void MelleeAttackAnimEvent()
// {
// Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, enemy.attackDistance, playerLayer);
// foreach (Collider2D hitInfo in hitColliders)
// {
// hitInfo.transform.root.GetComponentInChildren<CharacterCombat>().TakeDamage();
// }
// }
// public void YuanChengAttackAnimEvent(string name)
// {
// Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, enemy.attackDistance, playerLayer);
// foreach (Collider2D hitInfo in hitColliders)
// {
// GameObject go=Instantiate(attackVFX,transform.position,Quaternion.identity);
// go.AddComponent<VFXMove>();
// }
// }
// public void Protected(string name)
// {
// string monster = "Perfab/Monsters/" + name;
// UnityEngine.Object go =Resloader.Load<GameObject>(monster);
// if(go!=null)
// {
// GameObject m= (GameObject)Instantiate(go,transform.root);
// }
// }
//}

View File

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

View File

@@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LevelUp : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
UIManager.Instance.Show<UILevelUp>();
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 831a08ac5bb2de440acde27635619af9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMove : MonoBehaviour
{
private Transform player;
void Start()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
}
void Update()
{
//RaycastHit[] hits;
//hits = Physics.RaycastAll(ray, Mathf.Infinity, badMask);
//for (int i = 0; i < hits.Length; i++)
//{
// Debug.Log(hits[i].collider.gameObject.name);
//}
//Debug.Log(hits.Length);
if (player!=null)
{
transform.position = new Vector3(player.position.x, player.position.y - 11, player.position.z);
}
}
}

View File

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

View File

@@ -0,0 +1,63 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class CameraVR : MonoBehaviour
{
private CinemachineVirtualCamera _cinemachineVirtualCamera;
private CinemachineBasicMultiChannelPerlin _multiChannelPerlin;
//当前持续时间
private float _shakeTime;
//总时间
private float _shakeTimeTotal;
//强度
private float _shakeIntensity;
private void Awake()
{
_cinemachineVirtualCamera = GetComponent<CinemachineVirtualCamera>();
_multiChannelPerlin = _cinemachineVirtualCamera.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
}
// Update is called once per frame
void Update()
{
if (_shakeTime > 0)
{
_shakeTime -= Time.deltaTime;
_multiChannelPerlin.m_AmplitudeGain = Mathf.Lerp(0, _shakeIntensity, _shakeTime / _shakeTimeTotal);
}
}
/// <summary>
/// 抖动
/// </summary>
/// <param name="Time">抖动时间</param>
/// <param name="Intensity">强度</param>
public void ShakeCamera(float time, float intensity)
{
if (_cinemachineVirtualCamera != null)
{
_shakeTimeTotal = time;
_shakeIntensity = intensity;
_shakeTime = _shakeTimeTotal;
_multiChannelPerlin.m_AmplitudeGain = _shakeIntensity;
}
}
private void OnDrawGizmos()
{
Ray ray = new Ray(transform.position, transform.forward);
Gizmos.color = Color.blue;
Gizmos.DrawRay(ray);
}
}

View File

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

View File

@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Destructeable : MonoBehaviour
{
public GameObject destoryVFX;
public GameObject big;
public GameObject small;
private bool isDestory=false;
public float reTiem = 5;
public void OnDestoryObject()
{
if (isDestory)
return;
if (destoryVFX != null)
{
Instantiate(destoryVFX,transform.position,transform.rotation);
}
big.SetActive(false);
SmallActive(true);
isDestory = true;
StartCoroutine(nameof(DestoryTime));
}
IEnumerator DestoryTime()
{
yield return new WaitForSeconds(reTiem);
big.SetActive(true);
SmallActive(false);
}
private void SmallActive(bool active)
{
if (small != null)
{
small.SetActive(active);
isDestory = false;
}
}
}

View File

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

View File

@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Door : MonoBehaviour
{
public Animator _ani;
public BoxCollider2D bx;
public bool isOpen=false;
public GameObject boss;
private void Awake()
{
_ani = GetComponentInChildren<Animator>();
bx = GetComponent<BoxCollider2D>();
boss = GameObject.FindWithTag("Boss");
}
private void Update()
{
if(isOpen)
{
Debug.Log("¿ªÃÅ");
_ani.Play("activate");
StartCoroutine(nameof(Open));
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Player")&&!isOpen)
{
UIManager.Instance.Show<UIOpen>();
}
}
private IEnumerator Open()
{
yield return new WaitForSeconds(7f);
bx.isTrigger = true;
boss.GetComponentInChildren<BossAI>().SetBegin(true);
isOpen=false;
this.gameObject.SetActive(false);
}
}

View File

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

View File

@@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FacingCamera : MonoBehaviour
{
Transform[] childs;
private Transform cameraMain;
private void Awake()
{
cameraMain = GameObject.FindGameObjectWithTag("Camera").transform;
}
void Start()
{
childs = new Transform[transform.childCount];
for (int i = 0; i < transform.childCount; i++)
{
childs[i] = transform.GetChild(i);
}
}
void Update()
{
for (int i = 0; i < childs.Length; i++)
{
childs[i].rotation = cameraMain.rotation;
}
}
}

View File

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

View File

@@ -0,0 +1,48 @@
using Manager;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Teleport : MonoBehaviour
{
public BossAI m;
public bool isBattle;
private void Awake()
{
if(isBattle)
{
m = GameObject.FindWithTag("Boss").GetComponentInChildren<BossAI>();
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(isBattle)
{
if (m.GetIsDie() && collision.CompareTag("Player"))
{
Debug.Log("传送");
//保存玩家信息
CharacterCombat cm = collision.gameObject.GetComponentInChildren<CharacterCombat>();
PlayerInfo.Instance.KeepData(cm.maxHp, cm.currentHp, cm.attack);
UIManager.Instance.Show<UILoad>();
return;
}
}
else
{
if (collision.CompareTag("Player"))
{
Debug.Log("传送");
//保存玩家信息
CharacterCombat cm = collision.gameObject.GetComponentInChildren<CharacterCombat>();
PlayerInfo.Instance.KeepData(cm.maxHp,cm.currentHp,cm.attack);
UIManager.Instance.Show<UILoad>();
return;
}
}
}
}

View File

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

View File

@@ -0,0 +1,31 @@
using Spine;
using Spine.Unity;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tree : CombaSystem
{
private SkeletonAnimation skelet;
private Spine.AnimationState animationState;
protected override void Awake()
{
skelet = GetComponent<SkeletonAnimation>();
animationState = skelet.AnimationState;
//¶¯×÷Íê³ÉºóµÄ»Øµ÷
animationState.Complete += OnIdle;
}
private void OnIdle(TrackEntry trackEntry)
{
TrackEntry entry = skelet.AnimationState.SetAnimation(0, "animation", true);
}
public override void TakeDamage()
{
TrackEntry entry = skelet.AnimationState.SetAnimation(0, "hit", false);
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 12c2b15ec8c03cf48ae095dfbb940ab7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,155 @@
using Manager;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterCombat : CombaSystem
{
[Header("音效")]
public AudioSource audioSource;
public PlayerControler controler;
[Header("特效")]
public GameObject effect;
CameraVR cameraVR;
protected override void Awake()
{
maxHp = PlayerInfo.Instance.info.maxHp;
currentHp = PlayerInfo.Instance.info.currentHp;
attack = PlayerInfo.Instance.info.testAttack;
audioSource = transform.root.GetComponentInChildren<AudioSource>();
_animator = GetComponent<Animator>();
PlayerInfo.Instance.OnUpdateAttrbute += OnChangeAttrbute;
}
private void OnDisable()
{
PlayerInfo.Instance.OnUpdateAttrbute -= OnChangeAttrbute;
}
public override void MelleeAttackAnimEvent()
{
base.MelleeAttackAnimEvent();
Collider2D[] hitColliders = Physics2D.OverlapBoxAll(AttackAreaPos,attackSize,0,layerMasks[0]);
Collider2D[] destructiveColliders = Physics2D.OverlapBoxAll(AttackAreaPos, attackSize, 0,layerMasks[1]);
Collider2D[] treeColliders = Physics2D.OverlapBoxAll(AttackAreaPos, attackSize, 0, layerMasks[2]);
foreach (Collider2D hitInfo in hitColliders)
{
if(hitInfo.tag=="Enemy")
{//小怪
}
if (hitInfo.tag == "Boss")
{
hitInfo.GetComponentInChildren<BossAI>().TakeDamage("hurt-front",GetAttack());
if (_summerClip != null)
SoundManager.Instance.PlayEffect(_audio, _summerClip);
//加入卡肉,特效
if(effect!=null)
{
GameObject go = Instantiate(effect);
go.transform.position = hitInfo.transform.position + new Vector3(0,4,0);
//开始计时
string timerPath = "Perfab/Timer";
GameObject timer = Resloader.Load<GameObject>(timerPath);//寻找预制体
GameObject time = Instantiate(timer);
time.GetComponent<Timer>().CreateTime(0.2f, () =>
{
ManagersMode.Poll.UnSpwan("EffectPoll", effect.name, go);
}, false);
}
cameraVR = UnityExpandFunction.GetCamera();
if (cameraVR != null)
{
cameraVR.ShakeCamera(0.5f, 2);
}
}
}
foreach (Collider2D hitInfo in destructiveColliders)
{
}
foreach (Collider2D hitInfo in treeColliders)//数目
{
Debug.Log("攻击树木");
hitInfo.GetComponentInChildren<Tree>().TakeDamage();
}
}
//受伤
public override void TakeDamage(float atk)
{
currentHp -= atk;
OnHit?.Invoke(currentHp);//UI显示
if(currentHp<=0)
{
//死亡
return;
}
_animator.Play("hurt");
}
private void OnChangeAttrbute(LotteryType type, float value)
{
switch (type)
{
case LotteryType.Hp:
currentHp += value;
if(currentHp>=maxHp)
{
currentHp = maxHp;
}
OnHit?.Invoke(currentHp);
break;
case LotteryType.Mp:
maxHp += value;
OnHit?.Invoke(currentHp);
break;
case LotteryType.Attack:
attack += value;
OnHit?.Invoke(currentHp);
break;
case LotteryType.UpMaxHp:
PlayerInfo.Instance.info.maxHp += value;
maxHp += value;
OnHit?.Invoke(currentHp);
break;
case LotteryType.UpHp:
Date.Instance.ItemDate[1].value += (int)value;
OnHit?.Invoke(currentHp);
break;
case LotteryType.UpAttack:
PlayerInfo.Instance.info.attack += value;
attack += value;
OnHit?.Invoke(currentHp);
break;
default:break;
}
}
/// <summary>
/// 攻击力量
/// </summary>
/// <returns></returns>
public float GetAttack()
{
return attack + (PlayerInfo.Instance.info.Level * 10);
}
}

View File

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

View File

@@ -0,0 +1,210 @@
using Manager;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerControler : MonoBehaviour
{
[SerializeField] private InputActions inputActions;
[SerializeField] public Animator animator;
[SerializeField] private Rigidbody2D rb;
[SerializeField] private BoxCollider2D bc;
private CameraVR cameraVR;
[Header("正常速度")]
[SerializeField] private float normalSpeed;
Vector2 InputDir;//移动方向
public float dodgeCoolDown;//闪避Cd时间
public float dodgeSpeed;
private float dodge;
private bool isCanDodge;
private bool isWuDi;
public float wuDiTimer;
public CharacterCombat ch;
public CharacterHp info;
private void Awake()
{
inputActions = new InputActions();
cameraVR = GameObject.FindWithTag("Camera").GetComponentInChildren<CameraVR>();
}
private void Start()
{
inputActions.GamePlay.ComBa_01.started += this.Attack_01;
inputActions.GamePlay.ComBa_02.started += this.Attack_02;
inputActions.GamePlay.Dodge.started += this.Dodge;
inputActions.UI.Stop.started += this.OnStop;
inputActions.UI.Bag.started += this.OpenBag;
dodge = dodgeCoolDown;
isCanDodge = true;
ManagersMode.Poll.CreateGameObjectPoll("Timer", 10);
ManagersMode.Poll.CreateGameObjectPoll("BulletPoll", 3);
ManagersMode.Poll.CreateGameObjectPoll("EffectPoll", 2);
info.Init(ch);
}
private void Update()
{
if(ch.currentHp<=0)
{
UIManager.Instance.Show<UIGameOver>();
ch._animator.Play("die");
}
if(!animator.CheckAnimationTag("Roll"))
{
animator.speed = 1;
}
else
{
this.transform.Translate(InputDir*dodgeSpeed*0.01f);//闪避移动
}
CanDodge();
UseItem();
}
private void OnEnable()
{
inputActions.Enable();
}
private void OnDisable()
{
inputActions.Disable();
}
private void FixedUpdate()
{
if(!animator.CheckAnimationTag("Die"))
{
this.MoveController();
}
else
{
this.rb.velocity =Vector2.zero;
}
}
#region
private void MoveController()
{
InputDir = inputActions.GamePlay.Move.ReadValue<Vector2>().normalized;
animator.SetFloat("Horizontal", InputDir.x);
animator.SetFloat("Vertical", InputDir.y);
animator.SetFloat("Speed", InputDir.sqrMagnitude);
this.rb.velocity = InputDir * normalSpeed;
if (InputDir.x < 0)//向左
{
transform.localScale = new Vector3(1, 1, 1);
}
if (InputDir.x > 0)//向左
{
transform.localScale = new Vector3(-1, 1, 1);
}
}
private void OnStop(InputAction.CallbackContext obj)
{
UIManager.Instance.Show<UIGameOver>();
}
#endregion
/// <summary>
/// 角色攻击
/// </summary>
private void Attack_01(InputAction.CallbackContext obj)
{
animator.SetTrigger("Attack_01");
}
private void Attack_02(InputAction.CallbackContext obj)
{
animator.SetTrigger("Attack_02");
}
private bool CanDodge()
{
if(isCanDodge)
{
return true;
}
dodgeCoolDown -= Time.deltaTime;
if(dodgeCoolDown<=0)
{
isCanDodge = true;
dodgeCoolDown = dodge;
return true;
}
return false;
}
/// <summary>
/// 角色闪避
/// </summary>
private void Dodge(InputAction.CallbackContext obj)
{
//||animator.CheckAnimationTag("Hit")
if (!CanDodge())
{
return;
}
StartCoroutine(nameof(SetWuDi));//无敌状态
isCanDodge = false;
animator.speed = 1f;
if (InputDir.x!=0)
{
animator.Play("roll");
}
if (InputDir.y > 0)
{
animator.Play("roll-up");
}
if (InputDir.y < 0)
{
animator.Play("roll-down");
}
}
IEnumerator SetWuDi()
{
isWuDi = true;
yield return new WaitForSeconds(wuDiTimer);
isWuDi = false;
}
public bool GetIsDodge()
{
return isWuDi;
}
private void OpenBag(InputAction.CallbackContext obj)
{
UIManager.Instance.Show<UIBagInfo>();
}
public void UseItem()
{
if(Input.GetKeyDown(KeyCode.Alpha1))
{
PlayerInfo.Instance.BagMgr.UserItem(1, 1);//回血道具
}
}
}

View File

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

View File

@@ -0,0 +1,154 @@
using Managers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
public class PlayerInfo : Singleton<PlayerInfo>
{
public CharInfo info;
public Action OnUpdateBagInfo;
public Action OnUpdateMainUI;
public Action OnUpdateLevel;
public Action<LotteryType, float> OnUpdateAttrbute;
public Managers.BagManager BagMgr;
public void Init(CharInfo date)
{
info = date;
info.playerName = date.playerName;
info.Level = date.Level;
info.exp = date.exp;
info.maxHp = date.maxHp;
info.attack = date.attack;
info.testAttack = date.testAttack;
info.currentHp = date.currentHp;
info.currentMap = date.currentMap;
info.BagInfo = new Dictionary<int, int>();
info.UpInfo = new Dictionary<int, bool>();
for (int i = 0; i < date.BagKey.Count; i++)
{
info.BagInfo.Add(date.BagKey[i], date.BagValue[i]);
}
for (int i = 0; i < date.UpKey.Count; i++)
{
info.UpInfo.Add(date.UpKey[i], date.UpValue[i]);
}
//初始化管理器
BagMgr = new Managers.BagManager(this);
Debug.Log("数据读取完毕");
}
public void Resrt()
{
info.currentHp = info.maxHp; ;
info.testAttack = info.attack;
if(!info.BagInfo.ContainsKey(1))
{
info.BagInfo.Add(1,4);
}
else
{
info.BagInfo[1] = 4;
}
WriteBagInfo();
}
public void KeepData(float max, float current, float attack)
{
info.maxHp = max;
info.currentHp = current;
info.testAttack = attack;
}
public Sprite GetSprite(string path)
{
return Resloader.Load<Sprite>(path);
}
#region
public void AddHp(int num)
{
OnUpdateAttrbute?.Invoke(LotteryType.Hp, num);
}
public void AddMp(int num)
{
OnUpdateAttrbute?.Invoke(LotteryType.Mp, num);
}
public void AddAttack(int num)
{
OnUpdateAttrbute?.Invoke(LotteryType.Attack, num);
}
public void AddUpHp(int num)
{
OnUpdateAttrbute?.Invoke(LotteryType.UpHp, num);
}
public void AddUpMaxHp(int num)
{
OnUpdateAttrbute?.Invoke(LotteryType.UpMaxHp, num);
}
public void AddUpAttack(int num)
{
OnUpdateAttrbute?.Invoke(LotteryType.UpAttack, num);
}
#endregion
#region
public void LevelUp()
{
int need = NeedExp();
if (need < info.exp)
{
info.exp -= need;
info.Level++;
LevelUp();
SaveSystem.SaveDate(info.DatePath, info);
}
}
public int NeedExp()
{
int needExp;
return needExp = info.Level * (1000);
}
public void ItemLevel(LevelUpDefine item)
{
switch (item.type)
{
case LotteryType.UpMaxHp:
AddUpMaxHp(item.value);
break;
case LotteryType.UpAttack:
AddUpAttack(item.value);
break;
case LotteryType.UpHp:
AddUpHp(item.value);
break;
}
}
#endregion
//重写数据
public void WriteBagInfo()
{
info.BagKey.Clear();
info.BagValue.Clear();
foreach (var data in info.BagInfo)
{
info.BagKey.Add(data.Key);
info.BagValue.Add(data.Value);
}
}
}

View File

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