UnityCommon/Role/Role.cs

177 lines
5.0 KiB
C#
Raw Normal View History

2024-12-04 05:50:39 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using Debug = UnityEngine.Debug;
/// <summary>
/// <20><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>,<2C><><EFBFBD>Ҵ<EFBFBD><D2B4><EFBFBD><EFBFBD>¼<EFBFBD>
/// </summary>
[ExecuteInEditMode]
public class Role : Fun
{
[Header("Ѫ<><D1AA>")] public float hp = 100f;//Ѫ<><D1AA>
[Header("<22><><EFBFBD><EFBFBD>")] public float gold = 10f;
public float Hp
{
get => hp;
set
{
hp = value;
if (hp <= 0)
{
die();
//if (Progress_Display.Instance == null) return;
//Progress_Display.Instance.huadongClick(gold);
}
}
}
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public int physicalArmor = 10;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
[Header("ħ<><C4A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public int magicArmor = 5;//ħ<><C4A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public List<BUff> buffList = new List<BUff>();
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public SimplePathfindingDoTween Navigation;
[System.Serializable ]
public class AnimationList//<2F><><EFBFBD><EFBFBD>list
{
//[Header("<22><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>ѭ<EFBFBD><D1AD>")] public bool isloop = false;
[Header("<22><><EFBFBD><EFBFBD>ͼƬ")] public List<Sprite> value; // <20>ֵ<EFBFBD><D6B5><EFBFBD>ֵ
[Header("<22><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>)")] public int CharacterAnimationFrameInterval = 50;
}
[Header("<22><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>")] public List<AnimationList> AnimationTree = new List<AnimationList>();
[Header("<22><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public int animationHighlight = 0;
[Header("<22><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>")] public SpriteRenderer spriteRenderer;
[Header("<22><>ɫImageλ<65><CEBB>")] public Image image;
public delegate void AnimationItem(int AnimationItem);
public event AnimationItem OnAnimationStart;
public event AnimationItem OnAnimationIng;
public event AnimationItem OnAnimationEnd;
[Header("<22><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public bool isAnimationPlay = false;//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
async void Start()
{
if (Application.isPlaying)
{
UpdateBuff();
}
updateAnimation();
}
/// <summary>
/// <20><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public async void updateAnimation()
{
while (true)
{
//if (AnimationTree.Count == 0)
//{
// isAnimationPlay = false;
// return;
//}
//isAnimationPlay = true;
if (animationHighlight > AnimationTree.Count)
{
animationHighlight = AnimationTree.Count - 1;
Debug.Log("=---");
}
else if (animationHighlight < 0) {
animationHighlight = 0;
}
EditorUtility.SetDirty(this);
Debug.Log(animationHighlight > AnimationTree.Count);
Debug.Log(animationHighlight);
List<Sprite> LightSprite = AnimationTree[animationHighlight].value;
if (LightSprite == null )
{
//isAnimationPlay = false;
return;
};
OnAnimationStart?.Invoke(animationHighlight);
foreach (Sprite sprite in LightSprite)
{
if (image != null)
{
image.sprite = sprite;
}
else if (spriteRenderer != null)
{
spriteRenderer.sprite = sprite;
}
if (animationHighlight > 0 && animationHighlight < AnimationTree.Count)
{
OnAnimationIng?.Invoke(animationHighlight);
await Task.Delay(AnimationTree[animationHighlight].CharacterAnimationFrameInterval);
}
}
OnAnimationEnd?.Invoke(animationHighlight);
}
}
/// <summary>
/// <20><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>
/// </summary>
public virtual void die()
{
if (Application.isPlaying)
{
Destroy(gameObject);
}
}
/// <summary>
/// <20><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>buff
/// </summary>
async void UpdateBuff()//<2F><>λbuff<66><66><EFBFBD><EFBFBD>
{
while (true)
{
List<BUff> deleteArr = new List<BUff>();
foreach (BUff buffItem in buffList)
{
if (buffItem.executionInterval <= 0)
{
buffItem.executionInterval = buffItem.executionInterval_max;
buffItem.Funaction.Invoke(buffItem.value);
}
buffItem.executionInterval -= 0.1f;
buffItem.timeLeft -= 0.1f;
if (buffItem.timeLeft <= 0)
{
deleteArr.Add(buffItem);
}
}
foreach (BUff item in deleteArr)
{
buffList.Remove(item);
}
await Task.Delay(100);//buff<66><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сʱ<D0A1><CAB1>0.1<EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> MonoBehaviour<75><72><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>̶<EFBFBD>֡<EFBFBD><D6A1><EFBFBD>ʵ<EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô˺<C3B4><CBBA><EFBFBD>
private void FixedUpdate()
{
//if (!isAnimationPlay)
//{
// updateAnimation();
//}
}
}