You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.6 KiB
90 lines
2.6 KiB
using UnityEngine;
|
|
|
|
public enum EntityTag : uint
|
|
{
|
|
Character, Player, Enemy, Mate, Skill, PlayerBaseCamp,
|
|
}
|
|
|
|
public class Entity : MonoBehaviour
|
|
{
|
|
[SerializeField] Transform centerPivot;
|
|
|
|
public Bitset32 Tags { get; private set; } = 0;
|
|
public Vector2 LookDirection { get; private set; }
|
|
public Vector2 Position { get => transform.position; set => transform.position = new Vector3(value.x, value.y, transform.position.z); }
|
|
public Transform CenterPivotTransform => centerPivot != null ? centerPivot : transform;
|
|
public Vector2 CenterPivot => centerPivot != null ? Position + (centerPivot.localPosition * LookDirection) : Position;
|
|
|
|
public void AddTags(params EntityTag[] tag)
|
|
{
|
|
for (int i = 0; i < tag.Length; i++)
|
|
Tags.SetBit((int)tag[i], true);
|
|
}
|
|
|
|
public void RemoveTags(params EntityTag[] tag)
|
|
{
|
|
for (int i = 0; i < tag.Length; i++)
|
|
Tags.SetBit((int)tag[i], false);
|
|
}
|
|
|
|
public void ClearTags() => Tags.Reset();
|
|
|
|
public bool HasTagsAny(Bitset32 targetTags) => Tags.MatchAny(targetTags);
|
|
public bool HasTagsAny(Bitset32.Mask targetTags) => Tags.MatchAny(targetTags);
|
|
public bool HasTagsAny(params EntityTag[] targetTags)
|
|
{
|
|
for (int i = 0; i < targetTags.Length; i++)
|
|
{
|
|
if (Tags.GetBit((int)targetTags[i]))
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public bool HasTagsAll(Bitset32 targetTags) => Tags.MatchAll(targetTags);
|
|
public bool HasTagsAll(Bitset32.Mask targetTags) => Tags.MatchAll(targetTags);
|
|
public bool HasTagsAll(params EntityTag[] targetTags)
|
|
{
|
|
for (int i = 0; i < targetTags.Length; i++)
|
|
{
|
|
if (!Tags.GetBit(i))
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public void SetPosWithCenterPivot(Vector2 position)
|
|
{
|
|
Vector3 newPos = position;
|
|
newPos.z = transform.position.z;
|
|
|
|
if(centerPivot != null)
|
|
transform.position = position - CenterPivot + Position;
|
|
|
|
transform.position = newPos;
|
|
|
|
LookDirection = Vector2.right;
|
|
}
|
|
|
|
public void ChangeLookDirection(Transform lookTarget)
|
|
{
|
|
ChangeLookDirection((Vector2)lookTarget.position - Position);
|
|
}
|
|
|
|
public void ChangeLookDirection(Vector2 lookDirection)
|
|
{
|
|
if (lookDirection.x > 0)
|
|
{
|
|
LookDirection = Vector2.right;
|
|
transform.rotation = Quaternion.Euler(Vector3.zero);
|
|
}
|
|
else if(lookDirection.x < 0)
|
|
{
|
|
LookDirection = Vector2.left;
|
|
transform.rotation = Quaternion.Euler(Global.V3_RotRev);
|
|
}
|
|
}
|
|
}
|
|
|