2024-12-04 05:50:39 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
2024-12-05 16:25:46 +08:00
|
|
|
|
using System.Drawing;
|
2024-12-04 05:50:39 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
2024-12-05 16:25:46 +08:00
|
|
|
|
using UnityEngine.UIElements;
|
2024-12-04 05:50:39 +08:00
|
|
|
|
using Debug = UnityEngine.Debug;
|
2024-12-05 16:25:46 +08:00
|
|
|
|
using Image = UnityEngine.UI.Image;
|
|
|
|
|
|
|
|
|
|
public enum Camp
|
|
|
|
|
{/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
Player,
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
Enemy,
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
Neutral
|
|
|
|
|
}
|
2024-12-04 05:50:39 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>,<2C><><EFBFBD>Ҵ<EFBFBD><D2B4><EFBFBD><EFBFBD>¼<EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ExecuteInEditMode]
|
|
|
|
|
public class Role : Fun
|
|
|
|
|
{
|
2024-12-11 16:51:55 +08:00
|
|
|
|
[Header("Id")] public int id;
|
2024-12-05 16:25:46 +08:00
|
|
|
|
[Header("<22><>Ӫ")] public Camp camp ;
|
2024-12-04 05:50:39 +08:00
|
|
|
|
[Header("Ѫ<><D1AA>")] public float hp = 100f;//Ѫ<><D1AA>
|
|
|
|
|
public float Hp
|
|
|
|
|
{
|
|
|
|
|
get => hp;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
hp = value;
|
|
|
|
|
if (hp <= 0)
|
|
|
|
|
{
|
|
|
|
|
die();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-05 16:25:46 +08:00
|
|
|
|
[Header("<22><><EFBFBD><EFBFBD>")] public float gold = 10f;
|
|
|
|
|
public float Gold
|
|
|
|
|
{
|
|
|
|
|
[DebuggerStepThrough]
|
|
|
|
|
get => gold;
|
|
|
|
|
[DebuggerStepThrough]
|
|
|
|
|
set => gold = value;
|
|
|
|
|
}
|
|
|
|
|
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] private float attack = 10f;
|
|
|
|
|
public float Attack
|
|
|
|
|
{
|
|
|
|
|
get => attack;
|
|
|
|
|
set => attack = value;
|
|
|
|
|
}
|
|
|
|
|
[Header("<22>ȼ<EFBFBD>")] private int level = 1;
|
|
|
|
|
public int Level
|
|
|
|
|
{
|
|
|
|
|
[DebuggerStepThrough] get => level;
|
|
|
|
|
[DebuggerStepThrough] set => level = value;
|
|
|
|
|
}
|
2024-12-04 05:50:39 +08:00
|
|
|
|
[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>
|
2024-12-05 16:25:46 +08:00
|
|
|
|
[Header("<22><>ײ<EFBFBD><D7B2>")]public CircleCollider2D mycollider;
|
|
|
|
|
[Header("<22><><EFBFBD><EFBFBD><EFBFBD>ű<EFBFBD>")] public Attack attackClass;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-11 16:51:55 +08:00
|
|
|
|
public virtual async void Start()
|
2024-12-04 05:50:39 +08:00
|
|
|
|
{
|
|
|
|
|
if (Application.isPlaying)
|
|
|
|
|
{
|
2024-12-05 16:25:46 +08:00
|
|
|
|
if (attackClass)
|
|
|
|
|
{
|
|
|
|
|
attackClass.role = this;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-04 05:50:39 +08:00
|
|
|
|
UpdateBuff();
|
2024-12-05 16:25:46 +08:00
|
|
|
|
//Navigation.MoveToNextWaypoint(gameObject);
|
2024-12-04 05:50:39 +08:00
|
|
|
|
}
|
2024-12-05 16:25:46 +08:00
|
|
|
|
tag = Enum.GetName(typeof(Camp), camp);
|
2024-12-04 05:50:39 +08:00
|
|
|
|
updateAnimation();
|
2024-12-05 16:25:46 +08:00
|
|
|
|
|
|
|
|
|
//AttackScope=1f;
|
2024-12-04 05:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public async void updateAnimation()
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
2024-12-04 06:08:11 +08:00
|
|
|
|
if (AnimationTree.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
isAnimationPlay = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
isAnimationPlay = true;
|
|
|
|
|
if (animationHighlight >= AnimationTree.Count)
|
2024-12-04 05:50:39 +08:00
|
|
|
|
{
|
|
|
|
|
animationHighlight = AnimationTree.Count - 1;
|
|
|
|
|
}
|
|
|
|
|
else if (animationHighlight < 0) {
|
|
|
|
|
animationHighlight = 0;
|
|
|
|
|
}
|
2024-12-04 11:38:00 +08:00
|
|
|
|
//EditorUtility.SetDirty(this);
|
2024-12-04 05:50:39 +08:00
|
|
|
|
List<Sprite> LightSprite = AnimationTree[animationHighlight].value;
|
|
|
|
|
if (LightSprite == null )
|
|
|
|
|
{
|
2024-12-04 06:08:11 +08:00
|
|
|
|
isAnimationPlay = false;
|
2024-12-04 05:50:39 +08:00
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
OnAnimationStart?.Invoke(animationHighlight);
|
|
|
|
|
foreach (Sprite sprite in LightSprite)
|
|
|
|
|
{
|
|
|
|
|
if (image != null)
|
|
|
|
|
{
|
|
|
|
|
image.sprite = sprite;
|
|
|
|
|
}
|
|
|
|
|
else if (spriteRenderer != null)
|
|
|
|
|
{
|
|
|
|
|
spriteRenderer.sprite = sprite;
|
|
|
|
|
}
|
2024-12-04 06:08:11 +08:00
|
|
|
|
if (animationHighlight >= 0 && animationHighlight < AnimationTree.Count)
|
2024-12-04 05:50:39 +08:00
|
|
|
|
{
|
|
|
|
|
OnAnimationIng?.Invoke(animationHighlight);
|
|
|
|
|
await Task.Delay(AnimationTree[animationHighlight].CharacterAnimationFrameInterval);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
OnAnimationEnd?.Invoke(animationHighlight);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-05 16:25:46 +08:00
|
|
|
|
|
2024-12-04 05:50:39 +08:00
|
|
|
|
/// <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>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-11 16:51:55 +08:00
|
|
|
|
|
2024-12-04 05:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
2024-12-05 16:25:46 +08:00
|
|
|
|
|
|
|
|
|
|
2024-12-04 05:50:39 +08:00
|
|
|
|
}
|