(client) feat:添加设置类,子弹添加敌我识别; chore:修改了右键菜单的初始化方式为独立创建,加载定义报错提供更多信息,动画加载出错也返回默认序列。
This commit is contained in:
@ -1,10 +1,16 @@
|
||||
using System;
|
||||
using Base;
|
||||
using Data;
|
||||
using Prefab;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Entity
|
||||
{
|
||||
public class Bullet : Entity
|
||||
{
|
||||
public Entity bulletSource;
|
||||
public float lifeTime = 10;
|
||||
|
||||
public override void SetTarget(Vector3 pos)
|
||||
{
|
||||
base.SetTarget(pos);
|
||||
@ -14,24 +20,47 @@ namespace Entity
|
||||
protected override void AutoBehave()
|
||||
{
|
||||
TryMove();
|
||||
lifeTime-=Time.deltaTime;
|
||||
if (lifeTime <= 0)
|
||||
{
|
||||
Kill();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
other.GetComponent<Entity>()?.OnHit(this);
|
||||
var entity = other.GetComponent<Entity>();
|
||||
if (!entity || entity == bulletSource) return;
|
||||
if (Managers.AffiliationManager.Instance.GetRelation(bulletSource.affiliation, entity.affiliation) != Relation.Friendly)
|
||||
{
|
||||
entity.OnHit(this);
|
||||
}
|
||||
else if (Setting.Instance.CurrentSettings.friendlyFire)
|
||||
{
|
||||
entity.OnHit(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
return; // 如果是友好关系且不允许友军伤害,则不处理
|
||||
}
|
||||
attributes.health -= 1;
|
||||
}
|
||||
|
||||
// 旋转对象到指定方向
|
||||
public static void RotateTransformToDirection(Transform transform, Vector3 targetDirection)
|
||||
{
|
||||
// 默认向上方向
|
||||
Vector3 upDirection = Vector3.up;
|
||||
// 确保目标方向不是零向量
|
||||
if (targetDirection == Vector3.zero)
|
||||
return;
|
||||
|
||||
// 计算旋转角度
|
||||
float angle = Mathf.Atan2(targetDirection.x, targetDirection.y) * Mathf.Rad2Deg;
|
||||
// 计算当前向上方向与目标方向之间的角度
|
||||
float angle = Mathf.Atan2(targetDirection.y, targetDirection.x) * Mathf.Rad2Deg;
|
||||
|
||||
// 设置旋转
|
||||
transform.rotation = Quaternion.Euler(0, 0, angle);
|
||||
// 调整角度,因为默认贴图向上是0度,而Atan2计算的是相对于x轴的角度
|
||||
angle -= 90f;
|
||||
|
||||
// 应用旋转
|
||||
transform.rotation = Quaternion.Euler(0f, 0f, angle);
|
||||
}
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ namespace Entity
|
||||
var buttonDef = def.Values.First();
|
||||
Vector3 dir = Utils.MousePosition.GetWorldPosition();
|
||||
Managers.EntityManage.Instance.GenerateBulletEntity((BulletDef)buttonDef, Position,
|
||||
dir - Position);
|
||||
dir - Position, this);
|
||||
}
|
||||
}
|
||||
}
|
@ -149,7 +149,7 @@ namespace Entity
|
||||
{
|
||||
attributes = entityDef.attributes.Clone();
|
||||
aiTree = Utils.BehaviorTree.ConvertToAIBase(entityDef.behaviorTree);
|
||||
affiliation = entityDef.affiliation.defName;
|
||||
affiliation = entityDef.affiliation?.defName;
|
||||
InitBody(entityDef.drawingOrder);
|
||||
this.entityDef = entityDef;
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Managers;
|
||||
using Prefab;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
@ -7,6 +8,8 @@ namespace Entity
|
||||
{
|
||||
public class Outline : MonoBehaviour
|
||||
{
|
||||
public RightMenuPrefab rightMenuPrefab;
|
||||
|
||||
public GameObject body;
|
||||
public SpriteRenderer outlineRenderer;
|
||||
public CapsuleCollider2D outlineCollider;
|
||||
@ -96,10 +99,7 @@ namespace Entity
|
||||
// 检测是否按下的是鼠标右键
|
||||
if (Input.GetMouseButtonDown(1)) // 鼠标右键对应的是按钮索引 1
|
||||
{
|
||||
var rightMenu = Base.RightMenu.Instance;
|
||||
rightMenu.Init(GetMenu());
|
||||
rightMenu.Position = Input.mousePosition;
|
||||
rightMenu.Show();
|
||||
RightMenuManager.GenerateRightMenu(GetMenu(), Input.mousePosition);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user