(client) feat:实现摄像机跟踪与移动,实现任意位置生成实体,实现更安全的资源加载方式(指定unity内部加载资源) (#42)
Co-authored-by: zzdxxz <2079238449@qq.com> Co-committed-by: zzdxxz <2079238449@qq.com>
This commit is contained in:
@ -9,19 +9,20 @@ using UnityEngine.Serialization;
|
||||
|
||||
namespace Entity
|
||||
{
|
||||
public class Entity:MonoBehaviour,ITick
|
||||
public class Entity : MonoBehaviour, ITick
|
||||
{
|
||||
public SpriteAnimator animatorPrefab;
|
||||
public ImagePrefab imagePrefab;
|
||||
|
||||
|
||||
public AIBase aiTree;
|
||||
public JobBase currentJob;
|
||||
public AttributesDef attributes=new();
|
||||
public AttributesDef attributes = new();
|
||||
public Vector3 direction;
|
||||
public GameObject body;
|
||||
public string affiliation;
|
||||
|
||||
public bool canSelect = true;
|
||||
|
||||
public bool IsChase { set; get; } = true;
|
||||
public bool PlayerControlled
|
||||
{
|
||||
@ -36,15 +37,16 @@ namespace Entity
|
||||
}
|
||||
get => _isPlayerControlled;
|
||||
}
|
||||
public Vector3 Position => transform.position;
|
||||
|
||||
public bool IsDead => attributes.health <= 0;
|
||||
|
||||
private bool _isPlayerControlled = false;
|
||||
private bool _warning = false;
|
||||
|
||||
private Dictionary<Orientation,List<ITick>> bodyAnimationNode=new();
|
||||
public Dictionary<Orientation, List<ITick>> bodyAnimationNode = new();
|
||||
private Dictionary<Orientation, GameObject> bodyNodes = new();
|
||||
|
||||
|
||||
private Orientation currentOrientation = Orientation.Down;
|
||||
|
||||
public virtual void Init(PawnDef pawnDef)
|
||||
@ -70,7 +72,7 @@ namespace Entity
|
||||
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);
|
||||
bodyNodes[orientation] = directionRoot;
|
||||
}
|
||||
currentOrientation = Orientation.Down;
|
||||
@ -83,9 +85,9 @@ namespace Entity
|
||||
}
|
||||
|
||||
// 递归初始化单个绘图节点及其子节点
|
||||
public virtual void InitBodyPart(DrawNodeDef drawNode, GameObject parent,string folderPath)
|
||||
public virtual void InitBodyPart(DrawNodeDef drawNode, GameObject parent, string folderPath)
|
||||
{
|
||||
if(drawNode==null) return;
|
||||
if (drawNode == null) return;
|
||||
|
||||
GameObject nodeObject;
|
||||
if (drawNode.nodeName == "noName")
|
||||
@ -102,8 +104,11 @@ namespace Entity
|
||||
var texture =
|
||||
Managers.PackagesImageManager.Instance.FindBodyTextures(drawNode.packID, folderPath,
|
||||
$"{drawNode.nodeName}_{currentOrientation}");
|
||||
var image = nodeObject.GetComponent<ImagePrefab>();
|
||||
image.SetSprite(texture[0]);
|
||||
if (texture.Length > 0)
|
||||
{
|
||||
var image = nodeObject.GetComponent<ImagePrefab>();
|
||||
image.SetSprite(texture[0]);
|
||||
}
|
||||
break;
|
||||
|
||||
case DrawNodeType.Animation:
|
||||
@ -126,7 +131,7 @@ namespace Entity
|
||||
// 递归初始化子节点
|
||||
foreach (var child in drawNode.children)
|
||||
{
|
||||
InitBodyPart(child, nodeObject,folderPath);
|
||||
InitBodyPart(child, nodeObject, folderPath);
|
||||
}
|
||||
}
|
||||
public void Tick()
|
||||
@ -139,7 +144,6 @@ namespace Entity
|
||||
{
|
||||
AutoBehave();
|
||||
}
|
||||
|
||||
if (bodyAnimationNode.TryGetValue(currentOrientation, out var ticks))
|
||||
{
|
||||
foreach (var tick in ticks)
|
||||
@ -149,9 +153,9 @@ namespace Entity
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void TryAttck()
|
||||
public virtual void TryAttack()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public virtual void SetOrientation(Orientation orientation)
|
||||
@ -174,7 +178,7 @@ namespace Entity
|
||||
if (hit < 0)
|
||||
hit = from.attributes.attack / 100;
|
||||
attributes.health -= hit;
|
||||
|
||||
|
||||
currentJob.StopJob();
|
||||
}
|
||||
|
||||
@ -190,7 +194,7 @@ namespace Entity
|
||||
|
||||
private void AutoBehave()
|
||||
{
|
||||
if(aiTree == null)
|
||||
if (aiTree == null)
|
||||
return;
|
||||
if (currentJob == null || !currentJob.Running)
|
||||
{
|
||||
@ -206,7 +210,7 @@ namespace Entity
|
||||
}
|
||||
currentJob.StartJob(this);
|
||||
}
|
||||
|
||||
|
||||
currentJob.Update();
|
||||
}
|
||||
|
||||
@ -277,7 +281,7 @@ namespace Entity
|
||||
return (AIBase)Activator.CreateInstance(typeof(AIBase));
|
||||
}
|
||||
// 定义可能的命名空间列表
|
||||
var possibleNamespaces = new[] { "AI"};
|
||||
var possibleNamespaces = new[] { "AI" };
|
||||
|
||||
foreach (var ns in possibleNamespaces)
|
||||
{
|
||||
@ -305,4 +309,5 @@ namespace Entity
|
||||
throw new InvalidOperationException($"无法找到类型 {className} 或该类型不是 AIBase 的子类");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user