(client) feat:实现血条显示,实现攻击交互,添加碰撞体;fix:修复部分朝向贴图加载失败的问题;chore:规范工作类和行为获取类命名
This commit is contained in:
@ -13,7 +13,7 @@ namespace Entity
|
||||
|
||||
private void Start()
|
||||
{
|
||||
aiTree = new RandomWander();
|
||||
aiTree = new JobGiver_RandomWander();
|
||||
attributes = new AttributesDef();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using AI;
|
||||
using Base;
|
||||
@ -7,23 +8,73 @@ using Prefab;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
|
||||
namespace Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 表示游戏中的实体类,继承自 MonoBehaviour 并实现 ITick 接口。
|
||||
/// </summary>
|
||||
public class Entity : MonoBehaviour, ITick
|
||||
{
|
||||
/// <summary>
|
||||
/// 动画预制体,用于管理实体的动画逻辑。
|
||||
/// </summary>
|
||||
public SpriteAnimator animatorPrefab;
|
||||
|
||||
/// <summary>
|
||||
/// 图像预制体,用于管理实体的静态图像显示。
|
||||
/// </summary>
|
||||
public ImagePrefab imagePrefab;
|
||||
|
||||
public ProgressBarPrefab healthBarPrefab;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 人工智能行为树,定义实体的行为逻辑。
|
||||
/// </summary>
|
||||
public AIBase aiTree;
|
||||
|
||||
/// <summary>
|
||||
/// 当前实体正在执行的任务。
|
||||
/// </summary>
|
||||
public JobBase currentJob;
|
||||
|
||||
/// <summary>
|
||||
/// 实体的属性定义,包括生命值、攻击力、防御力等。
|
||||
/// </summary>
|
||||
public AttributesDef attributes = new();
|
||||
|
||||
/// <summary>
|
||||
/// 实体当前的移动方向。
|
||||
/// </summary>
|
||||
public Vector3 direction;
|
||||
|
||||
/// <summary>
|
||||
/// 实体的身体部分,用于挂载动画和图像节点。
|
||||
/// </summary>
|
||||
public GameObject body;
|
||||
|
||||
/// <summary>
|
||||
/// 实体所属的阵营或派系。
|
||||
/// </summary>
|
||||
public string affiliation;
|
||||
|
||||
/// <summary>
|
||||
/// 表示实体是否可以被选择。
|
||||
/// </summary>
|
||||
public bool canSelect = true;
|
||||
|
||||
/// <summary>
|
||||
/// 表示实体是否处于追逐状态(影响移动速度)。
|
||||
/// </summary>
|
||||
public bool IsChase { set; get; } = true;
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 表示实体是否由玩家控制。
|
||||
/// </summary>
|
||||
public bool PlayerControlled
|
||||
{
|
||||
set
|
||||
@ -37,26 +88,76 @@ namespace Entity
|
||||
}
|
||||
get => _isPlayerControlled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体当前位置。
|
||||
/// </summary>
|
||||
public Vector3 Position => transform.position;
|
||||
|
||||
/// <summary>
|
||||
/// 表示实体是否已经死亡(生命值小于等于零)。
|
||||
/// </summary>
|
||||
public bool IsDead => attributes.health <= 0;
|
||||
|
||||
private bool _isPlayerControlled = false;
|
||||
private bool _warning = false;
|
||||
|
||||
/// <summary>
|
||||
/// 存储不同朝向下的动画节点集合。
|
||||
/// </summary>
|
||||
public Dictionary<Orientation, List<ITick>> bodyAnimationNode = new();
|
||||
|
||||
/// <summary>
|
||||
/// 存储不同朝向下的身体节点对象。
|
||||
/// </summary>
|
||||
private Dictionary<Orientation, GameObject> bodyNodes = new();
|
||||
|
||||
/// <summary>
|
||||
/// 当前实体的朝向。
|
||||
/// </summary>
|
||||
private Orientation currentOrientation = Orientation.Down;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 攻击动画的持续时间(秒)。
|
||||
/// </summary>
|
||||
private const float attackAnimationDuration = 0.1f;
|
||||
|
||||
/// <summary>
|
||||
/// 抖动的偏移量。
|
||||
/// </summary>
|
||||
private const float shakeOffset = 0.5f;
|
||||
// 协程引用
|
||||
private Coroutine attackCoroutine;
|
||||
|
||||
protected PawnDef entityDef;
|
||||
|
||||
|
||||
public float hitBarUIShowTime = 5;
|
||||
private float hitBarUIShowTimer = 0;
|
||||
public bool isShowingOfHitBarUI=>hitBarUIShowTimer > 0;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化实体的基本属性和行为树。
|
||||
/// </summary>
|
||||
/// <param name="pawnDef">实体的定义数据。</param>
|
||||
public virtual void Init(PawnDef pawnDef)
|
||||
{
|
||||
attributes = pawnDef.attributes.Clone();
|
||||
aiTree = ConvertToAIBase(pawnDef.behaviorTree);
|
||||
aiTree = Utils.BehaviorTree.ConvertToAIBase(pawnDef.behaviorTree);
|
||||
affiliation = pawnDef.affiliation;
|
||||
InitBody(pawnDef.drawingOrder);
|
||||
entityDef = pawnDef;
|
||||
|
||||
HideHealthBar();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化实体的身体部分,包括不同朝向下的绘图节点。
|
||||
/// </summary>
|
||||
/// <param name="drawingOrder">绘制顺序定义。</param>
|
||||
public virtual void InitBody(DrawingOrderDef drawingOrder)
|
||||
{
|
||||
// 定义方向枚举和对应的 GetDrawingOrder 调用
|
||||
@ -67,12 +168,12 @@ namespace Entity
|
||||
currentOrientation = orientation;
|
||||
bodyAnimationNode[orientation] = new();
|
||||
// 获取当前方向的绘图节点
|
||||
var drawNode = drawingOrder.GetDrawingOrder(orientation);
|
||||
var drawNode = drawingOrder.GetDrawingOrder(orientation, out var realOrientation);
|
||||
|
||||
if (drawNode == null) continue;
|
||||
var directionRoot = new GameObject(orientation.ToString());
|
||||
directionRoot.transform.SetParent(body.transform, false);
|
||||
InitBodyPart(drawNode, directionRoot, drawingOrder.texturePath);
|
||||
InitBodyPart(drawNode, directionRoot, drawingOrder.texturePath,realOrientation);
|
||||
bodyNodes[orientation] = directionRoot;
|
||||
}
|
||||
currentOrientation = Orientation.Down;
|
||||
@ -84,8 +185,13 @@ namespace Entity
|
||||
SetOrientation(Orientation.Down);
|
||||
}
|
||||
|
||||
// 递归初始化单个绘图节点及其子节点
|
||||
public virtual void InitBodyPart(DrawNodeDef drawNode, GameObject parent, string folderPath)
|
||||
/// <summary>
|
||||
/// 递归初始化单个绘图节点及其子节点。
|
||||
/// </summary>
|
||||
/// <param name="drawNode">绘图节点定义。</param>
|
||||
/// <param name="parent">父节点对象。</param>
|
||||
/// <param name="folderPath">纹理资源路径。</param>
|
||||
public virtual void InitBodyPart(DrawNodeDef drawNode, GameObject parent, string folderPath,Orientation realOrientation)
|
||||
{
|
||||
if (drawNode == null) return;
|
||||
|
||||
@ -103,12 +209,11 @@ namespace Entity
|
||||
nodeObject = Instantiate(imagePrefab.gameObject, parent.transform);
|
||||
var texture =
|
||||
Managers.PackagesImageManager.Instance.FindBodyTextures(drawNode.packID, folderPath,
|
||||
$"{drawNode.nodeName}_{currentOrientation}");
|
||||
if (texture.Length > 0)
|
||||
{
|
||||
var image = nodeObject.GetComponent<ImagePrefab>();
|
||||
image.SetSprite(texture[0]);
|
||||
}
|
||||
$"{drawNode.nodeName}_{realOrientation}");
|
||||
var image = nodeObject.GetComponent<ImagePrefab>();
|
||||
image.SetSprite(texture.Length > 0
|
||||
? texture[0]
|
||||
: Managers.PackagesImageManager.Instance.defaultSprite);
|
||||
break;
|
||||
|
||||
case DrawNodeType.Animation:
|
||||
@ -118,7 +223,7 @@ namespace Entity
|
||||
bodyAnimationNode[currentOrientation].Add(tick);
|
||||
var textures = Managers.PackagesImageManager.Instance.FindBodyTextures(drawNode.packID,
|
||||
folderPath,
|
||||
$"{drawNode.nodeName}_{currentOrientation}");
|
||||
$"{drawNode.nodeName}_{realOrientation}");
|
||||
var animator = nodeObject.GetComponent<SpriteAnimator>();
|
||||
animator.SetSprites(textures);
|
||||
break;
|
||||
@ -131,9 +236,13 @@ namespace Entity
|
||||
// 递归初始化子节点
|
||||
foreach (var child in drawNode.children)
|
||||
{
|
||||
InitBodyPart(child, nodeObject, folderPath);
|
||||
InitBodyPart(child, nodeObject, folderPath,realOrientation);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新实体的逻辑,包括玩家控制和自动行为。
|
||||
/// </summary>
|
||||
public void Tick()
|
||||
{
|
||||
if (_isPlayerControlled)
|
||||
@ -151,47 +260,104 @@ namespace Entity
|
||||
tick.Tick();
|
||||
}
|
||||
}
|
||||
|
||||
if (isShowingOfHitBarUI)
|
||||
{
|
||||
hitBarUIShowTimer -= Time.deltaTime;
|
||||
if (hitBarUIShowTimer <= 0)
|
||||
{
|
||||
HideHealthBar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试攻击目标实体。
|
||||
/// </summary>
|
||||
public virtual void TryAttack()
|
||||
{
|
||||
|
||||
if(attackCoroutine == null)
|
||||
attackCoroutine = StartCoroutine(AttackFlow());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置实体的朝向。
|
||||
/// </summary>
|
||||
/// <param name="orientation">新的朝向。</param>
|
||||
public virtual void SetOrientation(Orientation orientation)
|
||||
{
|
||||
bodyNodes[currentOrientation]?.SetActive(false);
|
||||
currentOrientation = orientation;
|
||||
bodyNodes[orientation]?.SetActive(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 往对应朝向移动moveSpeed*deltaTime的距离
|
||||
/// 根据方向尝试移动实体。
|
||||
/// </summary>
|
||||
public virtual void TryMove()
|
||||
{
|
||||
transform.position += direction * (attributes.moveSpeed * Time.deltaTime * (IsChase ? 1 : 0.5f));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理实体受到攻击的逻辑。
|
||||
/// </summary>
|
||||
/// <param name="from">攻击来源实体。</param>
|
||||
public virtual void OnHit(Entity from)
|
||||
{
|
||||
var hit = from.attributes.attack - attributes.defense;
|
||||
if (hit < 0)
|
||||
hit = from.attributes.attack / 100;
|
||||
attributes.health -= hit;
|
||||
|
||||
currentJob.StopJob();
|
||||
currentJob?.StopJob();
|
||||
ShowHealthBar();
|
||||
}
|
||||
|
||||
public virtual void SetTarget(Vector3 pos)
|
||||
public void ShowHealthBar()
|
||||
{
|
||||
direction = (pos - transform.position).normalized;
|
||||
healthBarPrefab.gameObject.SetActive(true);
|
||||
healthBarPrefab.Progress = (float)attributes.health / entityDef.attributes.health;
|
||||
hitBarUIShowTimer=hitBarUIShowTime;
|
||||
}
|
||||
|
||||
public void HideHealthBar()
|
||||
{
|
||||
healthBarPrefab.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 杀死实体,设置生命值为零。
|
||||
/// </summary>
|
||||
public virtual void Kill()
|
||||
{
|
||||
attributes.health = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置实体的目标位置。
|
||||
/// </summary>
|
||||
/// <param name="pos">目标位置。</param>
|
||||
public virtual void SetTarget(Vector3 pos)
|
||||
{
|
||||
direction = (pos - transform.position).normalized;
|
||||
Orientation ori;
|
||||
// 判断方向向量最接近哪个朝向
|
||||
if (Mathf.Abs(direction.y) > Mathf.Abs(direction.x))
|
||||
{
|
||||
// 垂直方向优先
|
||||
ori = direction.y > 0 ? Orientation.Up : Orientation.Down;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 水平方向优先
|
||||
ori = direction.x > 0 ? Orientation.Right : Orientation.Left;
|
||||
}
|
||||
SetOrientation(ori);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动行为逻辑,根据行为树执行任务。
|
||||
/// </summary>
|
||||
private void AutoBehave()
|
||||
{
|
||||
if (aiTree == null)
|
||||
@ -213,13 +379,17 @@ namespace Entity
|
||||
|
||||
currentJob.Update();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新玩家控制的逻辑,处理输入和移动。
|
||||
/// </summary>
|
||||
protected virtual void UpdatePlayerControls()
|
||||
{
|
||||
// 检测 Shift 键状态
|
||||
var isHoldingShift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
|
||||
IsChase = !isHoldingShift; // 按住 Shift 时 IsChase = false,否则 true
|
||||
// 获取当前键盘输入状态(2D 移动,只使用 X 和 Y 轴)
|
||||
// 获取当前键盘输入状态(2D 移动,只使用 X 和 Y 轴)
|
||||
var inputDirection = Vector2.zero;
|
||||
|
||||
// 检测 WASD 或方向键输入
|
||||
@ -239,7 +409,10 @@ namespace Entity
|
||||
{
|
||||
inputDirection += Vector2.right; // 向右移动(X 轴正方向)
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
TryAttack();
|
||||
}
|
||||
// 如果有输入方向,则设置目标位置并尝试移动
|
||||
if (inputDirection == Vector2.zero) return;
|
||||
// 归一化方向向量,确保对角线移动速度一致
|
||||
@ -253,61 +426,76 @@ namespace Entity
|
||||
|
||||
// 调用 TryMove 方法处理实际移动逻辑
|
||||
TryMove();
|
||||
|
||||
|
||||
}
|
||||
public static AIBase ConvertToAIBase(BehaviorTreeDef behaviorTreeDef)
|
||||
// 攻击流程协程
|
||||
IEnumerator AttackFlow()
|
||||
{
|
||||
if (behaviorTreeDef == null)
|
||||
return null;
|
||||
var aiBase = CreateAIBaseInstance(behaviorTreeDef.className);
|
||||
if (behaviorTreeDef.childTree != null)
|
||||
{
|
||||
foreach (var child in behaviorTreeDef.childTree)
|
||||
{
|
||||
if (child != null)
|
||||
{
|
||||
aiBase.children.Add(ConvertToAIBase(child));
|
||||
}
|
||||
}
|
||||
}
|
||||
return aiBase;
|
||||
// 播放攻击动画并获取动画持续时间
|
||||
var animationDuration = PlayAttackAnimation();
|
||||
// 等待动画执行完毕
|
||||
yield return new WaitForSeconds(animationDuration);
|
||||
// 调用检测并攻击敌人的方法
|
||||
DetectAndAttackEnemies();
|
||||
// 攻击流程结束,清理协程引用
|
||||
attackCoroutine = null;
|
||||
}
|
||||
// 使用反射根据 className 创建具体的 AIBase 子类实例
|
||||
private static AIBase CreateAIBaseInstance(string className)
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 播放攻击动画。
|
||||
/// </summary>
|
||||
/// <returns>开始检测攻击范围内敌人的时间。</returns>
|
||||
public float PlayAttackAnimation()
|
||||
{
|
||||
if (string.IsNullOrEmpty(className))
|
||||
throw new ArgumentException("className 不能为空");
|
||||
if (className.Equals("AIBase", StringComparison.OrdinalIgnoreCase))
|
||||
// 启动协程来执行攻击动画
|
||||
StartCoroutine(ShakeInDirectionCoroutine());
|
||||
|
||||
// 返回检测敌人的起始时间
|
||||
return attackAnimationDuration;
|
||||
}
|
||||
|
||||
private IEnumerator ShakeInDirectionCoroutine()
|
||||
{
|
||||
var originalPosition = transform.position; // 记录原始位置
|
||||
transform.position += direction * shakeOffset;
|
||||
yield return new WaitForSeconds(attackAnimationDuration);
|
||||
transform.position = originalPosition;
|
||||
}
|
||||
|
||||
public void DetectAndAttackEnemies()
|
||||
{
|
||||
const int attackRange = 3;
|
||||
var attackCount = 3;
|
||||
|
||||
// 获取攻击范围内的所有碰撞体,使用LayerMask过滤掉非敌人
|
||||
var hits = Physics2D.OverlapCircleAll(
|
||||
transform.position,
|
||||
attackRange,
|
||||
LayerMask.GetMask("Entity"));
|
||||
|
||||
// 或者使用标签过滤(如果敌人有特定标签)
|
||||
// Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, attackRange);
|
||||
|
||||
Debug.Log($"Found {hits.Length} potential targets in attack range");
|
||||
|
||||
foreach (var hit in hits)
|
||||
{
|
||||
return (AIBase)Activator.CreateInstance(typeof(AIBase));
|
||||
if (attackCount <= 0) break;
|
||||
|
||||
// 检查是否是自身(额外安全措施)
|
||||
if (hit.gameObject == this.gameObject) continue;
|
||||
|
||||
// 获取Entity组件
|
||||
var entity = hit.GetComponent<Entity>();
|
||||
if (!entity) continue;
|
||||
|
||||
// 执行攻击
|
||||
entity.OnHit(this);
|
||||
attackCount--;
|
||||
}
|
||||
// 定义可能的命名空间列表
|
||||
var possibleNamespaces = new[] { "AI" };
|
||||
|
||||
foreach (var ns in possibleNamespaces)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 获取当前程序集
|
||||
var assembly = typeof(AIBase).Assembly;
|
||||
|
||||
// 尝试查找类型
|
||||
var type = assembly.GetType($"{ns}.{className}");
|
||||
|
||||
if (type != null && typeof(AIBase).IsAssignableFrom(type))
|
||||
{
|
||||
// 如果找到合适的类型,则创建实例并返回
|
||||
return (AIBase)Activator.CreateInstance(type);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略单个命名空间的错误,继续尝试下一个命名空间
|
||||
}
|
||||
}
|
||||
|
||||
// 如果所有命名空间都未找到对应的类型,抛出异常
|
||||
throw new InvalidOperationException($"无法找到类型 {className} 或该类型不是 AIBase 的子类");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
70
Client/Assets/Scripts/Entity/Inventory.cs
Normal file
70
Client/Assets/Scripts/Entity/Inventory.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System.Collections.Generic;
|
||||
using Item;
|
||||
|
||||
namespace Entity
|
||||
{
|
||||
public class Inventory
|
||||
{
|
||||
public Entity from; // 物品所属实体
|
||||
public List<ItemBase> items = new List<ItemBase>(); // 背包中的物品列表
|
||||
|
||||
/// <summary>
|
||||
/// 添加物品到背包
|
||||
/// </summary>
|
||||
/// <param name="item">要添加的物品</param>
|
||||
/// <param name="count">添加的数量</param>
|
||||
public void AddItem(ItemResource resource, int count)
|
||||
{
|
||||
if (count <= 0) return; // 如果数量小于等于0,直接返回
|
||||
|
||||
// 检查背包中是否已存在相同物品
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item.resource.Equals(resource))
|
||||
{
|
||||
item.count += count; // 增加数量
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有找到相同物品,则创建新物品并添加到背包
|
||||
var newItem = new ItemBase { resource = resource, count = count };
|
||||
items.Add(newItem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从背包中取出物品
|
||||
/// </summary>
|
||||
/// <param name="itemName">物品名称</param>
|
||||
/// <param name="count">取出的数量</param>
|
||||
/// <returns>是否成功取出</returns>
|
||||
public bool RemoveItem(string itemName, int count)
|
||||
{
|
||||
if (count <= 0) return false; // 如果数量小于等于0,直接返回失败
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item.resource.name == itemName)
|
||||
{
|
||||
if (item.count >= count)
|
||||
{
|
||||
item.count -= count; // 减少数量
|
||||
if (item.count == 0)
|
||||
{
|
||||
items.Remove(item); // 如果数量为0,则移除该物品
|
||||
}
|
||||
|
||||
return true; // 成功取出
|
||||
}
|
||||
else
|
||||
{
|
||||
return false; // 数量不足
|
||||
}
|
||||
}
|
||||
}
|
||||
return false; // 未找到物品
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/Entity/Inventory.cs.meta
Normal file
3
Client/Assets/Scripts/Entity/Inventory.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3da96d312e8e4c65b9157548281f7826
|
||||
timeCreated: 1755061766
|
@ -1,12 +1,9 @@
|
||||
namespace Entity
|
||||
{
|
||||
public class Monster
|
||||
public class Monster:Entity
|
||||
{
|
||||
public Protocol.MonsterPack ToPack()
|
||||
{
|
||||
var pack= new Protocol.MonsterPack();
|
||||
return pack;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Prefab;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
@ -10,6 +10,7 @@ namespace Entity
|
||||
public GameObject body;
|
||||
public SpriteRenderer outlineRenderer;
|
||||
public CapsuleCollider2D outlineCollider;
|
||||
public ProgressBarPrefab progressBarPrefab;
|
||||
|
||||
public Entity entity;
|
||||
|
||||
@ -23,6 +24,9 @@ namespace Entity
|
||||
outlineRenderer.size = size;
|
||||
outlineCollider.direction = size.x > size.y ? CapsuleDirection2D.Horizontal : CapsuleDirection2D.Vertical;
|
||||
outlineCollider.size = size;
|
||||
|
||||
progressBarPrefab.transform.localPosition += new Vector3(0f,size.y * 2 / 3,0f);
|
||||
progressBarPrefab.transform.localScale = new Vector3(size.x, size.x / 10, 1);
|
||||
}
|
||||
|
||||
public void Show()
|
||||
@ -76,23 +80,23 @@ namespace Entity
|
||||
private void OnMouseEnter()
|
||||
{
|
||||
Show();
|
||||
_select = true;
|
||||
}
|
||||
|
||||
private void OnMouseExit()
|
||||
{
|
||||
Hide();
|
||||
_select = false;
|
||||
}
|
||||
|
||||
private void OnMouseOver()
|
||||
{
|
||||
if (!entity.canSelect)
|
||||
return;
|
||||
// 检测是否按下的是鼠标右键
|
||||
if (Input.GetMouseButtonDown(1)) // 鼠标右键对应的是按钮索引 1
|
||||
{
|
||||
var rightMenu = Base.RightMenu.Instance;
|
||||
rightMenu.Init(GetMenu());
|
||||
rightMenu.transform.position = Input.mousePosition;
|
||||
rightMenu.Position = Input.mousePosition;
|
||||
rightMenu.Show();
|
||||
}
|
||||
}
|
||||
@ -104,6 +108,14 @@ namespace Entity
|
||||
result.Add(("结束操控", EndControl));
|
||||
else
|
||||
result.Add(("手动操控", StartControl));
|
||||
if (CameraControl.CameraControl.Instance.focusedEntity == entity)
|
||||
{
|
||||
result.Add(("取消跟随", ()=>CameraControl.CameraControl.Instance.focusedEntity=null));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(("视角跟随", ()=>CameraControl.CameraControl.Instance.focusedEntity=entity));
|
||||
}
|
||||
result.Add(("杀死", () => entity.Kill()));
|
||||
result.Add(("变成笨蛋", BecomeDefault));
|
||||
return result;
|
||||
|
Reference in New Issue
Block a user